From cbeef6eef7c4ec8801389fdf9787722b89056537 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Wed, 28 Sep 2022 13:00:43 -0400 Subject: [PATCH] fix(express): use the same clock for span start and end (#1210) --- .../src/instrumentation.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts index 1baffddfd1..f728bd5f80 100644 --- a/plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts @@ -14,12 +14,7 @@ * limitations under the License. */ -import { - hrTime, - setRPCMetadata, - getRPCMetadata, - RPCType, -} from '@opentelemetry/core'; +import { setRPCMetadata, getRPCMetadata, RPCType } from '@opentelemetry/core'; import { trace, context, diag, SpanAttributes } from '@opentelemetry/api'; import type * as express from 'express'; import { @@ -263,22 +258,19 @@ export class ExpressInstrumentation extends InstrumentationBase< ); } - const startTime = hrTime(); let spanHasEnded = false; - // If we found anything that isnt a middleware, there no point of measuring - // their time since they dont have callback. if ( metadata.attributes[AttributeNames.EXPRESS_TYPE] !== ExpressLayerType.MIDDLEWARE ) { - span.end(startTime); + span.end(); spanHasEnded = true; } // listener for response.on('finish') const onResponseFinish = () => { if (spanHasEnded === false) { spanHasEnded = true; - span.end(startTime); + span.end(); } }; // verify we have a callback