Skip to content

feat(tracing): Add span origin to trace context #9472

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

Merged
merged 2 commits into from
Nov 8, 2023
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 packages/core/src/tracing/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ export class Span implements SpanInterface {
status: this.status,
tags: Object.keys(this.tags).length > 0 ? this.tags : undefined,
trace_id: this.traceId,
origin: this.origin,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
'http.status_code': 200,
},
trace_id: traceId,
origin: 'auto.http.otel.http',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose to add an .http at the end? The last part is supposed to be the integration part, see https://develop.sentry.dev/sdk/performance/trace-origin/. Do you have multiple otel integration parts, so for example, 'auto.http.otel.https', 'auto.http.otel.http? I don't see any in this PR. It could be that 'auto.http.otel is enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I wasn't too sure about this TBH 😅 the idea being that this is added by the http integration vs. for example the fetch integration - that uses auto.http.otel.node_fetch, as an example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's totally fine to do this. Just wanted to ensure you are aware. Thanks for the clarification 👍

},
}),
}),
Expand All @@ -93,6 +94,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
'http.status_code': 200,
},
trace_id: traceId,
origin: 'auto.http.otel.http',
},
}),
}),
Expand Down Expand Up @@ -162,6 +164,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
'http.status_code': 200,
},
trace_id: traceId,
origin: 'auto.http.otel.http',
},
}),
}),
Expand All @@ -184,6 +187,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
'http.status_code': 200,
},
trace_id: traceId,
origin: 'auto.http.otel.http',
},
}),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
'http.status_code': 200,
},
trace_id: expect.any(String),
origin: 'auto.http.otel.http',
},
}),

Expand Down
1 change: 1 addition & 0 deletions packages/node-experimental/test/integration/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ describe('Integration | Scope', () => {
span_id: spanId,
status: 'ok',
trace_id: traceId,
origin: 'manual',
},
}),
spans: [],
Expand Down
60 changes: 12 additions & 48 deletions packages/node-experimental/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,18 @@ describe('Integration | Transactions', () => {
metadata: { requestPath: 'test-path' },
},
span => {
if (!span) {
return;
}

Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });

span.setAttributes({
'test.outer': 'test value',
});

const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
subSpan?.end();
subSpan.end();

Sentry.setTag('test.tag', 'test value');

Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
if (!innerSpan) {
return;
}

Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });

innerSpan.setAttributes({
Expand Down Expand Up @@ -97,6 +89,7 @@ describe('Integration | Transactions', () => {
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'auto.test',
},
},
environment: 'production',
Expand Down Expand Up @@ -189,26 +182,18 @@ describe('Integration | Transactions', () => {
Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });

Sentry.startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
if (!span) {
return;
}

Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });

span.setAttributes({
'test.outer': 'test value',
});

const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
subSpan?.end();
subSpan.end();

Sentry.setTag('test.tag', 'test value');

Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
if (!innerSpan) {
return;
}

Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });

innerSpan.setAttributes({
Expand All @@ -218,26 +203,18 @@ describe('Integration | Transactions', () => {
});

Sentry.startSpan({ op: 'test op b', name: 'test name b' }, span => {
if (!span) {
return;
}

Sentry.addBreadcrumb({ message: 'test breadcrumb 2b', timestamp: 123456 });

span.setAttributes({
'test.outer': 'test value b',
});

const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1b' });
subSpan?.end();
subSpan.end();

Sentry.setTag('test.tag', 'test value b');

Sentry.startSpan({ name: 'inner span 2b' }, innerSpan => {
if (!innerSpan) {
return;
}

Sentry.addBreadcrumb({ message: 'test breadcrumb 3b', timestamp: 123456 });

innerSpan.setAttributes({
Expand Down Expand Up @@ -268,6 +245,7 @@ describe('Integration | Transactions', () => {
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'auto.test',
},
}),
spans: [
Expand Down Expand Up @@ -309,6 +287,7 @@ describe('Integration | Transactions', () => {
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'manual',
},
}),
spans: [
Expand Down Expand Up @@ -362,19 +341,11 @@ describe('Integration | Transactions', () => {
context.with(
trace.setSpanContext(setPropagationContextOnContext(context.active(), propagationContext), spanContext),
() => {
Sentry.startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
if (!span) {
return;
}

Sentry.startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, () => {
const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
subSpan?.end();
subSpan.end();

Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
if (!innerSpan) {
return;
}
});
Sentry.startSpan({ name: 'inner span 2' }, () => {});
});
},
);
Expand All @@ -395,6 +366,7 @@ describe('Integration | Transactions', () => {
parent_span_id: parentSpanId,
status: 'ok',
trace_id: traceId,
origin: 'auto.test',
},
}),
// spans are circular (they have a reference to the transaction), which leads to jest choking on this
Expand Down Expand Up @@ -481,20 +453,12 @@ describe('Integration | Transactions', () => {
let innerSpan1Id: string | undefined;
let innerSpan2Id: string | undefined;

void Sentry.startSpan({ name: 'test name' }, async span => {
if (!span) {
return;
}

void Sentry.startSpan({ name: 'test name' }, async () => {
const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
innerSpan1Id = subSpan?.spanContext().spanId;
subSpan?.end();
subSpan.end();

Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
if (!innerSpan) {
return;
}

innerSpan2Id = innerSpan.spanContext().spanId;
});

Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry/test/custom/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('NodeExperimentalTransaction', () => {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
origin: 'manual',
},
},
spans: [],
Expand Down Expand Up @@ -106,6 +107,7 @@ describe('NodeExperimentalTransaction', () => {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
origin: 'manual',
},
},
spans: [],
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry/test/integration/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('Integration | Scope', () => {
span_id: spanId,
status: 'ok',
trace_id: traceId,
origin: 'manual',
},
}),

Expand Down
48 changes: 10 additions & 38 deletions packages/opentelemetry/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,18 @@ describe('Integration | Transactions', () => {
metadata: { requestPath: 'test-path' },
},
span => {
if (!span) {
return;
}

addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });

span.setAttributes({
'test.outer': 'test value',
});

const subSpan = startInactiveSpan({ name: 'inner span 1' });
subSpan?.end();
subSpan.end();

setTag('test.tag', 'test value');

startSpan({ name: 'inner span 2' }, innerSpan => {
if (!innerSpan) {
return;
}

addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });

innerSpan.setAttributes({
Expand Down Expand Up @@ -96,6 +88,7 @@ describe('Integration | Transactions', () => {
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'auto.test',
},
},
environment: 'production',
Expand Down Expand Up @@ -186,26 +179,18 @@ describe('Integration | Transactions', () => {
addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });

startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
if (!span) {
return;
}

addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });

span.setAttributes({
'test.outer': 'test value',
});

const subSpan = startInactiveSpan({ name: 'inner span 1' });
subSpan?.end();
subSpan.end();

setTag('test.tag', 'test value');

startSpan({ name: 'inner span 2' }, innerSpan => {
if (!innerSpan) {
return;
}

addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });

innerSpan.setAttributes({
Expand All @@ -215,26 +200,18 @@ describe('Integration | Transactions', () => {
});

startSpan({ op: 'test op b', name: 'test name b' }, span => {
if (!span) {
return;
}

addBreadcrumb({ message: 'test breadcrumb 2b', timestamp: 123456 });

span.setAttributes({
'test.outer': 'test value b',
});

const subSpan = startInactiveSpan({ name: 'inner span 1b' });
subSpan?.end();
subSpan.end();

setTag('test.tag', 'test value b');

startSpan({ name: 'inner span 2b' }, innerSpan => {
if (!innerSpan) {
return;
}

addBreadcrumb({ message: 'test breadcrumb 3b', timestamp: 123456 });

innerSpan.setAttributes({
Expand Down Expand Up @@ -265,6 +242,7 @@ describe('Integration | Transactions', () => {
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'auto.test',
},
}),
spans: [
Expand Down Expand Up @@ -306,6 +284,7 @@ describe('Integration | Transactions', () => {
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'manual',
},
}),
spans: [
Expand Down Expand Up @@ -359,19 +338,11 @@ describe('Integration | Transactions', () => {
context.with(
trace.setSpanContext(setPropagationContextOnContext(context.active(), propagationContext), spanContext),
() => {
startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
if (!span) {
return;
}

startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, () => {
const subSpan = startInactiveSpan({ name: 'inner span 1' });
subSpan?.end();
subSpan.end();

startSpan({ name: 'inner span 2' }, innerSpan => {
if (!innerSpan) {
return;
}
});
startSpan({ name: 'inner span 2' }, () => {});
});
},
);
Expand All @@ -392,6 +363,7 @@ describe('Integration | Transactions', () => {
parent_span_id: parentSpanId,
status: 'ok',
trace_id: traceId,
origin: 'auto.test',
},
}),
// spans are circular (they have a reference to the transaction), which leads to jest choking on this
Expand Down
1 change: 1 addition & 0 deletions packages/tracing/test/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ describe('Span', () => {
expect(context).toStrictEqual({
span_id: 'd',
trace_id: 'c',
origin: 'manual',
});
});
});
Expand Down
Loading