diff --git a/packages/core/src/tracing/span.ts b/packages/core/src/tracing/span.ts index 27cd287a017e..be4e420fc8bc 100644 --- a/packages/core/src/tracing/span.ts +++ b/packages/core/src/tracing/span.ts @@ -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, }); } diff --git a/packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts b/packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts index 8dbcb590b331..d069fd299682 100644 --- a/packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts +++ b/packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts @@ -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', }, }), }), @@ -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', }, }), }), @@ -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', }, }), }), @@ -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', }, }), }), diff --git a/packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts b/packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts index f34beaa63926..b9241d5a2569 100644 --- a/packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts +++ b/packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts @@ -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', }, }), diff --git a/packages/node-experimental/test/integration/scope.test.ts b/packages/node-experimental/test/integration/scope.test.ts index 5beb1b7ec06f..78579701e47e 100644 --- a/packages/node-experimental/test/integration/scope.test.ts +++ b/packages/node-experimental/test/integration/scope.test.ts @@ -92,6 +92,7 @@ describe('Integration | Scope', () => { span_id: spanId, status: 'ok', trace_id: traceId, + origin: 'manual', }, }), spans: [], diff --git a/packages/node-experimental/test/integration/transactions.test.ts b/packages/node-experimental/test/integration/transactions.test.ts index 2f6cea23c0fd..45dafa88916c 100644 --- a/packages/node-experimental/test/integration/transactions.test.ts +++ b/packages/node-experimental/test/integration/transactions.test.ts @@ -37,10 +37,6 @@ describe('Integration | Transactions', () => { metadata: { requestPath: 'test-path' }, }, span => { - if (!span) { - return; - } - Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 }); span.setAttributes({ @@ -48,15 +44,11 @@ describe('Integration | Transactions', () => { }); 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({ @@ -97,6 +89,7 @@ describe('Integration | Transactions', () => { span_id: expect.any(String), status: 'ok', trace_id: expect.any(String), + origin: 'auto.test', }, }, environment: 'production', @@ -189,10 +182,6 @@ 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({ @@ -200,15 +189,11 @@ describe('Integration | Transactions', () => { }); 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({ @@ -218,10 +203,6 @@ 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({ @@ -229,15 +210,11 @@ describe('Integration | Transactions', () => { }); 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({ @@ -268,6 +245,7 @@ describe('Integration | Transactions', () => { span_id: expect.any(String), status: 'ok', trace_id: expect.any(String), + origin: 'auto.test', }, }), spans: [ @@ -309,6 +287,7 @@ describe('Integration | Transactions', () => { span_id: expect.any(String), status: 'ok', trace_id: expect.any(String), + origin: 'manual', }, }), spans: [ @@ -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' }, () => {}); }); }, ); @@ -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 @@ -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; }); diff --git a/packages/opentelemetry/test/custom/transaction.test.ts b/packages/opentelemetry/test/custom/transaction.test.ts index 65f5f79a87eb..1c4f9f3eea81 100644 --- a/packages/opentelemetry/test/custom/transaction.test.ts +++ b/packages/opentelemetry/test/custom/transaction.test.ts @@ -28,6 +28,7 @@ describe('NodeExperimentalTransaction', () => { trace: { span_id: expect.any(String), trace_id: expect.any(String), + origin: 'manual', }, }, spans: [], @@ -106,6 +107,7 @@ describe('NodeExperimentalTransaction', () => { trace: { span_id: expect.any(String), trace_id: expect.any(String), + origin: 'manual', }, }, spans: [], diff --git a/packages/opentelemetry/test/integration/scope.test.ts b/packages/opentelemetry/test/integration/scope.test.ts index c028e1893d7a..16ff5e85ae37 100644 --- a/packages/opentelemetry/test/integration/scope.test.ts +++ b/packages/opentelemetry/test/integration/scope.test.ts @@ -98,6 +98,7 @@ describe('Integration | Scope', () => { span_id: spanId, status: 'ok', trace_id: traceId, + origin: 'manual', }, }), diff --git a/packages/opentelemetry/test/integration/transactions.test.ts b/packages/opentelemetry/test/integration/transactions.test.ts index 2a4de232cc1b..5174b577611a 100644 --- a/packages/opentelemetry/test/integration/transactions.test.ts +++ b/packages/opentelemetry/test/integration/transactions.test.ts @@ -37,10 +37,6 @@ describe('Integration | Transactions', () => { metadata: { requestPath: 'test-path' }, }, span => { - if (!span) { - return; - } - addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 }); span.setAttributes({ @@ -48,15 +44,11 @@ describe('Integration | Transactions', () => { }); 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({ @@ -96,6 +88,7 @@ describe('Integration | Transactions', () => { span_id: expect.any(String), status: 'ok', trace_id: expect.any(String), + origin: 'auto.test', }, }, environment: 'production', @@ -186,10 +179,6 @@ 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({ @@ -197,15 +186,11 @@ describe('Integration | Transactions', () => { }); 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({ @@ -215,10 +200,6 @@ 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({ @@ -226,15 +207,11 @@ describe('Integration | Transactions', () => { }); 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({ @@ -265,6 +242,7 @@ describe('Integration | Transactions', () => { span_id: expect.any(String), status: 'ok', trace_id: expect.any(String), + origin: 'auto.test', }, }), spans: [ @@ -306,6 +284,7 @@ describe('Integration | Transactions', () => { span_id: expect.any(String), status: 'ok', trace_id: expect.any(String), + origin: 'manual', }, }), spans: [ @@ -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' }, () => {}); }); }, ); @@ -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 diff --git a/packages/tracing/test/span.test.ts b/packages/tracing/test/span.test.ts index ca16a1395e3e..ffa57d615d7b 100644 --- a/packages/tracing/test/span.test.ts +++ b/packages/tracing/test/span.test.ts @@ -327,6 +327,7 @@ describe('Span', () => { expect(context).toStrictEqual({ span_id: 'd', trace_id: 'c', + origin: 'manual', }); }); }); diff --git a/packages/tracing/test/transaction.test.ts b/packages/tracing/test/transaction.test.ts index fed6a63ea684..a8a8557150a1 100644 --- a/packages/tracing/test/transaction.test.ts +++ b/packages/tracing/test/transaction.test.ts @@ -153,6 +153,7 @@ describe('`Transaction` class', () => { trace: { span_id: transaction.spanId, trace_id: transaction.traceId, + origin: 'manual', }, }, }), @@ -179,6 +180,7 @@ describe('`Transaction` class', () => { trace: { span_id: transaction.spanId, trace_id: transaction.traceId, + origin: 'manual', }, }, }), diff --git a/packages/types/src/context.ts b/packages/types/src/context.ts index d52b674e2cbe..8dadb959a97d 100644 --- a/packages/types/src/context.ts +++ b/packages/types/src/context.ts @@ -1,4 +1,5 @@ import type { Primitive } from './misc'; +import type { SpanOrigin } from './span'; export type Context = Record; @@ -101,6 +102,7 @@ export interface TraceContext extends Record { status?: string; tags?: { [key: string]: Primitive }; trace_id: string; + origin?: SpanOrigin; } export interface CloudResourceContext extends Record {