From 97276869cd90584c2d7618df2af18c8de37faf86 Mon Sep 17 00:00:00 2001 From: Jamie Danielson Date: Fri, 19 Jan 2024 06:47:12 -0500 Subject: [PATCH 1/2] chore(shim-opentracing): replace deprecated spanAttributes (#4430) * chore(shim-opentracing): replace deprecated spanAttributes * update minimum api version to 1.1 * keep newline in package.json * update changelog --- CHANGELOG_NEXT.md | 1 + package-lock.json | 4 ++-- .../package.json | 2 +- .../src/shim.ts | 20 +++++++++---------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG_NEXT.md b/CHANGELOG_NEXT.md index 1865224d25..5d735167aa 100644 --- a/CHANGELOG_NEXT.md +++ b/CHANGELOG_NEXT.md @@ -2,6 +2,7 @@ ### :boom: Breaking Change +* chore(shim-opentracing): replace deprecated SpanAttributes [#4430](https://github.com/open-telemetry/opentelemetry-js/pull/4430) @JamieDanielson * chore(otel-core): replace deprecated SpanAttributes [#4408](https://github.com/open-telemetry/opentelemetry-js/pull/4408) @JamieDanielson ### :rocket: (Enhancement) diff --git a/package-lock.json b/package-lock.json index 5a1c6d4721..9c685a2e95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31769,7 +31769,7 @@ "opentracing": "^0.14.4" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.8.0", + "@opentelemetry/api": ">=1.1.0 <1.8.0", "@opentelemetry/propagator-b3": "1.18.1", "@opentelemetry/propagator-jaeger": "1.18.1", "@opentelemetry/sdk-trace-base": "1.18.1", @@ -37882,7 +37882,7 @@ "@opentelemetry/shim-opentracing": { "version": "file:packages/opentelemetry-shim-opentracing", "requires": { - "@opentelemetry/api": ">=1.0.0 <1.8.0", + "@opentelemetry/api": ">=1.1.0 <1.8.0", "@opentelemetry/core": "1.18.1", "@opentelemetry/propagator-b3": "1.18.1", "@opentelemetry/propagator-jaeger": "1.18.1", diff --git a/packages/opentelemetry-shim-opentracing/package.json b/packages/opentelemetry-shim-opentracing/package.json index 073ed472e7..1f1d2f4bba 100644 --- a/packages/opentelemetry-shim-opentracing/package.json +++ b/packages/opentelemetry-shim-opentracing/package.json @@ -42,7 +42,7 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.8.0", + "@opentelemetry/api": ">=1.1.0 <1.8.0", "@opentelemetry/propagator-b3": "1.18.1", "@opentelemetry/propagator-jaeger": "1.18.1", "@opentelemetry/sdk-trace-base": "1.18.1", diff --git a/packages/opentelemetry-shim-opentracing/src/shim.ts b/packages/opentelemetry-shim-opentracing/src/shim.ts index 8b4ecd1bf6..ef7ca8e257 100644 --- a/packages/opentelemetry-shim-opentracing/src/shim.ts +++ b/packages/opentelemetry-shim-opentracing/src/shim.ts @@ -16,8 +16,8 @@ import * as api from '@opentelemetry/api'; import { - SpanAttributes, - SpanAttributeValue, + Attributes, + AttributeValue, SpanStatusCode, TextMapPropagator, } from '@opentelemetry/api'; @@ -287,7 +287,7 @@ export class SpanShim extends opentracing.Span { * @param eventName name of the event. * @param payload an arbitrary object to be attached to the event. */ - override logEvent(eventName: string, payload?: SpanAttributes): void { + override logEvent(eventName: string, payload?: Attributes): void { this._logInternal(eventName, payload); } @@ -297,7 +297,7 @@ export class SpanShim extends opentracing.Span { * @param keyValuePairs a set of key-value pairs to be used as event attributes * @param timestamp optional timestamp for the event */ - override log(keyValuePairs: SpanAttributes, timestamp?: number): this { + override log(keyValuePairs: Attributes, timestamp?: number): this { const entries = Object.entries(keyValuePairs); const eventEntry = entries.find(([key, _]) => key === 'event'); const eventName = eventEntry?.[1] || 'log'; @@ -309,7 +309,7 @@ export class SpanShim extends opentracing.Span { private _logInternal( eventName: string, - attributes: SpanAttributes | undefined, + attributes: Attributes | undefined, timestamp?: number ): void { if (attributes && eventName === 'error') { @@ -321,7 +321,7 @@ export class SpanShim extends opentracing.Span { return; } - const mappedAttributes: api.SpanAttributes = {}; + const mappedAttributes: api.Attributes = {}; for (const [k, v] of entries) { switch (k) { case 'error.kind': { @@ -352,7 +352,7 @@ export class SpanShim extends opentracing.Span { * Adds a set of tags to the span. * @param keyValueMap set of KV pairs representing tags */ - override addTags(keyValueMap: SpanAttributes): this { + override addTags(keyValueMap: Attributes): this { for (const [key, value] of Object.entries(keyValueMap)) { if (this._setErrorAsSpanStatusCode(key, value)) { continue; @@ -370,7 +370,7 @@ export class SpanShim extends opentracing.Span { * @param key key for the tag * @param value value for the tag */ - override setTag(key: string, value: SpanAttributeValue): this { + override setTag(key: string, value: AttributeValue): this { if (this._setErrorAsSpanStatusCode(key, value)) { return this; } @@ -398,7 +398,7 @@ export class SpanShim extends opentracing.Span { private _setErrorAsSpanStatusCode( key: string, - value: SpanAttributeValue | undefined + value: AttributeValue | undefined ): boolean { if (key === opentracing.Tags.ERROR) { const statusCode = SpanShim._mapErrorTag(value); @@ -409,7 +409,7 @@ export class SpanShim extends opentracing.Span { } private static _mapErrorTag( - value: SpanAttributeValue | undefined + value: AttributeValue | undefined ): SpanStatusCode { switch (value) { case true: From 0aba75ceefb2ee1cf6e576b0ccda9ee289d62cb6 Mon Sep 17 00:00:00 2001 From: Jamie Danielson Date: Mon, 22 Jan 2024 10:35:50 -0500 Subject: [PATCH 2/2] chore(otel-resources): replace deprecated spanAttributes (#4428) * chore(otel-resources): replace deprecated spanAttributes * update minimum api version to 1.1 * update changelog * per legendecas, add todo for ResourceAttributes --------- Co-authored-by: Marc Pichler --- CHANGELOG_NEXT.md | 1 + package-lock.json | 4 ++-- packages/opentelemetry-resources/package.json | 2 +- packages/opentelemetry-resources/src/Resource.ts | 2 +- packages/opentelemetry-resources/src/types.ts | 7 +++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG_NEXT.md b/CHANGELOG_NEXT.md index 5d735167aa..73772e677f 100644 --- a/CHANGELOG_NEXT.md +++ b/CHANGELOG_NEXT.md @@ -4,6 +4,7 @@ * chore(shim-opentracing): replace deprecated SpanAttributes [#4430](https://github.com/open-telemetry/opentelemetry-js/pull/4430) @JamieDanielson * chore(otel-core): replace deprecated SpanAttributes [#4408](https://github.com/open-telemetry/opentelemetry-js/pull/4408) @JamieDanielson +* chore(otel-resources): replace deprecated SpanAttributes [#4428](https://github.com/open-telemetry/opentelemetry-js/pull/4428) @JamieDanielson ### :rocket: (Enhancement) diff --git a/package-lock.json b/package-lock.json index 9c685a2e95..7800ff33d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31307,7 +31307,7 @@ "@opentelemetry/semantic-conventions": "1.18.1" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.8.0", + "@opentelemetry/api": ">=1.1.0 <1.8.0", "@opentelemetry/resources_1.9.0": "npm:@opentelemetry/resources@1.9.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", @@ -37075,7 +37075,7 @@ "@opentelemetry/resources": { "version": "file:packages/opentelemetry-resources", "requires": { - "@opentelemetry/api": ">=1.0.0 <1.8.0", + "@opentelemetry/api": ">=1.1.0 <1.8.0", "@opentelemetry/core": "1.18.1", "@opentelemetry/resources_1.9.0": "npm:@opentelemetry/resources@1.9.0", "@opentelemetry/semantic-conventions": "1.18.1", diff --git a/packages/opentelemetry-resources/package.json b/packages/opentelemetry-resources/package.json index 3c78e12eeb..fc502ef642 100644 --- a/packages/opentelemetry-resources/package.json +++ b/packages/opentelemetry-resources/package.json @@ -61,7 +61,7 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.8.0", + "@opentelemetry/api": ">=1.1.0 <1.8.0", "@opentelemetry/resources_1.9.0": "npm:@opentelemetry/resources@1.9.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", diff --git a/packages/opentelemetry-resources/src/Resource.ts b/packages/opentelemetry-resources/src/Resource.ts index dfddda8ae1..40e99ceae4 100644 --- a/packages/opentelemetry-resources/src/Resource.ts +++ b/packages/opentelemetry-resources/src/Resource.ts @@ -119,7 +119,7 @@ export class Resource implements IResource { merge(other: IResource | null): IResource { if (!other) return this; - // SpanAttributes from other resource overwrite attributes from this resource. + // Attributes from other resource overwrite attributes from this resource. const mergedSyncAttributes = { ...this._syncAttributes, //Support for old resource implementation where _syncAttributes is not defined diff --git a/packages/opentelemetry-resources/src/types.ts b/packages/opentelemetry-resources/src/types.ts index d20c09faa2..d86fc9da6e 100644 --- a/packages/opentelemetry-resources/src/types.ts +++ b/packages/opentelemetry-resources/src/types.ts @@ -15,15 +15,14 @@ */ import { ResourceDetectionConfig } from './config'; -import { SpanAttributes } from '@opentelemetry/api'; +import { Attributes } from '@opentelemetry/api'; import { IResource } from './IResource'; /** * Interface for Resource attributes. - * General `Attributes` interface is added in api v1.1.0. - * To backward support older api (1.0.x), the deprecated `SpanAttributes` is used here. */ -export type ResourceAttributes = SpanAttributes; +// TODO: replace ResourceAttributes with Attributes +export type ResourceAttributes = Attributes; /** * @deprecated please use {@link DetectorSync}