Skip to content

Commit

Permalink
feat(sdk-trace-base): replace SpanAttributes with Attributes (#5009)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-luna authored Sep 25, 2024
1 parent 1804925 commit e15d5b3
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/opentelemetry-sdk-trace-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"webpack": "5.94.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.0.0 <1.10.0"
"@opentelemetry/api": ">=1.3.0 <1.10.0"
},
"dependencies": {
"@opentelemetry/core": "1.26.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/opentelemetry-sdk-trace-base/src/Sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
Context,
Link,
SpanAttributes,
Attributes,
SpanKind,
TraceState,
} from '@opentelemetry/api';
Expand Down Expand Up @@ -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<SpanAttributes>;
attributes?: Readonly<Attributes>;
/**
* A {@link TraceState} that will be associated with the {@link Span} through
* the new {@link SpanContext}. Samplers SHOULD return the TraceState from
Expand All @@ -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}.
Expand All @@ -93,7 +93,7 @@ export interface Sampler {
traceId: string,
spanName: string,
spanKind: SpanKind,
attributes: SpanAttributes,
attributes: Attributes,
links: Link[]
): SamplingResult;

Expand Down
18 changes: 9 additions & 9 deletions packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
HrTime,
Link,
Span as APISpan,
SpanAttributes,
SpanAttributeValue,
Attributes,
AttributeValue,
SpanContext,
SpanKind,
SpanStatus,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-sdk-trace-base/src/TimedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { HrTime, SpanAttributes } from '@opentelemetry/api';
import { HrTime, Attributes } from '@opentelemetry/api';

/**
* Represents a timed event.
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
SpanKind,
SpanStatus,
SpanAttributes,
Attributes,
HrTime,
Link,
SpanContext,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Context,
isSpanContextValid,
Link,
SpanAttributes,
Attributes,
SpanKind,
TraceFlags,
trace,
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
SpanKind,
TraceFlags,
HrTime,
SpanAttributes,
SpanAttributeValue,
Attributes,
AttributeValue,
} from '@opentelemetry/api';
import {
DEFAULT_ATTRIBUTE_COUNT_LIMIT,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import {
SpanAttributes,
Attributes,
Context,
context,
createContextKey,
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Tracer', () => {
_traceId: string,
_spanName: string,
_spanKind: SpanKind,
attributes: SpanAttributes,
attributes: Attributes,
links: Link[]
) {
// The attributes object should be valid.
Expand All @@ -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,
};
}
Expand Down Expand Up @@ -442,7 +442,7 @@ describe('Tracer', () => {
const attributes = {
...validAttributes,
...invalidAttributes,
} as unknown as SpanAttributes;
} as unknown as Attributes;
const links = [
{
context: {
Expand Down

0 comments on commit e15d5b3

Please sign in to comment.