Skip to content

Commit 5b9e477

Browse files
committed
feat(tracing): Add span origin to trace context
1 parent 9a94e23 commit 5b9e477

File tree

5 files changed

+16
-38
lines changed

5 files changed

+16
-38
lines changed

packages/core/src/tracing/span.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ export class Span implements SpanInterface {
332332
status: this.status,
333333
tags: Object.keys(this.tags).length > 0 ? this.tags : undefined,
334334
trace_id: this.traceId,
335+
origin: this.origin,
335336
});
336337
}
337338

packages/opentelemetry/test/custom/transaction.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('NodeExperimentalTransaction', () => {
2828
trace: {
2929
span_id: expect.any(String),
3030
trace_id: expect.any(String),
31+
origin: 'manual',
3132
},
3233
},
3334
spans: [],
@@ -106,6 +107,7 @@ describe('NodeExperimentalTransaction', () => {
106107
trace: {
107108
span_id: expect.any(String),
108109
trace_id: expect.any(String),
110+
origin: 'manual',
109111
},
110112
},
111113
spans: [],

packages/opentelemetry/test/integration/scope.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ describe('Integration | Scope', () => {
9898
span_id: spanId,
9999
status: 'ok',
100100
trace_id: traceId,
101+
origin: 'manual',
101102
},
102103
}),
103104

packages/opentelemetry/test/integration/transactions.test.ts

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,18 @@ describe('Integration | Transactions', () => {
3737
metadata: { requestPath: 'test-path' },
3838
},
3939
span => {
40-
if (!span) {
41-
return;
42-
}
43-
4440
addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
4541

4642
span.setAttributes({
4743
'test.outer': 'test value',
4844
});
4945

5046
const subSpan = startInactiveSpan({ name: 'inner span 1' });
51-
subSpan?.end();
47+
subSpan.end();
5248

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

5551
startSpan({ name: 'inner span 2' }, innerSpan => {
56-
if (!innerSpan) {
57-
return;
58-
}
59-
6052
addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });
6153

6254
innerSpan.setAttributes({
@@ -96,6 +88,7 @@ describe('Integration | Transactions', () => {
9688
span_id: expect.any(String),
9789
status: 'ok',
9890
trace_id: expect.any(String),
91+
origin: 'auto.test',
9992
},
10093
},
10194
environment: 'production',
@@ -186,26 +179,18 @@ describe('Integration | Transactions', () => {
186179
addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });
187180

188181
startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
189-
if (!span) {
190-
return;
191-
}
192-
193182
addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
194183

195184
span.setAttributes({
196185
'test.outer': 'test value',
197186
});
198187

199188
const subSpan = startInactiveSpan({ name: 'inner span 1' });
200-
subSpan?.end();
189+
subSpan.end();
201190

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

204193
startSpan({ name: 'inner span 2' }, innerSpan => {
205-
if (!innerSpan) {
206-
return;
207-
}
208-
209194
addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });
210195

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

217202
startSpan({ op: 'test op b', name: 'test name b' }, span => {
218-
if (!span) {
219-
return;
220-
}
221-
222203
addBreadcrumb({ message: 'test breadcrumb 2b', timestamp: 123456 });
223204

224205
span.setAttributes({
225206
'test.outer': 'test value b',
226207
});
227208

228209
const subSpan = startInactiveSpan({ name: 'inner span 1b' });
229-
subSpan?.end();
210+
subSpan.end();
230211

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

233214
startSpan({ name: 'inner span 2b' }, innerSpan => {
234-
if (!innerSpan) {
235-
return;
236-
}
237-
238215
addBreadcrumb({ message: 'test breadcrumb 3b', timestamp: 123456 });
239216

240217
innerSpan.setAttributes({
@@ -265,6 +242,7 @@ describe('Integration | Transactions', () => {
265242
span_id: expect.any(String),
266243
status: 'ok',
267244
trace_id: expect.any(String),
245+
origin: 'auto.test',
268246
},
269247
}),
270248
spans: [
@@ -306,6 +284,7 @@ describe('Integration | Transactions', () => {
306284
span_id: expect.any(String),
307285
status: 'ok',
308286
trace_id: expect.any(String),
287+
origin: 'manual',
309288
},
310289
}),
311290
spans: [
@@ -359,19 +338,11 @@ describe('Integration | Transactions', () => {
359338
context.with(
360339
trace.setSpanContext(setPropagationContextOnContext(context.active(), propagationContext), spanContext),
361340
() => {
362-
startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
363-
if (!span) {
364-
return;
365-
}
366-
341+
startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, () => {
367342
const subSpan = startInactiveSpan({ name: 'inner span 1' });
368-
subSpan?.end();
343+
subSpan.end();
369344

370-
startSpan({ name: 'inner span 2' }, innerSpan => {
371-
if (!innerSpan) {
372-
return;
373-
}
374-
});
345+
startSpan({ name: 'inner span 2' }, () => {});
375346
});
376347
},
377348
);
@@ -392,6 +363,7 @@ describe('Integration | Transactions', () => {
392363
parent_span_id: parentSpanId,
393364
status: 'ok',
394365
trace_id: traceId,
366+
origin: 'auto.test',
395367
},
396368
}),
397369
// spans are circular (they have a reference to the transaction), which leads to jest choking on this

packages/types/src/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Primitive } from './misc';
2+
import { SpanOrigin } from './span';
23

34
export type Context = Record<string, unknown>;
45

@@ -101,6 +102,7 @@ export interface TraceContext extends Record<string, unknown> {
101102
status?: string;
102103
tags?: { [key: string]: Primitive };
103104
trace_id: string;
105+
origin?: SpanOrigin;
104106
}
105107

106108
export interface CloudResourceContext extends Record<string, unknown> {

0 commit comments

Comments
 (0)