From 5a24edcafe0c1e8b5d5dc0e1b66886da9c4e64d0 Mon Sep 17 00:00:00 2001 From: David Luna Date: Mon, 23 Sep 2024 12:56:15 +0200 Subject: [PATCH 1/4] feat(sdk-trace-base): replace SpanAttributes with Attributes --- package-lock.json | 2 +- .../opentelemetry-sdk-trace-base/package.json | 2 +- .../src/Sampler.ts | 8 ++++---- .../opentelemetry-sdk-trace-base/src/Span.ts | 18 +++++++++--------- .../src/TimedEvent.ts | 4 ++-- .../src/export/ReadableSpan.ts | 4 ++-- .../src/sampler/ParentBasedSampler.ts | 4 ++-- .../test/common/Span.test.ts | 10 +++++----- .../test/common/Tracer.test.ts | 8 ++++---- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7663f61b9c..8f7197ce22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30714,7 +30714,7 @@ "node": ">=18" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.10.0" + "@opentelemetry/api": ">=1.3.0 <1.10.0" } }, "packages/opentelemetry-sdk-trace-base/node_modules/terser-webpack-plugin": { diff --git a/packages/opentelemetry-sdk-trace-base/package.json b/packages/opentelemetry-sdk-trace-base/package.json index 7e6a704424..9a07313df9 100644 --- a/packages/opentelemetry-sdk-trace-base/package.json +++ b/packages/opentelemetry-sdk-trace-base/package.json @@ -90,7 +90,7 @@ "webpack": "5.89.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.10.0" + "@opentelemetry/api": ">=1.3.0 <1.10.0" }, "dependencies": { "@opentelemetry/core": "1.25.1", diff --git a/packages/opentelemetry-sdk-trace-base/src/Sampler.ts b/packages/opentelemetry-sdk-trace-base/src/Sampler.ts index 0a4236e882..6824fe3cce 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Sampler.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Sampler.ts @@ -17,7 +17,7 @@ import { Context, Link, - SpanAttributes, + Attributes, SpanKind, TraceState, } from '@opentelemetry/api'; @@ -58,7 +58,7 @@ export interface SamplingResult { * Caller may call {@link Sampler}.shouldSample any number of times and * can safely cache the returned value. */ - attributes?: Readonly; + attributes?: Readonly; /** * A {@link TraceState} that will be associated with the {@link Span} through * the new {@link SpanContext}. Samplers SHOULD return the TraceState from @@ -83,7 +83,7 @@ export interface Sampler { * span to be created starts a new trace. * @param spanName of the span to be created. * @param spanKind of the span to be created. - * @param attributes Initial set of SpanAttributes for the Span being constructed. + * @param attributes Initial set of Attributes for the Span being constructed. * @param links Collection of links that will be associated with the Span to * be created. Typically useful for batch operations. * @returns a {@link SamplingResult}. @@ -93,7 +93,7 @@ export interface Sampler { traceId: string, spanName: string, spanKind: SpanKind, - attributes: SpanAttributes, + attributes: Attributes, links: Link[] ): SamplingResult; diff --git a/packages/opentelemetry-sdk-trace-base/src/Span.ts b/packages/opentelemetry-sdk-trace-base/src/Span.ts index 3b7758f138..6f68cc2505 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Span.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Span.ts @@ -21,8 +21,8 @@ import { HrTime, Link, Span as APISpan, - SpanAttributes, - SpanAttributeValue, + Attributes, + AttributeValue, SpanContext, SpanKind, SpanStatus, @@ -64,7 +64,7 @@ export class Span implements APISpan, ReadableSpan { private readonly _spanContext: SpanContext; readonly kind: SpanKind; readonly parentSpanId?: string; - readonly attributes: SpanAttributes = {}; + readonly attributes: Attributes = {}; readonly links: Link[] = []; readonly events: TimedEvent[] = []; readonly startTime: HrTime; @@ -105,7 +105,7 @@ export class Span implements APISpan, ReadableSpan { links: Link[] = [], startTime?: TimeInput, _deprecatedClock?: unknown, // keeping this argument even though it is unused to ensure backwards compatibility - attributes?: SpanAttributes + attributes?: Attributes ) { this.name = spanName; this._spanContext = spanContext; @@ -139,7 +139,7 @@ export class Span implements APISpan, ReadableSpan { return this._spanContext; } - setAttribute(key: string, value?: SpanAttributeValue): this; + setAttribute(key: string, value?: AttributeValue): this; setAttribute(key: string, value: unknown): this { if (value == null || this._isSpanEnded()) return this; if (key.length === 0) { @@ -163,7 +163,7 @@ export class Span implements APISpan, ReadableSpan { return this; } - setAttributes(attributes: SpanAttributes): this { + setAttributes(attributes: Attributes): this { for (const [k, v] of Object.entries(attributes)) { this.setAttribute(k, v); } @@ -179,7 +179,7 @@ export class Span implements APISpan, ReadableSpan { */ addEvent( name: string, - attributesOrStartTime?: SpanAttributes | TimeInput, + attributesOrStartTime?: Attributes | TimeInput, timeStamp?: TimeInput ): this { if (this._isSpanEnded()) return this; @@ -301,7 +301,7 @@ export class Span implements APISpan, ReadableSpan { } recordException(exception: Exception, time?: TimeInput): void { - const attributes: SpanAttributes = {}; + const attributes: Attributes = {}; if (typeof exception === 'string') { attributes[SEMATTRS_EXCEPTION_MESSAGE] = exception; } else if (exception) { @@ -380,7 +380,7 @@ export class Span implements APISpan, ReadableSpan { * @param value Attribute value * @returns truncated attribute value if required, otherwise same value */ - private _truncateToSize(value: SpanAttributeValue): SpanAttributeValue { + private _truncateToSize(value: AttributeValue): AttributeValue { const limit = this._attributeValueLengthLimit; // Check limit if (limit <= 0) { diff --git a/packages/opentelemetry-sdk-trace-base/src/TimedEvent.ts b/packages/opentelemetry-sdk-trace-base/src/TimedEvent.ts index 1f835ba710..068caa432d 100644 --- a/packages/opentelemetry-sdk-trace-base/src/TimedEvent.ts +++ b/packages/opentelemetry-sdk-trace-base/src/TimedEvent.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { HrTime, SpanAttributes } from '@opentelemetry/api'; +import { HrTime, Attributes } from '@opentelemetry/api'; /** * Represents a timed event. @@ -25,7 +25,7 @@ export interface TimedEvent { /** The name of the event. */ name: string; /** The attributes of the event. */ - attributes?: SpanAttributes; + attributes?: Attributes; /** Count of attributes of the event that were dropped due to collection limits */ droppedAttributesCount?: number; } diff --git a/packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts b/packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts index 20ffea4c56..34741c0323 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/ReadableSpan.ts @@ -17,7 +17,7 @@ import { SpanKind, SpanStatus, - SpanAttributes, + Attributes, HrTime, Link, SpanContext, @@ -34,7 +34,7 @@ export interface ReadableSpan { readonly startTime: HrTime; readonly endTime: HrTime; readonly status: SpanStatus; - readonly attributes: SpanAttributes; + readonly attributes: Attributes; readonly links: Link[]; readonly events: TimedEvent[]; readonly duration: HrTime; diff --git a/packages/opentelemetry-sdk-trace-base/src/sampler/ParentBasedSampler.ts b/packages/opentelemetry-sdk-trace-base/src/sampler/ParentBasedSampler.ts index 6f89ac6431..eb621adcf9 100644 --- a/packages/opentelemetry-sdk-trace-base/src/sampler/ParentBasedSampler.ts +++ b/packages/opentelemetry-sdk-trace-base/src/sampler/ParentBasedSampler.ts @@ -18,7 +18,7 @@ import { Context, isSpanContextValid, Link, - SpanAttributes, + Attributes, SpanKind, TraceFlags, trace, @@ -64,7 +64,7 @@ export class ParentBasedSampler implements Sampler { traceId: string, spanName: string, spanKind: SpanKind, - attributes: SpanAttributes, + attributes: Attributes, links: Link[] ): SamplingResult { const parentContext = trace.getSpanContext(context); 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 33808acd54..0648cbc298 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts @@ -23,8 +23,8 @@ import { SpanKind, TraceFlags, HrTime, - SpanAttributes, - SpanAttributeValue, + Attributes, + AttributeValue, } from '@opentelemetry/api'; import { DEFAULT_ATTRIBUTE_COUNT_LIMIT, @@ -266,7 +266,7 @@ describe('Span', () => { span.setAttribute(k, v); } for (const [k, v] of Object.entries(invalidAttributes)) { - span.setAttribute(k, v as unknown as SpanAttributeValue); + span.setAttribute(k, v as unknown as AttributeValue); } assert.deepStrictEqual(span.attributes, validAttributes); @@ -735,7 +735,7 @@ describe('Span', () => { ); span.setAttributes(validAttributes); - span.setAttributes(invalidAttributes as unknown as SpanAttributes); + span.setAttributes(invalidAttributes as unknown as Attributes); assert.deepStrictEqual(span.attributes, validAttributes); }); @@ -766,7 +766,7 @@ describe('Span', () => { span.addEvent('rev', { ...validAttributes, ...invalidAttributes, - } as unknown as SpanAttributes); + } as unknown as Attributes); span.end(); assert.strictEqual(span.events.length, 1); 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 70058ac79e..3d1dc91c46 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/Tracer.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/Tracer.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { - SpanAttributes, + Attributes, Context, context, createContextKey, @@ -65,7 +65,7 @@ describe('Tracer', () => { _traceId: string, _spanName: string, _spanKind: SpanKind, - attributes: SpanAttributes, + attributes: Attributes, links: Link[] ) { // The attributes object should be valid. @@ -82,7 +82,7 @@ describe('Tracer', () => { testAttribute: 'foobar', // invalid attributes should be sanitized. ...invalidAttributes, - } as unknown as SpanAttributes, + } as unknown as Attributes, traceState: this.traceState, }; } @@ -442,7 +442,7 @@ describe('Tracer', () => { const attributes = { ...validAttributes, ...invalidAttributes, - } as unknown as SpanAttributes; + } as unknown as Attributes; const links = [ { context: { From 51f997b87d57035db69a76a32d49212e4684df39 Mon Sep 17 00:00:00 2001 From: David Luna Date: Mon, 23 Sep 2024 13:28:28 +0200 Subject: [PATCH 2/4] chore(sdk-trace-base): update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index caeea8bebb..aa426e4e81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se * propagator-aws-xray * sdk-metrics * deps(sdk-metrics): remove unused lodash.merge dependency [#4905](https://github.com/open-telemetry/opentelemetry-js/pull/4905) @pichlermarc +* refactor(sdk-trace-base): replace `SpanAttributes` with `Attributes` [#5009](https://github.com/open-telemetry/opentelemetry-js/pull/5009) @david-luna ## 1.25.1 From 04d70e1356a192c605c07b27c9be2f29fc3a2322 Mon Sep 17 00:00:00 2001 From: David Luna Date: Wed, 25 Sep 2024 15:42:07 +0200 Subject: [PATCH 3/4] chore(sdk-trace-base): omve changoleg entry to the right place --- CHANGELOG.md | 1 - CHANGELOG_NEXT.md | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adf3abb50c..7e0a043a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,7 +62,6 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se * propagator-aws-xray * sdk-metrics * deps(sdk-metrics): remove unused lodash.merge dependency [#4905](https://github.com/open-telemetry/opentelemetry-js/pull/4905) @pichlermarc -* refactor(sdk-trace-base): replace `SpanAttributes` with `Attributes` [#5009](https://github.com/open-telemetry/opentelemetry-js/pull/5009) @david-luna ## 1.25.1 diff --git a/CHANGELOG_NEXT.md b/CHANGELOG_NEXT.md index a41332c0fc..b25bc2d60c 100644 --- a/CHANGELOG_NEXT.md +++ b/CHANGELOG_NEXT.md @@ -18,5 +18,6 @@ ### :house: (Internal) * chore: remove checks for unsupported node versions [#4341](https://github.com/open-telemetry/opentelemetry-js/pull/4341) @dyladan +* refactor(sdk-trace-base)!: replace `SpanAttributes` with `Attributes` [#5009](https://github.com/open-telemetry/opentelemetry-js/pull/5009) @david-luna ### :bug: (Bug Fix) From c649c4bdf36c864033248ced43995ed1b3173d4d Mon Sep 17 00:00:00 2001 From: David Luna Date: Wed, 25 Sep 2024 16:31:11 +0200 Subject: [PATCH 4/4] chore(resources): updte changelog --- CHANGELOG_NEXT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG_NEXT.md b/CHANGELOG_NEXT.md index b25bc2d60c..2ecf08018b 100644 --- a/CHANGELOG_NEXT.md +++ b/CHANGELOG_NEXT.md @@ -10,6 +10,7 @@ * chore(otel-resources): replace deprecated SpanAttributes [#4428](https://github.com/open-telemetry/opentelemetry-js/pull/4428) @JamieDanielson * feat(sdk-metrics)!: remove MeterProvider.addMetricReader() in favor of constructor option [#4419](https://github.com/open-telemetry/opentelemetry-js/pull/4419) @pichlermarc * feat(sdk-metrics)!: replace attributeKeys with custom processors option [#4532](https://github.com/open-telemetry/opentelemetry-js/pull/4532) @pichlermarc +* refactor(sdk-trace-base)!: replace `SpanAttributes` with `Attributes` [#5009](https://github.com/open-telemetry/opentelemetry-js/pull/5009) @david-luna ### :rocket: (Enhancement) @@ -18,6 +19,5 @@ ### :house: (Internal) * chore: remove checks for unsupported node versions [#4341](https://github.com/open-telemetry/opentelemetry-js/pull/4341) @dyladan -* refactor(sdk-trace-base)!: replace `SpanAttributes` with `Attributes` [#5009](https://github.com/open-telemetry/opentelemetry-js/pull/5009) @david-luna ### :bug: (Bug Fix)