From 5a601b0f78dd124fc0a9056f43d2e4d85d5c1246 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 14 Mar 2022 11:55:38 -0700 Subject: [PATCH] grpc-js: Consistently log subchannel and call IDs in traces --- packages/grpc-js/package.json | 2 +- packages/grpc-js/src/call-stream.ts | 4 ++++ packages/grpc-js/src/channel.ts | 17 +++++++++++------ packages/grpc-js/src/subchannel.ts | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/grpc-js/package.json b/packages/grpc-js/package.json index f41de376d..f617223bc 100644 --- a/packages/grpc-js/package.json +++ b/packages/grpc-js/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/grpc-js", - "version": "1.5.7", + "version": "1.5.8", "description": "gRPC Library for Node - pure JS implementation", "homepage": "https://grpc.io/", "repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js", diff --git a/packages/grpc-js/src/call-stream.ts b/packages/grpc-js/src/call-stream.ts index f2e045aef..601218886 100644 --- a/packages/grpc-js/src/call-stream.ts +++ b/packages/grpc-js/src/call-stream.ts @@ -795,6 +795,10 @@ export class Http2CallStream implements Call { this.filterStack.push(extraFilters); } + getCallNumber() { + return this.callNumber; + } + startRead() { /* If the stream has ended with an error, we should not emit any more * messages and we should communicate that the stream has ended */ diff --git a/packages/grpc-js/src/channel.ts b/packages/grpc-js/src/channel.ts index 8fa2c592a..9d73c5df8 100644 --- a/packages/grpc-js/src/channel.ts +++ b/packages/grpc-js/src/channel.ts @@ -404,11 +404,16 @@ export class ChannelImplementation implements Channel { metadata: callMetadata, extraPickInfo: callConfig.pickInformation, }); + const subchannelString = pickResult.subchannel ? + '(' + pickResult.subchannel.getChannelzRef().id + ') ' + pickResult.subchannel.getAddress() : + '' + pickResult.subchannel; this.trace( - 'Pick result: ' + + 'Pick result for call [' + + callStream.getCallNumber() + + ']: ' + PickResultType[pickResult.pickResultType] + ' subchannel: ' + - pickResult.subchannel?.getAddress() + + subchannelString + ' status: ' + pickResult.status?.code + ' ' + @@ -433,7 +438,7 @@ export class ChannelImplementation implements Channel { log( LogVerbosity.ERROR, 'Error: COMPLETE pick result subchannel ' + - pickResult.subchannel!.getAddress() + + subchannelString + ' has state ' + ConnectivityState[pickResult.subchannel!.getConnectivityState()] ); @@ -480,7 +485,7 @@ export class ChannelImplementation implements Channel { * tryPick */ this.trace( 'Failed to start call on picked subchannel ' + - pickResult.subchannel!.getAddress() + + subchannelString + ' with error ' + (error as Error).message + '. Retrying pick', @@ -490,7 +495,7 @@ export class ChannelImplementation implements Channel { } else { this.trace( 'Failed to start call on picked subchanel ' + - pickResult.subchannel!.getAddress() + + subchannelString + ' with error ' + (error as Error).message + '. Ending call', @@ -509,7 +514,7 @@ export class ChannelImplementation implements Channel { * block above */ this.trace( 'Picked subchannel ' + - pickResult.subchannel!.getAddress() + + subchannelString + ' has state ' + ConnectivityState[subchannelState] + ' after metadata filters. Retrying pick', diff --git a/packages/grpc-js/src/subchannel.ts b/packages/grpc-js/src/subchannel.ts index 24f02144d..22c243fed 100644 --- a/packages/grpc-js/src/subchannel.ts +++ b/packages/grpc-js/src/subchannel.ts @@ -857,7 +857,7 @@ export class Subchannel { logging.trace( LogVerbosity.DEBUG, 'call_stream', - 'Starting stream on subchannel ' + + 'Starting stream [' + callStream.getCallNumber() + '] on subchannel ' + '(' + this.channelzRef.id + ') ' + this.subchannelAddressString + ' with headers\n' +