Skip to content

Commit

Permalink
fix: experimental metrics middleware should use the grpc message cons…
Browse files Browse the repository at this point in the history
…tructor name in emitted metrics instead of MiddlewareMessage (#993)

* fix: experimental metrics middleware should use the grpc message constructor name in emitted metrics instead of MiddlewareMessage

* add null and undefined check

* fix lint errors

* move null check to middleware message instead

* remove console log and run linter
  • Loading branch information
anitarua authored Oct 31, 2023
1 parent 1738884 commit 45a0049
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export abstract class ExperimentalMetricsMiddlewareRequestHandler

onRequestBody(request: MiddlewareMessage): Promise<MiddlewareMessage> {
this.requestSize = request.messageLength();
this.requestType = request.constructor.name;
this.requestType = request._grpcMessage.constructor.name;
this.requestBodyTime = new Date().getTime();
return Promise.resolve(request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class MiddlewareMessage {
}

messageLength(): number {
return this._grpcMessage.serializeBinary().length;
if (this._grpcMessage !== null && this._grpcMessage !== undefined) {
return this._grpcMessage.serializeBinary().length;
}
return 0;
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/client-sdk-nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export {

export {ExperimentalRequestLoggingMiddleware} from './config/middleware/experimental-request-logging-middleware';
export {ExperimentalMetricsCsvMiddleware} from './config/middleware/experimental-metrics-csv-middleware';
export {ExperimentalMetricsLoggingMiddleware} from './config/middleware/experimental-metrics-logging-middleware';
export {ExampleAsyncMiddleware} from './config/middleware/example-async-middleware';

export {
Expand Down

0 comments on commit 45a0049

Please sign in to comment.