Skip to content

ref: Remove deprecated properties from startSpan options #11054

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test('Should send a transaction event for a generateMetadata() function invokati
const transactionPromise = waitForTransaction('nextjs-14', async transactionEvent => {
return (
transactionEvent?.transaction === 'Page.generateMetadata (/generation-functions)' &&
transactionEvent.contexts?.trace?.data?.['searchParams']?.['metadataTitle'] === testTitle
(transactionEvent.extra?.route_data as any)?.searchParams?.metadataTitle === testTitle
);
});

Expand All @@ -26,8 +26,8 @@ test('Should send a transaction and an error event for a faulty generateMetadata

const transactionPromise = waitForTransaction('nextjs-14', async transactionEvent => {
return (
transactionEvent?.transaction === 'Page.generateMetadata (/generation-functions)' &&
transactionEvent.contexts?.trace?.data?.['searchParams']?.['metadataTitle'] === testTitle
transactionEvent.transaction === 'Page.generateMetadata (/generation-functions)' &&
(transactionEvent.extra?.route_data as any)?.searchParams?.metadataTitle === testTitle
);
});

Expand All @@ -47,7 +47,7 @@ test('Should send a transaction event for a generateViewport() function invokati
const transactionPromise = waitForTransaction('nextjs-14', async transactionEvent => {
return (
transactionEvent?.transaction === 'Page.generateViewport (/generation-functions)' &&
transactionEvent.contexts?.trace?.data?.['searchParams']?.['viewportThemeColor'] === testTitle
(transactionEvent.extra?.route_data as any)?.searchParams?.viewportThemeColor === testTitle
);
});

Expand All @@ -64,7 +64,7 @@ test('Should send a transaction and an error event for a faulty generateViewport
const transactionPromise = waitForTransaction('nextjs-14', async transactionEvent => {
return (
transactionEvent?.transaction === 'Page.generateViewport (/generation-functions)' &&
transactionEvent.contexts?.trace?.data?.['searchParams']?.['viewportThemeColor'] === testTitle
(transactionEvent.extra?.route_data as any)?.searchParams?.viewportThemeColor === testTitle
);
});

Expand All @@ -86,7 +86,7 @@ test('Should send a transaction event with correct status for a generateMetadata
const transactionPromise = waitForTransaction('nextjs-14', async transactionEvent => {
return (
transactionEvent?.transaction === 'Page.generateMetadata (/generation-functions/with-redirect)' &&
transactionEvent.contexts?.trace?.data?.['searchParams']?.['metadataTitle'] === testTitle
(transactionEvent.extra?.route_data as any)?.searchParams?.metadataTitle === testTitle
);
});

Expand All @@ -103,7 +103,7 @@ test('Should send a transaction event with correct status for a generateMetadata
const transactionPromise = waitForTransaction('nextjs-14', async transactionEvent => {
return (
transactionEvent?.transaction === 'Page.generateMetadata (/generation-functions/with-notfound)' &&
transactionEvent.contexts?.trace?.data?.['searchParams']?.['metadataTitle'] === testTitle
(transactionEvent.extra?.route_data as any)?.searchParams?.metadataTitle === testTitle
);
});

Expand Down
3 changes: 0 additions & 3 deletions dev-packages/e2e-tests/tracing-shim-esm/index.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions dev-packages/e2e-tests/tracing-shim-esm/index.mjs

This file was deleted.

10 changes: 0 additions & 10 deletions dev-packages/e2e-tests/tracing-shim-esm/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions dev-packages/e2e-tests/tracing-shim/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions dev-packages/e2e-tests/tracing-shim/package.json

This file was deleted.

41 changes: 5 additions & 36 deletions packages/core/test/lib/tracing/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
getMainCarrier,
setAsyncContextStrategy,
setCurrentClient,
spanIsSampled,
spanToJSON,
withScope,
} from '../../../src';
Expand Down Expand Up @@ -101,33 +100,6 @@ describe('startSpan', () => {
expect(spanToJSON(_span!).status).toEqual(isError ? 'internal_error' : undefined);
});

it('allows traceparent information to be overriden', async () => {
let _span: Span | undefined = undefined;
client.on('spanEnd', span => {
_span = span;
});
try {
await startSpan(
{
name: 'GET users/[id]',
parentSampled: true,
traceId: '12345678901234567890123456789012',
parentSpanId: '1234567890123456',
},
() => {
return callback();
},
);
} catch (e) {
//
}
expect(_span).toBeDefined();

expect(spanIsSampled(_span!)).toEqual(true);
expect(spanToJSON(_span!).trace_id).toEqual('12345678901234567890123456789012');
expect(spanToJSON(_span!).parent_span_id).toEqual('1234567890123456');
});

it('allows for transaction to be mutated', async () => {
let _span: Span | undefined = undefined;
client.on('spanEnd', span => {
Expand All @@ -153,7 +125,7 @@ describe('startSpan', () => {
}
});
try {
await startSpan({ name: 'GET users/[id]', parentSampled: true }, () => {
await startSpan({ name: 'GET users/[id]' }, () => {
return startSpan({ name: 'SELECT * from users' }, () => {
return callback();
});
Expand All @@ -179,7 +151,7 @@ describe('startSpan', () => {
}
});
try {
await startSpan({ name: 'GET users/[id]', parentSampled: true }, () => {
await startSpan({ name: 'GET users/[id]' }, () => {
return startSpan({ name: 'SELECT * from users' }, childSpan => {
if (childSpan) {
childSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'db.query');
Expand Down Expand Up @@ -453,12 +425,9 @@ describe('startSpan', () => {
setCurrentClient(client);
client.init();

startSpan(
{ name: 'outer', attributes: { test1: 'aa', test2: 'aa' }, data: { test1: 'bb', test3: 'bb' } },
outerSpan => {
expect(outerSpan).toBeDefined();
},
);
startSpan({ name: 'outer', attributes: { test1: 'aa', test2: 'aa', test3: 'bb' } }, outerSpan => {
expect(outerSpan).toBeDefined();
});

expect(tracesSampler).toBeCalledTimes(1);
expect(tracesSampler).toHaveBeenLastCalledWith({
Expand Down
12 changes: 6 additions & 6 deletions packages/ember/addon/instance-initializers/sentry-performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void {
},
name: 'runloop',
op: `ui.ember.runloop.${queue}`,
startTimestamp: currentQueueStart,
startTime: currentQueueStart,
})?.end(now);
}
currentQueueStart = undefined;
Expand Down Expand Up @@ -295,7 +295,7 @@ function processComponentRenderAfter(
startInactiveSpan({
name: payload.containerKey || payload.object,
op,
startTimestamp: begin.now,
startTime: begin.now,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.ember',
},
Expand Down Expand Up @@ -374,17 +374,17 @@ function _instrumentInitialLoad(config: EmberSentryConfig): void {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const measure = measures[0]!;

const startTimestamp = (measure.startTime + browserPerformanceTimeOrigin) / 1000;
const endTimestamp = startTimestamp + measure.duration / 1000;
const startTime = (measure.startTime + browserPerformanceTimeOrigin) / 1000;
const endTime = startTime + measure.duration / 1000;

startInactiveSpan({
op: 'ui.ember.init',
name: 'init',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.ember',
},
startTimestamp,
})?.end(endTimestamp);
startTime,
})?.end(endTime);
performance.clearMarks(startName);
performance.clearMarks(endName);

Expand Down
7 changes: 4 additions & 3 deletions packages/nextjs/src/common/utils/edgeWrapperUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
addTracingExtensions,
captureException,
continueTrace,
getIsolationScope,
handleCallbackErrors,
setHttpStatus,
startSpan,
Expand Down Expand Up @@ -39,6 +40,9 @@ export function withEdgeWrapping<H extends EdgeRouteHandler>(
baggage,
},
() => {
getIsolationScope().setSDKProcessingMetadata({
request: req instanceof Request ? winterCGRequestToRequestData(req) : undefined,
});
return startSpan(
{
name: options.spanDescription,
Expand All @@ -47,9 +51,6 @@ export function withEdgeWrapping<H extends EdgeRouteHandler>(
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping',
},
metadata: {
request: req instanceof Request ? winterCGRequestToRequestData(req) : undefined,
},
},
async span => {
const handlerResult = await handleCallbackErrors(
Expand Down
3 changes: 0 additions & 3 deletions packages/nextjs/src/common/wrapApiHandlerWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.nextjs',
},
metadata: {
request: req,
},
},
async span => {
// eslint-disable-next-line @typescript-eslint/unbound-method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function wrapGenerationFunctionWithSentry<F extends (...args: any[]) => a
{
op: 'function.nextjs',
name: `${componentType}.${generationFunctionIdentifier} (${componentRoute})`,
data,
Copy link
Contributor

Choose a reason for hiding this comment

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

This looked sus but I saw that we also set it as extra on the scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

jup, that's why I removed it, this should remain the same on the event as far as I can tell! (it is also not flat so cannot be attributes directly, we'd need to flatten this but I don't think that's worth it here)

attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs',
Expand Down
7 changes: 4 additions & 3 deletions packages/nextjs/test/config/withSentry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ describe('withSentry', () => {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.nextjs',
},
metadata: {
request: expect.objectContaining({ url: 'http://dogs.are.great' }),
},
},
expect.any(Function),
);

expect(SentryCore.getIsolationScope().getScopeData().sdkProcessingMetadata).toEqual({
request: expect.objectContaining({ url: 'http://dogs.are.great' }),
});
});
});
});
7 changes: 4 additions & 3 deletions packages/nextjs/test/edge/edgeWrapperUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ describe('withEdgeWrapping', () => {
expect(startSpanSpy).toHaveBeenCalledTimes(1);
expect(startSpanSpy).toHaveBeenCalledWith(
expect.objectContaining({
metadata: {
request: { headers: {} },
},
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[coreSdk.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping',
Expand All @@ -94,6 +91,10 @@ describe('withEdgeWrapping', () => {
}),
expect.any(Function),
);

expect(coreSdk.getIsolationScope().getScopeData().sdkProcessingMetadata).toEqual({
request: { headers: {} },
});
});

it("should return a function that doesn't crash when req isn't passed", async () => {
Expand Down
10 changes: 6 additions & 4 deletions packages/nextjs/test/edge/withSentryAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ describe('wrapApiHandlerWithSentry', () => {
expect(startSpanSpy).toHaveBeenCalledTimes(1);
expect(startSpanSpy).toHaveBeenCalledWith(
expect.objectContaining({
metadata: {
request: { headers: {}, method: 'POST', url: 'https://sentry.io/' },
},
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping',
Expand All @@ -65,6 +62,10 @@ describe('wrapApiHandlerWithSentry', () => {
}),
expect.any(Function),
);

expect(coreSdk.getIsolationScope().getScopeData().sdkProcessingMetadata).toEqual({
request: { headers: {}, method: 'POST', url: 'https://sentry.io/' },
});
});

it('should return a function that calls trace without throwing when no request is passed', async () => {
Expand All @@ -77,7 +78,6 @@ describe('wrapApiHandlerWithSentry', () => {
expect(startSpanSpy).toHaveBeenCalledTimes(1);
expect(startSpanSpy).toHaveBeenCalledWith(
expect.objectContaining({
metadata: {},
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[coreSdk.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping',
Expand All @@ -87,5 +87,7 @@ describe('wrapApiHandlerWithSentry', () => {
}),
expect.any(Function),
);

expect(coreSdk.getIsolationScope().getScopeData().sdkProcessingMetadata).toEqual({});
});
});
7 changes: 0 additions & 7 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ export function tracingHandler(): (
[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
// `event.sdkProcessingMetadata` the same way the metadata here will) by `sentryRequestMiddleware`, but on the
// off chance someone is using `sentryTracingMiddleware` without `sentryRequestMiddleware`, it doesn't hurt to
// be sure
request: req,
},
}) as Transaction;
});

Expand Down
19 changes: 0 additions & 19 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as http from 'http';
import * as sentryCore from '@sentry/core';
import {
Hub,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
Transaction,
getClient,
Expand Down Expand Up @@ -469,24 +468,6 @@ describe('tracingHandler', () => {
done();
});
});

it('stores request in transaction metadata', () => {
const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 });
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(new NodeClient(options));

jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
// eslint-disable-next-line deprecation/deprecation
jest.spyOn(sentryCore, 'getCurrentScope').mockImplementation(() => hub.getScope());

sentryTracingMiddleware(req, res, next);

// eslint-disable-next-line deprecation/deprecation
const transaction = getCurrentScope().getTransaction();

// eslint-disable-next-line deprecation/deprecation
expect(transaction?.metadata.request).toEqual(req);
});
});

describe('errorHandler()', () => {
Expand Down
8 changes: 1 addition & 7 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_SOURCE,
getClient,
getCurrentScope,
getRootSpan,
Expand Down Expand Up @@ -141,16 +140,11 @@ function getTracer(): Tracer {
}

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

if (op) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
}

if (source) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
}
}

function getSpanContext(options: OpenTelemetrySpanContext): SpanOptions {
Expand Down
Loading