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

chore(exporter-zipkin): remove usages of Span constructor #5030

108 changes: 48 additions & 60 deletions packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ const spanContext: api.SpanContext = {
describe('transform', () => {
describe('toZipkinSpan', () => {
it('should convert an OpenTelemetry span to a Zipkin span', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
const span = tracer.startSpan(
'my-span',
spanContext,
api.SpanKind.SERVER,
parentId
);
{ kind: api.SpanKind.SERVER },
api.ROOT_CONTEXT
) as unknown as Span;
(span as any)['_spanContext'] = spanContext;
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
(span as any)['parentSpanId'] = parentId;

span.setAttributes({
key1: 'value1',
key2: 'value2',
Expand Down Expand Up @@ -112,13 +112,11 @@ describe('transform', () => {
});
});
it("should skip parentSpanId if doesn't exist", () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
const span = tracer.startSpan(
'my-span',
spanContext,
api.SpanKind.SERVER
);
{ kind: api.SpanKind.SERVER },
api.ROOT_CONTEXT
) as unknown as Span;
span.end();

const zipkinSpan = toZipkinSpan(
Expand Down Expand Up @@ -163,13 +161,11 @@ describe('transform', () => {
it(`should map OpenTelemetry SpanKind ${
api.SpanKind[item.ot]
} to Zipkin ${item.zipkin}`, () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
const span = tracer.startSpan(
'my-span',
spanContext,
item.ot
);
{ kind: item.ot },
api.ROOT_CONTEXT
) as unknown as Span;
span.end();

const zipkinSpan = toZipkinSpan(
Expand Down Expand Up @@ -208,14 +204,12 @@ describe('transform', () => {

describe('_toZipkinTags', () => {
it('should convert OpenTelemetry attributes to Zipkin tags', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
const span = tracer.startSpan(
'my-span',
spanContext,
api.SpanKind.SERVER,
parentId
);
{ kind: api.SpanKind.SERVER },
api.ROOT_CONTEXT
) as unknown as Span;

span.setAttributes({
key1: 'value1',
key2: 'value2',
Expand All @@ -239,21 +233,18 @@ describe('transform', () => {
});
});
it('should map OpenTelemetry constructor attributes to a Zipkin tag', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
const span = tracer.startSpan(
'my-span',
spanContext,
api.SpanKind.SERVER,
parentId,
[],
undefined,
undefined,
{
key1: 'value1',
key2: 'value2',
}
);
kind: api.SpanKind.SERVER,
attributes: {
key1: 'value1',
key2: 'value2',
},
},
api.ROOT_CONTEXT
) as unknown as Span;

const tags: zipkinTypes.Tags = _toZipkinTags(
span,
defaultStatusCodeTagName,
Expand All @@ -273,14 +264,13 @@ describe('transform', () => {
});
});
it('should map OpenTelemetry SpanStatus.code to a Zipkin tag', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
const span = tracer.startSpan(
'my-span',
spanContext,
api.SpanKind.SERVER,
parentId
);
{
kind: api.SpanKind.SERVER,
},
api.ROOT_CONTEXT
) as unknown as Span;
const status: api.SpanStatus = {
code: api.SpanStatusCode.ERROR,
};
Expand Down Expand Up @@ -309,14 +299,13 @@ describe('transform', () => {
});
});
it('should map OpenTelemetry SpanStatus.message to a Zipkin tag', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
const span = tracer.startSpan(
'my-span',
spanContext,
api.SpanKind.SERVER,
parentId
);
{
kind: api.SpanKind.SERVER,
},
api.ROOT_CONTEXT
) as unknown as Span;
const status: api.SpanStatus = {
code: api.SpanStatusCode.ERROR,
message: 'my-message',
Expand Down Expand Up @@ -350,14 +339,13 @@ describe('transform', () => {

describe('_toZipkinAnnotations', () => {
it('should convert OpenTelemetry events to Zipkin annotations', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
const span = tracer.startSpan(
'my-span',
spanContext,
api.SpanKind.SERVER,
parentId
);
{
kind: api.SpanKind.SERVER,
},
api.ROOT_CONTEXT
) as unknown as Span;
span.addEvent('my-event1');
span.addEvent('my-event2', { key1: 'value1' });

Expand Down
Loading