diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index a463bbc871..0a57beb228 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -27,7 +27,6 @@ export * from './context/propagation/HttpTraceContext'; export * from './context/propagation/types'; export * from './baggage/propagation/HttpBaggage'; export * from './platform'; -export * from './trace/NoRecordingSpan'; export * from './trace/Plugin'; export * from './trace/sampler/AlwaysOffSampler'; export * from './trace/sampler/AlwaysOnSampler'; diff --git a/packages/opentelemetry-core/src/trace/NoRecordingSpan.ts b/packages/opentelemetry-core/src/trace/NoRecordingSpan.ts deleted file mode 100644 index 589ea5c1cf..0000000000 --- a/packages/opentelemetry-core/src/trace/NoRecordingSpan.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - SpanContext, - NoopSpan, - INVALID_SPAN_CONTEXT, -} from '@opentelemetry/api'; - -/** - * The NoRecordingSpan extends the {@link NoopSpan}, making all operations no-op - * except context propagation. - */ -export class NoRecordingSpan extends NoopSpan { - private readonly _context: SpanContext; - - constructor(spanContext: SpanContext) { - super(spanContext); - this._context = spanContext || INVALID_SPAN_CONTEXT; - } - - // Returns a SpanContext. - context(): SpanContext { - return this._context; - } -} diff --git a/packages/opentelemetry-core/test/trace/NoRecordingSpan.test.ts b/packages/opentelemetry-core/test/trace/NoRecordingSpan.test.ts deleted file mode 100644 index 87bc315c9e..0000000000 --- a/packages/opentelemetry-core/test/trace/NoRecordingSpan.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as assert from 'assert'; -import { NoRecordingSpan } from '../../src/trace/NoRecordingSpan'; -import { TraceFlags } from '@opentelemetry/api'; - -describe('NoRecordingSpan', () => { - it('propagates span contexts', () => { - const spanContext = { - traceId: 'd4cda95b652f4a1592b449d5929fda1b', - spanId: '6e0c63257de34c92', - traceFlags: TraceFlags.NONE, - }; - - const span = new NoRecordingSpan(spanContext); - assert.strictEqual(span.context(), spanContext); - span.end(); - }); -}); diff --git a/packages/opentelemetry-instrumentation-http/package.json b/packages/opentelemetry-instrumentation-http/package.json index 7c4bca3ee8..d1dc58c4a9 100644 --- a/packages/opentelemetry-instrumentation-http/package.json +++ b/packages/opentelemetry-instrumentation-http/package.json @@ -43,6 +43,7 @@ "devDependencies": { "@opentelemetry/context-async-hooks": "^0.16.0", "@opentelemetry/context-base": "^0.16.0", + "@opentelemetry/core": "^0.16.0", "@opentelemetry/node": "^0.16.0", "@opentelemetry/tracing": "^0.16.0", "@types/got": "9.6.11", @@ -70,7 +71,6 @@ }, "dependencies": { "@opentelemetry/api": "^0.16.0", - "@opentelemetry/core": "^0.16.0", "@opentelemetry/instrumentation": "^0.16.0", "@opentelemetry/semantic-conventions": "^0.16.0", "semver": "^7.1.3" diff --git a/packages/opentelemetry-instrumentation-http/src/http.ts b/packages/opentelemetry-instrumentation-http/src/http.ts index 22a6fd796b..f04d7de7e2 100644 --- a/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/packages/opentelemetry-instrumentation-http/src/http.ts @@ -22,13 +22,11 @@ import { SpanOptions, SpanStatus, setSpan, - SpanContext, - TraceFlags, ROOT_CONTEXT, getSpan, suppressInstrumentation, + NoopSpan, } from '@opentelemetry/api'; -import { NoRecordingSpan } from '@opentelemetry/core'; import type * as http from 'http'; import type * as https from 'https'; import { Socket } from 'net'; @@ -61,11 +59,6 @@ export class HttpInstrumentation extends InstrumentationBase { /** keep track on spans not ended */ private readonly _spanNotEnded: WeakSet = new WeakSet(); private readonly _version = process.versions.node; - private readonly _emptySpanContext: SpanContext = { - traceId: '', - spanId: '', - traceFlags: TraceFlags.NONE, - }; constructor(config: HttpInstrumentationConfig & InstrumentationConfig = {}) { super( @@ -580,7 +573,7 @@ export class HttpInstrumentation extends InstrumentationBase { private _startHttpSpan(name: string, options: SpanOptions) { /* - * If a parent is required but not present, we use a `NoRecordingSpan` to still + * If a parent is required but not present, we use a `NoopSpan` to still * propagate context without recording it. */ const requireParent = @@ -594,7 +587,7 @@ export class HttpInstrumentation extends InstrumentationBase { if (requireParent === true && currentSpan === undefined) { // TODO: Refactor this when a solution is found in // https://github.com/open-telemetry/opentelemetry-specification/issues/530 - span = new NoRecordingSpan(this._emptySpanContext); + span = new NoopSpan(); } else if (requireParent === true && currentSpan?.context().isRemote) { span = currentSpan; } else { diff --git a/packages/opentelemetry-node/test/NodeTracerProvider.test.ts b/packages/opentelemetry-node/test/NodeTracerProvider.test.ts index fab7c8ee78..aeb43ed3c1 100644 --- a/packages/opentelemetry-node/test/NodeTracerProvider.test.ts +++ b/packages/opentelemetry-node/test/NodeTracerProvider.test.ts @@ -21,12 +21,9 @@ import { setSpan, setSpanContext, getSpan, + NoopSpan, } from '@opentelemetry/api'; -import { - AlwaysOnSampler, - AlwaysOffSampler, - NoRecordingSpan, -} from '@opentelemetry/core'; +import { AlwaysOnSampler, AlwaysOffSampler } from '@opentelemetry/core'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { Span } from '@opentelemetry/tracing'; import { Resource, TELEMETRY_SDK_RESOURCE } from '@opentelemetry/resources'; @@ -124,7 +121,7 @@ describe('NodeTracerProvider', () => { logger: new NoopLogger(), }); const span = provider.getTracer('default').startSpan('my-span'); - assert.ok(span instanceof NoRecordingSpan); + assert.ok(span instanceof NoopSpan); assert.strictEqual(span.context().traceFlags, TraceFlags.NONE); assert.strictEqual(span.isRecording(), false); }); diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index 676a2a3209..665c155bee 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -21,14 +21,13 @@ import { SpanKind, SpanOptions, SpanStatus, - SpanContext, - TraceFlags, setSpan, ROOT_CONTEXT, getSpan, suppressInstrumentation, + NoopSpan, } from '@opentelemetry/api'; -import { BasePlugin, NoRecordingSpan } from '@opentelemetry/core'; +import { BasePlugin } from '@opentelemetry/core'; import type { ClientRequest, IncomingMessage, @@ -60,12 +59,6 @@ export class HttpPlugin extends BasePlugin { /** keep track on spans not ended */ private readonly _spanNotEnded: WeakSet; - private readonly _emptySpanContext: SpanContext = { - traceId: '', - spanId: '', - traceFlags: TraceFlags.NONE, - }; - constructor(readonly moduleName: string, readonly version: string) { super(`@opentelemetry/plugin-${moduleName}`, VERSION); // For now component is equal to moduleName but it can change in the future. @@ -439,7 +432,7 @@ export class HttpPlugin extends BasePlugin { private _startHttpSpan(name: string, options: SpanOptions) { /* - * If a parent is required but not present, we use a `NoRecordingSpan` to still + * If a parent is required but not present, we use a `NoopSpan` to still * propagate context without recording it. */ const requireParent = @@ -453,7 +446,7 @@ export class HttpPlugin extends BasePlugin { if (requireParent === true && currentSpan === undefined) { // TODO: Refactor this when a solution is found in // https://github.com/open-telemetry/opentelemetry-specification/issues/530 - span = new NoRecordingSpan(plugin._emptySpanContext); + span = new NoopSpan(); } else if (requireParent === true && currentSpan?.context().isRemote) { span = currentSpan; } else { diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index fefdb00dfd..d4f80344b9 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -18,7 +18,6 @@ import * as api from '@opentelemetry/api'; import { ConsoleLogger, InstrumentationLibrary, - NoRecordingSpan, IdGenerator, RandomIdGenerator, sanitizeAttributes, @@ -104,7 +103,7 @@ export class Tracer implements api.Tracer { const spanContext = { traceId, spanId, traceFlags, traceState }; if (samplingResult.decision === api.SamplingDecision.NOT_RECORD) { this.logger.debug('Recording is off, starting no recording span'); - return new NoRecordingSpan(spanContext); + return new api.NoopSpan(spanContext); } const span = new Span( diff --git a/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts b/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts index 91e3332008..7c43d868ac 100644 --- a/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts +++ b/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts @@ -20,6 +20,7 @@ import { TraceFlags, ROOT_CONTEXT, NoopLogger, + NoopSpan, setSpan, setSpanContext, getSpan, @@ -27,7 +28,6 @@ import { import { AlwaysOnSampler, AlwaysOffSampler, - NoRecordingSpan, TraceState, } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; @@ -264,7 +264,7 @@ describe('BasicTracerProvider', () => { logger: new NoopLogger(), }).getTracer('default'); const span = tracer.startSpan('my-span'); - assert.ok(span instanceof NoRecordingSpan); + assert.ok(span instanceof NoopSpan); const context = span.context(); assert.ok(context.traceId.match(/[a-f0-9]{32}/)); assert.ok(context.spanId.match(/[a-f0-9]{16}/));