Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(sdk-trace-base)!: remove Span class from exports #5048

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* refactor(sdk-trace-base)!: replace `SpanAttributes` with `Attributes` [#5009](https://github.com/open-telemetry/opentelemetry-js/pull/5009) @david-luna
* refactor(resources)!: replace `ResourceAttributes` with `Attributes` [#5016](https://github.com/open-telemetry/opentelemetry-js/pull/5016) @david-luna
* feat(sdk-metrics)!: drop `View` and `Aggregation` in favor of `ViewOptions` and `AggregationOption` [#4931](https://github.com/open-telemetry/opentelemetry-js/pull/4931) @pichlermarc
* 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

### :rocket: (Enhancement)

Expand Down
10 changes: 8 additions & 2 deletions packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@ import {
SEMATTRS_EXCEPTION_STACKTRACE,
SEMATTRS_EXCEPTION_TYPE,
} from '@opentelemetry/semantic-conventions';
import { ExceptionEventName } from './enums';
import { ReadableSpan } from './export/ReadableSpan';
import { ExceptionEventName } from './enums';
import { SpanProcessor } from './SpanProcessor';
import { TimedEvent } from './TimedEvent';
import { Tracer } from './Tracer';
import { SpanLimits } from './types';

/**
* This type provides the properties of @link{ReadableSpan} at the same time
* of the Span API
*/
export type Span = APISpan & ReadableSpan;
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved

/**
* This class represents a span.
*/
export class Span implements APISpan, ReadableSpan {
export class SpanImpl implements Span {
// Below properties are included to implement ReadableSpan for export
// purposes but are not intended to be written-to directly.
private readonly _spanContext: SpanContext;
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-sdk-trace-base/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@opentelemetry/core';
import { IResource } from '@opentelemetry/resources';
import { BasicTracerProvider } from './BasicTracerProvider';
import { Span } from './Span';
import { SpanImpl } from './Span';
import { GeneralLimits, SpanLimits, TracerConfig } from './types';
import { mergeConfig } from './utility';
import { SpanProcessor } from './SpanProcessor';
Expand Down Expand Up @@ -138,7 +138,7 @@ export class Tracer implements api.Tracer {
Object.assign(attributes, samplingResult.attributes)
);

const span = new Span(
const span = new SpanImpl(
this,
context,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
AlwaysOnSampler,
AlwaysOffSampler,
} from '../../src';
import { SpanImpl } from '../../src/Span';

class DummyPropagator implements TextMapPropagator {
inject(context: Context, carrier: any, setter: TextMapSetter<any>): void {
Expand Down Expand Up @@ -582,7 +583,7 @@ describe('BasicTracerProvider', () => {
const tracer = new BasicTracerProvider().getTracer('default');
const span = tracer.startSpan('my-span');
assert.ok(span);
assert.ok(span instanceof Span);
assert.ok(span instanceof SpanImpl);
});

it('should propagate resources', () => {
Expand All @@ -597,7 +598,7 @@ describe('BasicTracerProvider', () => {
const tracer = new BasicTracerProvider().getTracer('default');
const span = tracer.startSpan('my-span', {});
assert.ok(span);
assert.ok(span instanceof Span);
assert.ok(span instanceof SpanImpl);
const context = span.spanContext();
assert.ok(context.traceId.match(/[a-f0-9]{32}/));
assert.ok(context.spanId.match(/[a-f0-9]{16}/));
Expand Down Expand Up @@ -638,7 +639,7 @@ describe('BasicTracerProvider', () => {
traceState: state,
})
);
assert.ok(span instanceof Span);
assert.ok(span instanceof SpanImpl);
const context = span.spanContext();
assert.strictEqual(context.traceId, 'd4cda95b652f4a1592b449d5929fda1b');
assert.strictEqual(context.traceFlags, TraceFlags.SAMPLED);
Expand Down Expand Up @@ -691,7 +692,7 @@ describe('BasicTracerProvider', () => {
'invalid-parent' as unknown as SpanContext
)
);
assert.ok(span instanceof Span);
assert.ok(span instanceof SpanImpl);
assert.deepStrictEqual((span as Span).parentSpanId, undefined);
});

Expand All @@ -706,7 +707,7 @@ describe('BasicTracerProvider', () => {
traceFlags: TraceFlags.SAMPLED,
})
);
assert.ok(span instanceof Span);
assert.ok(span instanceof SpanImpl);
const context = span.spanContext();
assert.ok(context.traceId.match(/[a-f0-9]{32}/));
assert.ok(context.spanId.match(/[a-f0-9]{16}/));
Expand All @@ -733,7 +734,7 @@ describe('BasicTracerProvider', () => {
sampler: new AlwaysOnSampler(),
}).getTracer('default');
const span = tracer.startSpan('my-span');
assert.ok(span instanceof Span);
assert.ok(span instanceof SpanImpl);
assert.strictEqual(span.spanContext().traceFlags, TraceFlags.SAMPLED);
assert.strictEqual(span.isRecording(), true);
});
Expand Down
Loading
Loading