From df1dcf1fa3b643bbdca284db0f1782db05f4e322 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Thu, 9 Jan 2025 11:15:08 +0100 Subject: [PATCH 1/2] feat(core)!: remove deprecated InstrumentationLibrary --- .../otlp-transformer/src/trace/internal.ts | 22 ++-- .../otlp-transformer/test/trace.test.ts | 2 +- .../opentelemetry-core/src/common/types.ts | 12 --- packages/opentelemetry-core/src/index.ts | 1 - .../src/transform.ts | 6 +- .../test/jaeger.test.ts | 2 +- .../test/transform.test.ts | 10 +- .../test/helper.ts | 2 +- .../test/node/zipkin.test.ts | 14 +-- .../opentelemetry-sdk-trace-base/src/Span.ts | 8 +- .../src/Tracer.ts | 10 +- .../src/export/ConsoleSpanExporter.ts | 2 +- .../src/export/ReadableSpan.ts | 4 +- .../test/common/Span.test.ts | 100 +++++++++--------- .../test/common/Tracer.test.ts | 6 +- .../common/export/ConsoleSpanExporter.test.ts | 4 +- .../common/export/SimpleSpanProcessor.test.ts | 12 +-- 17 files changed, 102 insertions(+), 115 deletions(-) diff --git a/experimental/packages/otlp-transformer/src/trace/internal.ts b/experimental/packages/otlp-transformer/src/trace/internal.ts index 06aab08bcc..5799b3a5ea 100644 --- a/experimental/packages/otlp-transformer/src/trace/internal.ts +++ b/experimental/packages/otlp-transformer/src/trace/internal.ts @@ -114,22 +114,22 @@ export function createExportTraceServiceRequest( function createResourceMap(readableSpans: ReadableSpan[]) { const resourceMap: Map> = new Map(); for (const record of readableSpans) { - let ilmMap = resourceMap.get(record.resource); + let ilsMap = resourceMap.get(record.resource); - if (!ilmMap) { - ilmMap = new Map(); - resourceMap.set(record.resource, ilmMap); + if (!ilsMap) { + ilsMap = new Map(); + resourceMap.set(record.resource, ilsMap); } // TODO this is duplicated in basic tracer. Consolidate on a common helper in core - const instrumentationLibraryKey = `${record.instrumentationLibrary.name}@${ - record.instrumentationLibrary.version || '' - }:${record.instrumentationLibrary.schemaUrl || ''}`; - let records = ilmMap.get(instrumentationLibraryKey); + const instrumentationScopeKey = `${record.instrumentationScope.name}@${ + record.instrumentationScope.version || '' + }:${record.instrumentationScope.schemaUrl || ''}`; + let records = ilsMap.get(instrumentationScopeKey); if (!records) { records = []; - ilmMap.set(instrumentationLibraryKey, records); + ilsMap.set(instrumentationScopeKey, records); } records.push(record); @@ -161,10 +161,10 @@ function spanRecordsToResourceSpans( scopeResourceSpans.push({ scope: createInstrumentationScope( - scopeSpans[0].instrumentationLibrary + scopeSpans[0].instrumentationScope ), spans: spans, - schemaUrl: scopeSpans[0].instrumentationLibrary.schemaUrl, + schemaUrl: scopeSpans[0].instrumentationScope.schemaUrl, }); } ilmEntry = ilmIterator.next(); diff --git a/experimental/packages/otlp-transformer/test/trace.test.ts b/experimental/packages/otlp-transformer/test/trace.test.ts index 81ad9eb2cc..7641d9bf4d 100644 --- a/experimental/packages/otlp-transformer/test/trace.test.ts +++ b/experimental/packages/otlp-transformer/test/trace.test.ts @@ -256,7 +256,7 @@ describe('Trace', () => { }, }, ], - instrumentationLibrary: { + instrumentationScope: { name: 'myLib', version: '0.1.0', schemaUrl: 'http://url.to.schema', diff --git a/packages/opentelemetry-core/src/common/types.ts b/packages/opentelemetry-core/src/common/types.ts index 2c6d9b7d5b..3b102fac65 100644 --- a/packages/opentelemetry-core/src/common/types.ts +++ b/packages/opentelemetry-core/src/common/types.ts @@ -39,18 +39,6 @@ export interface ShimWrapped extends Function { __original: Function; } -/** - * An instrumentation library consists of the name and optional version - * used to obtain a tracer or meter from a provider. This metadata is made - * available on ReadableSpan and MetricRecord for use by the export pipeline. - * @deprecated Use {@link InstrumentationScope} instead. - */ -export interface InstrumentationLibrary { - readonly name: string; - readonly version?: string; - readonly schemaUrl?: string; -} - /** * An instrumentation scope consists of the name and optional version * used to obtain a tracer or meter from a provider. This metadata is made diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 0c2dc7c1a8..ca08233123 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -42,7 +42,6 @@ export { } from './common/time'; export { ErrorHandler, - InstrumentationLibrary, InstrumentationScope, ShimWrapped, TimeOriginLegacy, diff --git a/packages/opentelemetry-exporter-jaeger/src/transform.ts b/packages/opentelemetry-exporter-jaeger/src/transform.ts index b91e0c2929..9a82e23140 100644 --- a/packages/opentelemetry-exporter-jaeger/src/transform.ts +++ b/packages/opentelemetry-exporter-jaeger/src/transform.ts @@ -75,14 +75,14 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan { }) ); - if (span.instrumentationLibrary) { + if (span.instrumentationScope) { tags.push({ key: 'otel.library.name', - value: toTagValue(span.instrumentationLibrary.name), + value: toTagValue(span.instrumentationScope.name), }); tags.push({ key: 'otel.library.version', - value: toTagValue(span.instrumentationLibrary.version), + value: toTagValue(span.instrumentationScope.version), }); } diff --git a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts index 24cd64a73d..e6115fba5a 100644 --- a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts @@ -49,7 +49,7 @@ describe('JaegerExporter', () => { resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'opentelemetry', }), - instrumentationLibrary: { + instrumentationScope: { name: 'default', version: '0.0.1', }, diff --git a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts index 6aade85f5a..ad21c6f97f 100644 --- a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts @@ -78,7 +78,7 @@ describe('transform', () => { version: 1, cost: 112.12, }), - instrumentationLibrary: { + instrumentationScope: { name: 'default', version: '0.0.1', }, @@ -178,7 +178,7 @@ describe('transform', () => { events: [], duration: [32, 800000000], resource: Resource.empty(), - instrumentationLibrary: { + instrumentationScope: { name: 'default', version: '0.0.1', }, @@ -248,7 +248,7 @@ describe('transform', () => { events: [], duration: [32, 800000000], resource: Resource.empty(), - instrumentationLibrary: { + instrumentationScope: { name: 'default', version: '0.0.1', }, @@ -296,7 +296,7 @@ describe('transform', () => { events: [], duration: [32, 800000000], resource: Resource.empty(), - instrumentationLibrary: { + instrumentationScope: { name: 'default', version: '0.0.1', }, @@ -361,7 +361,7 @@ describe('transform', () => { version: 1, cost: 112.12, }), - instrumentationLibrary: { + instrumentationScope: { name: 'default', version: '0.0.1', }, diff --git a/packages/opentelemetry-exporter-zipkin/test/helper.ts b/packages/opentelemetry-exporter-zipkin/test/helper.ts index bd4d300a1e..da6176cf54 100644 --- a/packages/opentelemetry-exporter-zipkin/test/helper.ts +++ b/packages/opentelemetry-exporter-zipkin/test/helper.ts @@ -44,7 +44,7 @@ export const mockedReadableSpan: ReadableSpan = { version: 1, cost: 112.12, }), - instrumentationLibrary: { name: 'default', version: '0.0.1' }, + instrumentationScope: { name: 'default', version: '0.0.1' }, droppedAttributesCount: 0, droppedEventsCount: 0, droppedLinksCount: 0, diff --git a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts index dfcaf6188a..c36722f891 100644 --- a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts @@ -55,7 +55,7 @@ function getReadableSpan() { links: [], events: [], resource: Resource.empty(), - instrumentationLibrary: { name: 'default', version: '0.0.1' }, + instrumentationScope: { name: 'default', version: '0.0.1' }, droppedAttributesCount: 0, droppedEventsCount: 0, droppedLinksCount: 0, @@ -166,7 +166,7 @@ describe('Zipkin Exporter - node', () => { }, ], resource: Resource.empty(), - instrumentationLibrary: { name: 'default', version: '0.0.1' }, + instrumentationScope: { name: 'default', version: '0.0.1' }, droppedAttributesCount: 0, droppedEventsCount: 0, droppedLinksCount: 0, @@ -192,7 +192,7 @@ describe('Zipkin Exporter - node', () => { links: [], events: [], resource: Resource.empty(), - instrumentationLibrary: { name: 'default', version: '0.0.1' }, + instrumentationScope: { name: 'default', version: '0.0.1' }, droppedAttributesCount: 0, droppedEventsCount: 0, droppedLinksCount: 0, @@ -387,7 +387,7 @@ describe('Zipkin Exporter - node', () => { resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: resource_service_name, }), - instrumentationLibrary: { name: 'default', version: '0.0.1' }, + instrumentationScope: { name: 'default', version: '0.0.1' }, droppedAttributesCount: 0, droppedEventsCount: 0, droppedLinksCount: 0, @@ -413,7 +413,7 @@ describe('Zipkin Exporter - node', () => { resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: resource_service_name_prime, }), - instrumentationLibrary: { name: 'default', version: '0.0.1' }, + instrumentationScope: { name: 'default', version: '0.0.1' }, droppedAttributesCount: 0, droppedEventsCount: 0, droppedLinksCount: 0, @@ -481,7 +481,7 @@ describe('Zipkin Exporter - node', () => { }, ], resource: Resource.empty(), - instrumentationLibrary: { name: 'default', version: '0.0.1' }, + instrumentationScope: { name: 'default', version: '0.0.1' }, droppedAttributesCount: 0, droppedEventsCount: 0, droppedLinksCount: 0, @@ -507,7 +507,7 @@ describe('Zipkin Exporter - node', () => { links: [], events: [], resource: Resource.empty(), - instrumentationLibrary: { name: 'default', version: '0.0.1' }, + instrumentationScope: { name: 'default', version: '0.0.1' }, droppedAttributesCount: 0, droppedEventsCount: 0, droppedLinksCount: 0, diff --git a/packages/opentelemetry-sdk-trace-base/src/Span.ts b/packages/opentelemetry-sdk-trace-base/src/Span.ts index 9d567e794d..f28f74a3e1 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Span.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Span.ts @@ -35,7 +35,7 @@ import { getTimeOrigin, hrTime, hrTimeDuration, - InstrumentationLibrary, + InstrumentationScope, isAttributeValue, isTimeInput, isTimeInputHrTime, @@ -62,7 +62,7 @@ export type Span = APISpan & ReadableSpan; interface SpanOptions { resource: IResource; - scope: InstrumentationLibrary; + scope: InstrumentationScope; context: Context; spanContext: SpanContext; name: string; @@ -89,7 +89,7 @@ export class SpanImpl implements Span { readonly events: TimedEvent[] = []; readonly startTime: HrTime; readonly resource: IResource; - readonly instrumentationLibrary: InstrumentationLibrary; + readonly instrumentationScope: InstrumentationScope; private _droppedAttributesCount = 0; private _droppedEventsCount: number = 0; @@ -132,7 +132,7 @@ export class SpanImpl implements Span { this.links = opts.links || []; this.startTime = this._getTime(opts.startTime ?? now); this.resource = opts.resource; - this.instrumentationLibrary = opts.scope; + this.instrumentationScope = opts.scope; if (opts.attributes != null) { this.setAttributes(opts.attributes); diff --git a/packages/opentelemetry-sdk-trace-base/src/Tracer.ts b/packages/opentelemetry-sdk-trace-base/src/Tracer.ts index c7ebdcc010..28f0e91adf 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Tracer.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Tracer.ts @@ -16,7 +16,7 @@ import * as api from '@opentelemetry/api'; import { - InstrumentationLibrary, + InstrumentationScope, sanitizeAttributes, isTracingSuppressed, } from '@opentelemetry/core'; @@ -37,7 +37,7 @@ export class Tracer implements api.Tracer { private readonly _generalLimits: GeneralLimits; private readonly _spanLimits: SpanLimits; private readonly _idGenerator: IdGenerator; - readonly instrumentationLibrary: InstrumentationLibrary; + readonly instrumentationScope: InstrumentationScope; private readonly _resource: IResource; private readonly _spanProcessor: SpanProcessor; @@ -46,7 +46,7 @@ export class Tracer implements api.Tracer { * Constructs a new Tracer instance. */ constructor( - instrumentationLibrary: InstrumentationLibrary, + instrumentationScope: InstrumentationScope, config: TracerConfig, resource: IResource, spanProcessor: SpanProcessor @@ -58,7 +58,7 @@ export class Tracer implements api.Tracer { this._idGenerator = config.idGenerator || new RandomIdGenerator(); this._resource = resource; this._spanProcessor = spanProcessor; - this.instrumentationLibrary = instrumentationLibrary; + this.instrumentationScope = instrumentationScope; } /** @@ -143,7 +143,7 @@ export class Tracer implements api.Tracer { const span = new SpanImpl({ resource: this._resource, - scope: this.instrumentationLibrary, + scope: this.instrumentationScope, context, spanContext, name, diff --git a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts index 39397e6969..6403391254 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts @@ -67,7 +67,7 @@ export class ConsoleSpanExporter implements SpanExporter { resource: { attributes: span.resource.attributes, }, - instrumentationScope: span.instrumentationLibrary, + instrumentationScope: span.instrumentationScope, traceId: span.spanContext().traceId, parentId: span.parentSpanId, traceState: span.spanContext().traceState?.serialize(), diff --git a/packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts b/packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts index 34741c0323..15b4ceff9c 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts @@ -23,7 +23,7 @@ import { SpanContext, } from '@opentelemetry/api'; import { IResource } from '@opentelemetry/resources'; -import { InstrumentationLibrary } from '@opentelemetry/core'; +import { InstrumentationScope } from '@opentelemetry/core'; import { TimedEvent } from '../TimedEvent'; export interface ReadableSpan { @@ -40,7 +40,7 @@ export interface ReadableSpan { readonly duration: HrTime; readonly ended: boolean; readonly resource: IResource; - readonly instrumentationLibrary: InstrumentationLibrary; + readonly instrumentationScope: InstrumentationScope; readonly droppedAttributesCount: number; readonly droppedEventsCount: number; readonly droppedLinksCount: number; diff --git a/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts index 1e9297b7b0..cff451c43c 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts @@ -78,7 +78,7 @@ describe('Span', () => { it('should create a Span instance', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -93,7 +93,7 @@ describe('Span', () => { it('should have valid startTime', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -110,7 +110,7 @@ describe('Span', () => { it('should have valid endTime', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -134,7 +134,7 @@ describe('Span', () => { it('should have a duration', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -149,7 +149,7 @@ describe('Span', () => { it('should ensure duration is never negative even if provided with inconsistent times', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -166,7 +166,7 @@ describe('Span', () => { it('should have valid event.time', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -185,7 +185,7 @@ describe('Span', () => { it('should have an entered time for event', () => { const startTime = Date.now(); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -209,7 +209,7 @@ describe('Span', () => { it('should have an entered time for event - ', () => { const startTime = Date.now(); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -232,7 +232,7 @@ describe('Span', () => { it('should get the span context of span', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -253,7 +253,7 @@ describe('Span', () => { describe('isRecording', () => { it('should return true when span is not ended', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -267,7 +267,7 @@ describe('Span', () => { }); it('should return false when span is ended', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -285,7 +285,7 @@ describe('Span', () => { describe('when default options set', () => { it('should set an attribute', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -307,7 +307,7 @@ describe('Span', () => { it('should be able to overwrite attributes', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -336,7 +336,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -371,7 +371,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -418,7 +418,7 @@ describe('Span', () => { it('should truncate value when attributes are passed to the constructor', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -441,7 +441,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -481,7 +481,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -512,7 +512,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -567,7 +567,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -610,7 +610,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -645,7 +645,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -684,7 +684,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -743,7 +743,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -792,7 +792,7 @@ describe('Span', () => { describe('setAttributes', () => { it('should be able to set multiple attributes', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -812,7 +812,7 @@ describe('Span', () => { describe('addEvent', () => { it('should add an event', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -828,7 +828,7 @@ describe('Span', () => { it('should sanitize attribute values', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -851,7 +851,7 @@ describe('Span', () => { it('should drop extra events', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -881,7 +881,7 @@ describe('Span', () => { it('should store the count of dropped events in droppedEventsCount', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -906,7 +906,7 @@ describe('Span', () => { }).getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -925,7 +925,7 @@ describe('Span', () => { it('should set an error status', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -947,7 +947,7 @@ describe('Span', () => { it('should drop non-string status message', function () { const warnStub = sinon.spy(diag, 'warn'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -973,7 +973,7 @@ describe('Span', () => { it('should return ReadableSpan', () => { const parentId = '5c1c63257de34c67'; const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -995,15 +995,15 @@ describe('Span', () => { assert.deepStrictEqual(span.links, []); assert.deepStrictEqual(span.events, []); - assert.ok(span.instrumentationLibrary); - const { name, version } = span.instrumentationLibrary; + assert.ok(span.instrumentationScope); + const { name, version } = span.instrumentationScope; assert.strictEqual(name, 'default'); assert.strictEqual(version, undefined); }); it('should return ReadableSpan with attributes', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1032,7 +1032,7 @@ describe('Span', () => { it('should return ReadableSpan with links', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1064,7 +1064,7 @@ describe('Span', () => { it('should be possible to add a link after span creation', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1088,7 +1088,7 @@ describe('Span', () => { it('should be possible to add multiple links after span creation', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1122,7 +1122,7 @@ describe('Span', () => { it('should return ReadableSpan with events', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1160,7 +1160,7 @@ describe('Span', () => { it('should return ReadableSpan with new status', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1187,7 +1187,7 @@ describe('Span', () => { it('should only end a span once', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1204,7 +1204,7 @@ describe('Span', () => { it('should update name', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1223,7 +1223,7 @@ describe('Span', () => { it('should have ended', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1330,7 +1330,7 @@ describe('Span', () => { describe(`when exception is (${JSON.stringify(key)})`, () => { it('should NOT record an exception', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1353,7 +1353,7 @@ describe('Span', () => { }); it('should record an exception', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1389,7 +1389,7 @@ describe('Span', () => { const error: Exception = errorObj.obj; it('should record an exception', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1422,7 +1422,7 @@ describe('Span', () => { describe('when time is provided', () => { it('should record an exception with provided time', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1443,7 +1443,7 @@ describe('Span', () => { describe('when exception code is numeric', () => { it('should record an exception with string value', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -1464,7 +1464,7 @@ describe('Span', () => { describe('when attributes are specified', () => { it('should store specified attributes', () => { const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, diff --git a/packages/opentelemetry-sdk-trace-base/test/common/Tracer.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/Tracer.test.ts index 41e374e15c..261221780a 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/Tracer.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/Tracer.test.ts @@ -29,7 +29,7 @@ import { TraceState, } from '@opentelemetry/api'; import { - InstrumentationLibrary, + InstrumentationScope, sanitizeAttributes, suppressTracing, } from '@opentelemetry/core'; @@ -181,7 +181,7 @@ describe('Tracer', () => { assert.strictEqual(span.spanContext().traceState, traceState); }); - it('should have an instrumentationLibrary', () => { + it('should have an instrumentationScope', () => { const tracer = new Tracer( { name: 'default', version: '0.0.1' }, {}, @@ -189,7 +189,7 @@ describe('Tracer', () => { tracerProvider['_activeSpanProcessor'] ); - const lib: InstrumentationLibrary = tracer.instrumentationLibrary; + const lib: InstrumentationScope = tracer.instrumentationScope; assert.strictEqual(lib.name, 'default'); assert.strictEqual(lib.version, '0.0.1'); diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts index 1e41f12b77..2d57a1cc57 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts @@ -99,10 +99,10 @@ describe('ConsoleSpanExporter', () => { assert.ok(consoleSpan.id === firstSpan.spanContext().spanId); assert.ok(keys === expectedKeys, 'expectedKeys'); assert.ok( - firstSpan.instrumentationLibrary.name === instrumentationScopeName + firstSpan.instrumentationScope.name === instrumentationScopeName ); assert.ok( - firstSpan.instrumentationLibrary.version === + firstSpan.instrumentationScope.version === instrumentationScopeVersion ); diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts index 745cd2c82c..7bb23021ae 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts @@ -66,7 +66,7 @@ describe('SimpleSpanProcessor', () => { }; const tracer = provider.getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -94,7 +94,7 @@ describe('SimpleSpanProcessor', () => { }; const tracer = provider.getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -123,7 +123,7 @@ describe('SimpleSpanProcessor', () => { }; const tracer = provider.getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -190,7 +190,7 @@ describe('SimpleSpanProcessor', () => { const tracer = providerWithAsyncResource.getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -235,7 +235,7 @@ describe('SimpleSpanProcessor', () => { }; const tracer = providerWithAsyncResource.getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, @@ -298,7 +298,7 @@ describe('SimpleSpanProcessor', () => { }; const tracer = provider.getTracer('default'); const span = new SpanImpl({ - scope: tracer.instrumentationLibrary, + scope: tracer.instrumentationScope, resource: tracer['_resource'], context: ROOT_CONTEXT, spanContext, From b575c1e247fc7f2e21c7214654c936049d00a30d Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Thu, 9 Jan 2025 11:29:59 +0100 Subject: [PATCH 2/2] chore: changelog and lint fixes --- CHANGELOG.md | 8 ++++++++ .../packages/otlp-transformer/src/trace/internal.ts | 4 +--- .../test/common/export/ConsoleSpanExporter.test.ts | 3 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d2af8ed12..4c9a142f92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,14 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se * refactor(sdk-trace-base)!: remove `new Span` constructor in favor of `Tracer.startSpan` API [#5048](https://github.com/open-telemetry/opentelemetry-js/pull/5048) @david-luna * refactor(sdk-trace-base)!: remove `BasicTracerProvider.addSpanProcessor` API in favor of constructor options. [#5134](https://github.com/open-telemetry/opentelemetry-js/pull/5134) @david-luna * refactor(sdk-trace-base)!: make `resource` property private in `BasicTracerProvider` and remove `getActiveSpanProcessor` API. [#5192](https://github.com/open-telemetry/opentelemetry-js/pull/5192) @david-luna +* feat(core)!: remove deprecated type `InstrumentationLibrary` [#5308](https://github.com/open-telemetry/opentelemetry-js/pull/5308) @pichlermarc + * (user-facing): please use equivalent type `InstrumentationScope` instead +* feat(sdk-trace-base)!: replace usages fo `InstrumentationLibrary` with `InstrumentationScope` [#5308](https://github.com/open-telemetry/opentelemetry-js/pull/5308) @pichlermarc + * (user-facing) rename `Tracer.instrumentationLibrary` -> `Tracer.instrumentationScope` + * (user-facing) rename `ReadableSpan.instrumentationLibrary` -> `ReadableSpan.instrumentationScope` + * also renames the property in implementations of `ReadableSpan` +* feat(exporter-jaeger): use `ReadableSpan.instrumentationScope` over `ReadableSpan.instrumentationLibrary` [#5308](https://github.com/open-telemetry/opentelemetry-js/pull/5308) @pichlermarc +* feat(exporter-zipkin): use `ReadableSpan.instrumentationScope` over `ReadableSpan.instrumentationLibrary` [#5308](https://github.com/open-telemetry/opentelemetry-js/pull/5308) @pichlermarc ### :rocket: (Enhancement) diff --git a/experimental/packages/otlp-transformer/src/trace/internal.ts b/experimental/packages/otlp-transformer/src/trace/internal.ts index 5799b3a5ea..da94baf747 100644 --- a/experimental/packages/otlp-transformer/src/trace/internal.ts +++ b/experimental/packages/otlp-transformer/src/trace/internal.ts @@ -160,9 +160,7 @@ function spanRecordsToResourceSpans( ); scopeResourceSpans.push({ - scope: createInstrumentationScope( - scopeSpans[0].instrumentationScope - ), + scope: createInstrumentationScope(scopeSpans[0].instrumentationScope), spans: spans, schemaUrl: scopeSpans[0].instrumentationScope.schemaUrl, }); diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts index 2d57a1cc57..3390ea56af 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts @@ -102,8 +102,7 @@ describe('ConsoleSpanExporter', () => { firstSpan.instrumentationScope.name === instrumentationScopeName ); assert.ok( - firstSpan.instrumentationScope.version === - instrumentationScopeVersion + firstSpan.instrumentationScope.version === instrumentationScopeVersion ); assert.ok(spyExport.calledOnce);