Skip to content

Commit

Permalink
fix(express): use the same clock for span start and end (open-telemet…
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Sep 28, 2022
1 parent 1c450f5 commit cbeef6e
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cbeef6e

Please sign in to comment.