diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ffa659cf46..66f17a5c5e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2 ### :bug: Bug Fixes * fix(opentelemetry-instrumentation): improve `_warnOnPreloadedModules` function not to show warning logs when the module is not marked as loaded [#6095](https://github.com/open-telemetry/opentelemetry-js/pull/6095) @rlj1202 +* fix(sdk-trace-base): derive internal `SpanOptions` from API type to prevent drift [#6478](https://github.com/open-telemetry/opentelemetry-js/pull/6478) @overbalance ### :books: Documentation diff --git a/api/CHANGELOG.md b/api/CHANGELOG.md index f8a42fd8368..1b5290f0100 100644 --- a/api/CHANGELOG.md +++ b/api/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. * fix(api): prioritize `esnext` export condition as it is more specific [#5458](https://github.com/open-telemetry/opentelemetry-js/pull/5458) * fix(api): update diag `consoleLogger` to use original console methods to prevent infinite loop when a console instrumentation is present [#6395](https://github.com/open-telemetry/opentelemetry-js/pull/6395) +* fix(api): use `Attributes` instead of deprecated `SpanAttributes` in `SpanOptions` [#6478](https://github.com/open-telemetry/opentelemetry-js/pull/6478) @overbalance ### :books: (Refine Doc) diff --git a/api/src/trace/SpanOptions.ts b/api/src/trace/SpanOptions.ts index 5247cea35f2..802654da54b 100644 --- a/api/src/trace/SpanOptions.ts +++ b/api/src/trace/SpanOptions.ts @@ -3,8 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import type { Attributes } from '../common/Attributes'; import type { TimeInput } from '../common/Time'; -import type { SpanAttributes } from './attributes'; import type { Link } from './link'; import type { SpanKind } from './span_kind'; @@ -21,7 +21,7 @@ export interface SpanOptions { kind?: SpanKind; /** A span's attributes */ - attributes?: SpanAttributes; + attributes?: Attributes; /** {@link Link}s span to other spans */ links?: Link[]; diff --git a/packages/opentelemetry-sdk-trace-base/src/Span.ts b/packages/opentelemetry-sdk-trace-base/src/Span.ts index 391418ee16c..a1b900a245e 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Span.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Span.ts @@ -9,6 +9,7 @@ import type { HrTime, Link, Span as APISpan, + SpanOptions as APISpanOptions, Attributes, AttributeValue, SpanContext, @@ -47,21 +48,22 @@ import type { SpanLimits } from './types'; */ export type Span = APISpan & ReadableSpan; -interface SpanOptions { +// `root` is omitted because it is consumed by Tracer.startSpan() to strip +// parent context but it has no meaning when constructing a Span directly. +type SpanOptions = Omit & { resource: Resource; scope: InstrumentationScope; context: Context; spanContext: SpanContext; name: string; + // Required here to override optional `kind` from the API's SpanOptions + // SpanImpl assigns it unconditionally and ReadableSpan expects it to be set. kind: SpanKind; parentSpanContext?: SpanContext; - links?: Link[]; - startTime?: TimeInput; - attributes?: Attributes; spanLimits: SpanLimits; spanProcessor: SpanProcessor; recordEndMetrics?: () => void; -} +}; /** * This class represents a span.