Skip to content

ref: Remove deprecated origin field on span start options #11058

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
Mar 13, 2024
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
2 changes: 1 addition & 1 deletion packages/core/src/tracing/sentrySpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class SentrySpan implements Span {

this._attributes = {};
this.setAttributes({
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: spanContext.origin || 'manual',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: spanContext.op,
...spanContext.attributes,
});
Expand Down
20 changes: 11 additions & 9 deletions packages/core/test/lib/tracing/trace.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Event, Span, StartSpanOptions } from '@sentry/types';
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
Scope,
addTracingExtensions,
getCurrentScope,
Expand Down Expand Up @@ -197,20 +198,21 @@ describe('startSpan', () => {
expect(spanToJSON(spans[1]).op).toEqual('db.query');
});

it.each([
{ origin: 'auto.http.browser' },
{ attributes: { 'sentry.origin': 'auto.http.browser' } },
// attribute should take precedence over top level origin
{ origin: 'manual', attributes: { 'sentry.origin': 'auto.http.browser' } },
])('correctly sets the span origin', async () => {
it('correctly sets the span origin', async () => {
let _span: Span | undefined = undefined;
client.on('spanEnd', span => {
_span = span;
});
try {
await startSpan({ name: 'GET users/[id]', origin: 'auto.http.browser' }, () => {
return callback();
});
await startSpan(
{
name: 'GET users/[id]',
attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.browser' },
},
() => {
return callback();
},
);
} catch (e) {
//
}
Expand Down
4 changes: 3 additions & 1 deletion packages/core/test/lib/utils/spanUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ describe('spanToJSON', () => {
parentSpanId: '1234',
spanId: '5678',
traceId: 'abcd',
origin: 'auto',
startTimestamp: 123,
endTimestamp: 456,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto',
},
});
span.setStatus({ code: SPAN_STATUS_OK });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ export function _instrumentEmberRouter(
const routeInfo = routerService.recognize(url);
activeRootSpan = startBrowserTracingPageLoadSpan(client, {
name: `route:${routeInfo.name}`,
origin: 'auto.pageload.ember',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.ember',
url,
toRoute: routeInfo.name,
},
Expand All @@ -149,9 +149,9 @@ export function _instrumentEmberRouter(

activeRootSpan = startBrowserTracingNavigationSpan(client, {
name: `route:${toRoute}`,
origin: 'auto.navigation.ember',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.ember',
fromRoute,
toRoute,
},
Expand Down Expand Up @@ -295,8 +295,10 @@ function processComponentRenderAfter(
startInactiveSpan({
name: payload.containerKey || payload.object,
op,
origin: 'auto.ui.ember',
startTimestamp: begin.now,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.ember',
},
})?.end(now);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/node-experimental/src/utils/addOriginToSpan.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Span } from '@opentelemetry/api';
import { _INTERNAL } from '@sentry/opentelemetry';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
import type { SpanOrigin } from '@sentry/types';

/** Adds an origin to an OTEL Span. */
export function addOriginToSpan(span: Span, origin: SpanOrigin): void {
_INTERNAL.addOriginToSpan(span, origin);
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
}
48 changes: 30 additions & 18 deletions packages/node-experimental/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TraceFlags, context, trace } from '@opentelemetry/api';
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { SentrySpanProcessor } from '@sentry/opentelemetry';
import type { TransactionEvent } from '@sentry/types';
import { logger } from '@sentry/utils';
Expand Down Expand Up @@ -36,9 +36,9 @@ describe('Integration | Transactions', () => {
{
op: 'test op',
name: 'test name',
origin: 'auto.test',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test',
},
},
span => {
Expand Down Expand Up @@ -179,26 +179,36 @@ describe('Integration | Transactions', () => {
Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });

Sentry.withIsolationScope(() => {
Sentry.startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
Sentry.startSpan(
{
op: 'test op',
name: 'test name',
attributes: {
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test',
},
},
span => {
Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });

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

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

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

Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });
Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });

innerSpan.setAttributes({
'test.inner': 'test value',
innerSpan.setAttributes({
'test.inner': 'test value',
});
});
});
});
},
);
});

Sentry.withIsolationScope(() => {
Expand Down Expand Up @@ -493,8 +503,10 @@ describe('Integration | Transactions', () => {
{
op: 'test op',
name: 'test name',
origin: 'auto.test',
attributes: { [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task' },
attributes: {
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test',
},
},
() => {
const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
Expand Down
3 changes: 2 additions & 1 deletion packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as http from 'http';
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Transaction } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
Expand Down Expand Up @@ -68,10 +69,10 @@ export function tracingHandler(): (
return startInactiveSpan({
name,
op: 'http.server',
origin: 'auto.http.node.tracingHandler',
forceTransaction: true,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.node.tracingHandler',
},
metadata: {
// The request should already have been stored in `scope.sdkProcessingMetadata` (which will become
Expand Down
2 changes: 0 additions & 2 deletions packages/opentelemetry/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { addOriginToSpan } from './utils/addOriginToSpan';
import { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent';
import { getRequestSpanData } from './utils/getRequestSpanData';

Expand Down Expand Up @@ -46,7 +45,6 @@ export { getClient } from '@sentry/core';
* @hidden
*/
const _INTERNAL = {
addOriginToSpan,
maybeCaptureExceptionForTimedEvent,
getRequestSpanData,
} as const;
Expand Down
7 changes: 1 addition & 6 deletions packages/opentelemetry/src/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { TraceState, suppressTracing } from '@opentelemetry/core';
import {
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
getClient,
getCurrentScope,
Expand Down Expand Up @@ -143,11 +142,7 @@ function getTracer(): Tracer {

function _applySentryAttributesToSpan(span: Span, options: OpenTelemetrySpanContext): void {
// eslint-disable-next-line deprecation/deprecation
const { origin, op, source } = options;

if (origin) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
}
const { op, source } = options;

if (op) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
Expand Down
97 changes: 67 additions & 30 deletions packages/opentelemetry/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import type { SpanContext } from '@opentelemetry/api';
import { ROOT_CONTEXT } from '@opentelemetry/api';
import { TraceFlags, context, trace } from '@opentelemetry/api';
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, addBreadcrumb, getClient, setTag, withIsolationScope } from '@sentry/core';
import {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
addBreadcrumb,
getClient,
setTag,
withIsolationScope,
} from '@sentry/core';
import type { Event, TransactionEvent } from '@sentry/types';
import { logger } from '@sentry/utils';

Expand Down Expand Up @@ -42,9 +49,9 @@ describe('Integration | Transactions', () => {
{
op: 'test op',
name: 'test name',
origin: 'auto.test',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test',
},
},
span => {
Expand Down Expand Up @@ -185,26 +192,36 @@ describe('Integration | Transactions', () => {
addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });

withIsolationScope(() => {
startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
startSpan(
{
op: 'test op',
name: 'test name',
source: 'task',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test',
},
},
span => {
addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });

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

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

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

startSpan({ name: 'inner span 2' }, innerSpan => {
addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });
startSpan({ name: 'inner span 2' }, innerSpan => {
addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });

innerSpan.setAttributes({
'test.inner': 'test value',
innerSpan.setAttributes({
'test.inner': 'test value',
});
});
});
});
},
);
});

withIsolationScope(() => {
Expand Down Expand Up @@ -346,12 +363,22 @@ describe('Integration | Transactions', () => {

// We simulate the correct context we'd normally get from the SentryPropagator
context.with(trace.setSpanContext(ROOT_CONTEXT, spanContext), () => {
startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, () => {
const subSpan = startInactiveSpan({ name: 'inner span 1' });
subSpan.end();
startSpan(
{
op: 'test op',
name: 'test name',
source: 'task',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test',
},
},
() => {
const subSpan = startInactiveSpan({ name: 'inner span 1' });
subSpan.end();

startSpan({ name: 'inner span 2' }, () => {});
});
startSpan({ name: 'inner span 2' }, () => {});
},
);
});

await client.flush();
Expand Down Expand Up @@ -551,19 +578,29 @@ describe('Integration | Transactions', () => {

// We simulate the correct context we'd normally get from the SentryPropagator
context.with(trace.setSpanContext(ROOT_CONTEXT, spanContext), () => {
startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
expect(span.spanContext().traceState?.get(SENTRY_TRACE_STATE_DSC)).toEqual(dscString);
startSpan(
{
op: 'test op',
name: 'test name',
source: 'task',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test',
},
},
span => {
expect(span.spanContext().traceState?.get(SENTRY_TRACE_STATE_DSC)).toEqual(dscString);

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

expect(subSpan.spanContext().traceState?.get(SENTRY_TRACE_STATE_DSC)).toEqual(dscString);
expect(subSpan.spanContext().traceState?.get(SENTRY_TRACE_STATE_DSC)).toEqual(dscString);

subSpan.end();
subSpan.end();

startSpan({ name: 'inner span 2' }, subSpan => {
expect(subSpan.spanContext().traceState?.get(SENTRY_TRACE_STATE_DSC)).toEqual(dscString);
});
});
startSpan({ name: 'inner span 2' }, subSpan => {
expect(subSpan.spanContext().traceState?.get(SENTRY_TRACE_STATE_DSC)).toEqual(dscString);
});
},
);
});

await client.flush();
Expand Down
Loading