diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dda81b650..79881b78dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ All notable changes to this project will be documented in this file. [#3327](https://github.com/open-telemetry/opentelemetry-js/pull/3327) @dyladan * fix(resources): fix EnvDetector throwing errors when attribute values contain spaces [#3295](https://github.com/open-telemetry/opentelemetry-js/issues/3295) +* fix(trace): fix an issue which caused negative span durations in web based spans + [#3359](https://github.com/open-telemetry/opentelemetry-js/pull/3359) @dyladan * fix(resources): strict OTEL_RESOURCE_ATTRIBUTES baggage octet decoding [#3341](https://github.com/open-telemetry/opentelemetry-js/pull/3341) @legendecas diff --git a/packages/opentelemetry-sdk-trace-base/src/Tracer.ts b/packages/opentelemetry-sdk-trace-base/src/Tracer.ts index 4af02e2494..23d0f47895 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Tracer.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Tracer.ts @@ -19,8 +19,6 @@ import { InstrumentationLibrary, sanitizeAttributes, isTracingSuppressed, - AnchoredClock, - otperformance, } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { BasicTracerProvider } from './BasicTracerProvider'; @@ -74,22 +72,10 @@ export class Tracer implements api.Tracer { context = api.trace.deleteSpan(context); } const parentSpan = api.trace.getSpan(context); - let clock: AnchoredClock | undefined; - if (parentSpan) { - clock = (parentSpan as any)['_clock']; - } - - if (!clock) { - clock = new AnchoredClock(Date, otperformance); - if (parentSpan) { - (parentSpan as any)['_clock'] = clock; - } - } if (isTracingSuppressed(context)) { api.diag.debug('Instrumentation suppressed, returning Noop Span'); const nonRecordingSpan = api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT); - (nonRecordingSpan as any)['_clock'] = clock; return nonRecordingSpan; } @@ -134,7 +120,6 @@ export class Tracer implements api.Tracer { if (samplingResult.decision === api.SamplingDecision.NOT_RECORD) { api.diag.debug('Recording is off, propagating context in a non-recording span'); const nonRecordingSpan = api.trace.wrapSpanContext(spanContext); - (nonRecordingSpan as any)['_clock'] = clock; return nonRecordingSpan; } @@ -147,7 +132,6 @@ export class Tracer implements api.Tracer { parentSpanId, links, options.startTime, - clock, ); // Set initial span attributes. The attributes object may have been mutated // by the sampler, so we sanitize the merged attributes before setting them.