Skip to content

Commit 0a5ed80

Browse files
committed
ref: Remove deprecated properties from startSpan options
So the public API for this is now fully aligned!
1 parent 390fd0a commit 0a5ed80

File tree

16 files changed

+120
-208
lines changed

16 files changed

+120
-208
lines changed

packages/core/test/lib/tracing/trace.test.ts

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
getMainCarrier,
1010
setAsyncContextStrategy,
1111
setCurrentClient,
12-
spanIsSampled,
1312
spanToJSON,
1413
withScope,
1514
} from '../../../src';
@@ -100,33 +99,6 @@ describe('startSpan', () => {
10099
expect(spanToJSON(_span!).status).toEqual(isError ? 'internal_error' : undefined);
101100
});
102101

103-
it('allows traceparent information to be overriden', async () => {
104-
let _span: Span | undefined = undefined;
105-
client.on('spanEnd', span => {
106-
_span = span;
107-
});
108-
try {
109-
await startSpan(
110-
{
111-
name: 'GET users/[id]',
112-
parentSampled: true,
113-
traceId: '12345678901234567890123456789012',
114-
parentSpanId: '1234567890123456',
115-
},
116-
() => {
117-
return callback();
118-
},
119-
);
120-
} catch (e) {
121-
//
122-
}
123-
expect(_span).toBeDefined();
124-
125-
expect(spanIsSampled(_span!)).toEqual(true);
126-
expect(spanToJSON(_span!).trace_id).toEqual('12345678901234567890123456789012');
127-
expect(spanToJSON(_span!).parent_span_id).toEqual('1234567890123456');
128-
});
129-
130102
it('allows for transaction to be mutated', async () => {
131103
let _span: Span | undefined = undefined;
132104
client.on('spanEnd', span => {
@@ -152,7 +124,7 @@ describe('startSpan', () => {
152124
}
153125
});
154126
try {
155-
await startSpan({ name: 'GET users/[id]', parentSampled: true }, () => {
127+
await startSpan({ name: 'GET users/[id]' }, () => {
156128
return startSpan({ name: 'SELECT * from users' }, () => {
157129
return callback();
158130
});
@@ -178,7 +150,7 @@ describe('startSpan', () => {
178150
}
179151
});
180152
try {
181-
await startSpan({ name: 'GET users/[id]', parentSampled: true }, () => {
153+
await startSpan({ name: 'GET users/[id]' }, () => {
182154
return startSpan({ name: 'SELECT * from users' }, childSpan => {
183155
if (childSpan) {
184156
childSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'db.query');
@@ -451,12 +423,9 @@ describe('startSpan', () => {
451423
setCurrentClient(client);
452424
client.init();
453425

454-
startSpan(
455-
{ name: 'outer', attributes: { test1: 'aa', test2: 'aa' }, data: { test1: 'bb', test3: 'bb' } },
456-
outerSpan => {
457-
expect(outerSpan).toBeDefined();
458-
},
459-
);
426+
startSpan({ name: 'outer', attributes: { test1: 'aa', test2: 'aa', test3: 'bb' } }, outerSpan => {
427+
expect(outerSpan).toBeDefined();
428+
});
460429

461430
expect(tracesSampler).toBeCalledTimes(1);
462431
expect(tracesSampler).toHaveBeenLastCalledWith({

packages/nextjs/src/common/utils/edgeWrapperUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
addTracingExtensions,
66
captureException,
77
continueTrace,
8+
getIsolationScope,
89
handleCallbackErrors,
910
setHttpStatus,
1011
startSpan,
@@ -39,6 +40,9 @@ export function withEdgeWrapping<H extends EdgeRouteHandler>(
3940
baggage,
4041
},
4142
() => {
43+
getIsolationScope().setSDKProcessingMetadata({
44+
request: req instanceof Request ? winterCGRequestToRequestData(req) : undefined,
45+
});
4246
return startSpan(
4347
{
4448
name: options.spanDescription,
@@ -47,9 +51,6 @@ export function withEdgeWrapping<H extends EdgeRouteHandler>(
4751
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
4852
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping',
4953
},
50-
metadata: {
51-
request: req instanceof Request ? winterCGRequestToRequestData(req) : undefined,
52-
},
5354
},
5455
async span => {
5556
const handlerResult = await handleCallbackErrors(

packages/nextjs/src/common/wrapApiHandlerWithSentry.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
9191
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
9292
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.nextjs',
9393
},
94-
metadata: {
95-
request: req,
96-
},
9794
},
9895
async span => {
9996
// eslint-disable-next-line @typescript-eslint/unbound-method

packages/nextjs/src/common/wrapGenerationFunctionWithSentry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export function wrapGenerationFunctionWithSentry<F extends (...args: any[]) => a
6868
{
6969
op: 'function.nextjs',
7070
name: `${componentType}.${generationFunctionIdentifier} (${componentRoute})`,
71-
data,
7271
attributes: {
7372
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
7473
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs',

packages/nextjs/test/config/withSentry.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ describe('withSentry', () => {
4747
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
4848
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.nextjs',
4949
},
50-
metadata: {
51-
request: expect.objectContaining({ url: 'http://dogs.are.great' }),
52-
},
5350
},
5451
expect.any(Function),
5552
);
53+
54+
expect(SentryCore.getIsolationScope().getScopeData().sdkProcessingMetadata).toEqual({
55+
request: expect.objectContaining({ url: 'http://dogs.are.great' }),
56+
});
5657
});
5758
});
5859
});

packages/nextjs/test/edge/edgeWrapperUtils.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ describe('withEdgeWrapping', () => {
8282
expect(startSpanSpy).toHaveBeenCalledTimes(1);
8383
expect(startSpanSpy).toHaveBeenCalledWith(
8484
expect.objectContaining({
85-
metadata: {
86-
request: { headers: {} },
87-
},
8885
attributes: {
8986
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
9087
[coreSdk.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping',
@@ -94,6 +91,10 @@ describe('withEdgeWrapping', () => {
9491
}),
9592
expect.any(Function),
9693
);
94+
95+
expect(coreSdk.getIsolationScope().getScopeData().sdkProcessingMetadata).toEqual({
96+
request: { headers: {} },
97+
});
9798
});
9899

99100
it("should return a function that doesn't crash when req isn't passed", async () => {

packages/nextjs/test/edge/withSentryAPI.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ describe('wrapApiHandlerWithSentry', () => {
5353
expect(startSpanSpy).toHaveBeenCalledTimes(1);
5454
expect(startSpanSpy).toHaveBeenCalledWith(
5555
expect.objectContaining({
56-
metadata: {
57-
request: { headers: {}, method: 'POST', url: 'https://sentry.io/' },
58-
},
5956
attributes: {
6057
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
6158
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping',
@@ -65,6 +62,10 @@ describe('wrapApiHandlerWithSentry', () => {
6562
}),
6663
expect.any(Function),
6764
);
65+
66+
expect(coreSdk.getIsolationScope().getScopeData().sdkProcessingMetadata).toEqual({
67+
request: { headers: {}, method: 'POST', url: 'https://sentry.io/' },
68+
});
6869
});
6970

7071
it('should return a function that calls trace without throwing when no request is passed', async () => {
@@ -77,7 +78,6 @@ describe('wrapApiHandlerWithSentry', () => {
7778
expect(startSpanSpy).toHaveBeenCalledTimes(1);
7879
expect(startSpanSpy).toHaveBeenCalledWith(
7980
expect.objectContaining({
80-
metadata: {},
8181
attributes: {
8282
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
8383
[coreSdk.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping',
@@ -87,5 +87,7 @@ describe('wrapApiHandlerWithSentry', () => {
8787
}),
8888
expect.any(Function),
8989
);
90+
91+
expect(coreSdk.getIsolationScope().getScopeData().sdkProcessingMetadata).toEqual({});
9092
});
9193
});

packages/node-experimental/test/integration/transactions.test.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,26 +179,36 @@ describe('Integration | Transactions', () => {
179179
Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });
180180

181181
Sentry.withIsolationScope(() => {
182-
Sentry.startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => {
183-
Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
182+
Sentry.startSpan(
183+
{
184+
op: 'test op',
185+
name: 'test name',
186+
origin: 'auto.test',
187+
attributes: {
188+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
189+
},
190+
},
191+
span => {
192+
Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
184193

185-
span.setAttributes({
186-
'test.outer': 'test value',
187-
});
194+
span.setAttributes({
195+
'test.outer': 'test value',
196+
});
188197

189-
const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
190-
subSpan.end();
198+
const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' });
199+
subSpan.end();
191200

192-
Sentry.setTag('test.tag', 'test value');
201+
Sentry.setTag('test.tag', 'test value');
193202

194-
Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
195-
Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });
203+
Sentry.startSpan({ name: 'inner span 2' }, innerSpan => {
204+
Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 });
196205

197-
innerSpan.setAttributes({
198-
'test.inner': 'test value',
206+
innerSpan.setAttributes({
207+
'test.inner': 'test value',
208+
});
199209
});
200-
});
201-
});
210+
},
211+
);
202212
});
203213

204214
Sentry.withIsolationScope(() => {

packages/node/src/handlers.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ export function tracingHandler(): (
7373
attributes: {
7474
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
7575
},
76-
metadata: {
77-
// The request should already have been stored in `scope.sdkProcessingMetadata` (which will become
78-
// `event.sdkProcessingMetadata` the same way the metadata here will) by `sentryRequestMiddleware`, but on the
79-
// off chance someone is using `sentryTracingMiddleware` without `sentryRequestMiddleware`, it doesn't hurt to
80-
// be sure
81-
request: req,
82-
},
8376
}) as Transaction;
8477
});
8578

packages/node/test/handlers.test.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as http from 'http';
22
import * as sentryCore from '@sentry/core';
33
import {
4-
Hub,
54
SEMANTIC_ATTRIBUTE_SENTRY_OP,
65
Transaction,
76
getClient,
@@ -469,24 +468,6 @@ describe('tracingHandler', () => {
469468
done();
470469
});
471470
});
472-
473-
it('stores request in transaction metadata', () => {
474-
const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 });
475-
// eslint-disable-next-line deprecation/deprecation
476-
const hub = new Hub(new NodeClient(options));
477-
478-
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
479-
// eslint-disable-next-line deprecation/deprecation
480-
jest.spyOn(sentryCore, 'getCurrentScope').mockImplementation(() => hub.getScope());
481-
482-
sentryTracingMiddleware(req, res, next);
483-
484-
// eslint-disable-next-line deprecation/deprecation
485-
const transaction = getCurrentScope().getTransaction();
486-
487-
// eslint-disable-next-line deprecation/deprecation
488-
expect(transaction?.metadata.request).toEqual(req);
489-
});
490471
});
491472

492473
describe('errorHandler()', () => {

packages/opentelemetry/src/trace.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
SDK_VERSION,
88
SEMANTIC_ATTRIBUTE_SENTRY_OP,
99
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
10-
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
1110
getClient,
1211
getCurrentScope,
1312
getRootSpan,
@@ -143,7 +142,7 @@ function getTracer(): Tracer {
143142

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

148147
if (origin) {
149148
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
@@ -152,10 +151,6 @@ function _applySentryAttributesToSpan(span: Span, options: OpenTelemetrySpanCont
152151
if (op) {
153152
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
154153
}
155-
156-
if (source) {
157-
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
158-
}
159154
}
160155

161156
function getSpanContext(options: OpenTelemetrySpanContext): SpanOptions {

0 commit comments

Comments
 (0)