Skip to content

Commit af66eb4

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into test/e2e-runner
2 parents 120cc5b + 5623fd8 commit af66eb4

File tree

51 files changed

+205
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+205
-116
lines changed

MIGRATION.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ npx @sentry/migr8@latest
88

99
This will let you select which updates to run, and automatically update your code. Make sure to still review all code changes!
1010

11+
## Deprecate `scope.getSpan()` and `scope.setSpan()`
12+
13+
Instead, you can get the currently active span via `Sentry.getActiveSpan()`.
14+
Setting a span on the scope happens automatically when you use the new performance APIs `startSpan()` and `startSpanManual()`.
15+
1116
## Deprecate `scope.setTransactionName()`
1217

1318
Instead, either set this as attributes or tags, or use an event processor to set `event.transaction`.

dev-packages/e2e-tests/test-applications/create-next-app/pages/api/success.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
55
export default function handler(req: NextApiRequest, res: NextApiResponse) {
66
// eslint-disable-next-line deprecation/deprecation
77
const transaction = Sentry.startTransaction({ name: 'test-transaction', op: 'e2e-test' });
8+
// eslint-disable-next-line deprecation/deprecation
89
Sentry.getCurrentHub().getScope().setSpan(transaction);
910

1011
// eslint-disable-next-line deprecation/deprecation

dev-packages/node-integration-tests/suites/tracing-new/apollo-graphql/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const server = new ApolloServer({
3030
// eslint-disable-next-line deprecation/deprecation
3131
const transaction = Sentry.startTransaction({ name: 'test_transaction', op: 'transaction' });
3232

33+
// eslint-disable-next-line deprecation/deprecation
3334
Sentry.getCurrentScope().setSpan(transaction);
3435

3536
// eslint-disable-next-line @typescript-eslint/no-floating-promises

dev-packages/node-integration-tests/suites/tracing-new/auto-instrument/mongodb/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async function run(): Promise<void> {
2222
op: 'transaction',
2323
});
2424

25+
// eslint-disable-next-line deprecation/deprecation
2526
Sentry.getCurrentScope().setSpan(transaction);
2627

2728
try {

dev-packages/node-integration-tests/suites/tracing-new/auto-instrument/mysql/withConnect/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const transaction = Sentry.startTransaction({
2525
name: 'Test Transaction',
2626
});
2727

28+
// eslint-disable-next-line deprecation/deprecation
2829
Sentry.getCurrentScope().setSpan(transaction);
2930

3031
connection.query('SELECT 1 + 1 AS solution', function () {

dev-packages/node-integration-tests/suites/tracing-new/auto-instrument/mysql/withoutCallback/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const transaction = Sentry.startTransaction({
2525
name: 'Test Transaction',
2626
});
2727

28+
// eslint-disable-next-line deprecation/deprecation
2829
Sentry.getCurrentScope().setSpan(transaction);
2930

3031
const query = connection.query('SELECT 1 + 1 AS solution');

dev-packages/node-integration-tests/suites/tracing-new/auto-instrument/mysql/withoutConnect/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const transaction = Sentry.startTransaction({
1919
name: 'Test Transaction',
2020
});
2121

22+
// eslint-disable-next-line deprecation/deprecation
2223
Sentry.getCurrentScope().setSpan(transaction);
2324

2425
connection.query('SELECT 1 + 1 AS solution', function () {

dev-packages/node-integration-tests/suites/tracing-new/auto-instrument/pg/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const transaction = Sentry.startTransaction({
1414
name: 'Test Transaction',
1515
});
1616

17+
// eslint-disable-next-line deprecation/deprecation
1718
Sentry.getCurrentScope().setSpan(transaction);
1819

1920
const client = new pg.Client();

dev-packages/node-integration-tests/suites/tracing-new/prisma-orm/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ async function run(): Promise<void> {
1919
op: 'transaction',
2020
});
2121

22+
// eslint-disable-next-line deprecation/deprecation
2223
Sentry.getCurrentScope().setSpan(transaction);
2324

2425
try {

dev-packages/node-integration-tests/suites/tracing-new/tracePropagationTargets/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Sentry.init({
1313
// eslint-disable-next-line deprecation/deprecation
1414
const transaction = Sentry.startTransaction({ name: 'test_transaction' });
1515

16+
// eslint-disable-next-line deprecation/deprecation
1617
Sentry.getCurrentScope().setSpan(transaction);
1718

1819
http.get('http://match-this-url.com/api/v0');

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const server = new ApolloServer({
3232
// eslint-disable-next-line deprecation/deprecation
3333
const transaction = Sentry.startTransaction({ name: 'test_transaction', op: 'transaction' });
3434

35+
// eslint-disable-next-line deprecation/deprecation
3536
Sentry.getCurrentScope().setSpan(transaction);
3637

3738
// eslint-disable-next-line @typescript-eslint/no-floating-promises

dev-packages/node-integration-tests/suites/tracing/auto-instrument/mongodb/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ async function run(): Promise<void> {
2323
op: 'transaction',
2424
});
2525

26+
// eslint-disable-next-line deprecation/deprecation
2627
Sentry.getCurrentScope().setSpan(transaction);
2728

2829
try {

dev-packages/node-integration-tests/suites/tracing/auto-instrument/mysql/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const transaction = Sentry.startTransaction({
2626
name: 'Test Transaction',
2727
});
2828

29+
// eslint-disable-next-line deprecation/deprecation
2930
Sentry.getCurrentScope().setSpan(transaction);
3031

3132
connection.query('SELECT 1 + 1 AS solution', function () {

dev-packages/node-integration-tests/suites/tracing/auto-instrument/pg/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const transaction = Sentry.startTransaction({
1515
name: 'Test Transaction',
1616
});
1717

18+
// eslint-disable-next-line deprecation/deprecation
1819
Sentry.getCurrentScope().setSpan(transaction);
1920

2021
const client = new pg.Client();

dev-packages/node-integration-tests/suites/tracing/prisma-orm/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function run(): Promise<void> {
2121
op: 'transaction',
2222
});
2323

24+
// eslint-disable-next-line deprecation/deprecation
2425
Sentry.getCurrentScope().setSpan(transaction);
2526

2627
try {

dev-packages/node-integration-tests/suites/tracing/tracePropagationTargets/scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Sentry.init({
1515
// eslint-disable-next-line deprecation/deprecation
1616
const transaction = Sentry.startTransaction({ name: 'test_transaction' });
1717

18+
// eslint-disable-next-line deprecation/deprecation
1819
Sentry.getCurrentScope().setSpan(transaction);
1920

2021
http.get('http://match-this-url.com/api/v0');

packages/astro/src/server/middleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
22
import {
33
captureException,
44
continueTrace,
5+
getActiveSpan,
56
getClient,
67
getCurrentScope,
78
runWithAsyncContext,
@@ -70,7 +71,7 @@ export const handleRequest: (options?: MiddlewareOptions) => MiddlewareResponseH
7071
// if there is an active span, we know that this handle call is nested and hence
7172
// we don't create a new domain for it. If we created one, nested server calls would
7273
// create new transactions instead of adding a child span to the currently active span.
73-
if (getCurrentScope().getSpan()) {
74+
if (getActiveSpan()) {
7475
return instrumentRequest(ctx, next, handlerOptions);
7576
}
7677
return runWithAsyncContext(() => {

packages/astro/test/server/middleware.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
22
import * as SentryNode from '@sentry/node';
3-
import type { Client } from '@sentry/types';
3+
import type { Client, Span } from '@sentry/types';
44
import { vi } from 'vitest';
55

66
import { handleRequest, interpolateRouteFromUrlAndParams } from '../../src/server/middleware';
@@ -15,7 +15,9 @@ vi.mock('../../src/server/meta', () => ({
1515
describe('sentryMiddleware', () => {
1616
const startSpanSpy = vi.spyOn(SentryNode, 'startSpan');
1717

18-
const getSpanMock = vi.fn(() => {});
18+
const getSpanMock = vi.fn(() => {
19+
return {} as Span | undefined;
20+
});
1921
const setUserMock = vi.fn();
2022

2123
beforeEach(() => {
@@ -26,6 +28,7 @@ describe('sentryMiddleware', () => {
2628
getSpan: getSpanMock,
2729
} as any;
2830
});
31+
vi.spyOn(SentryNode, 'getActiveSpan').mockImplementation(getSpanMock);
2932
vi.spyOn(SentryNode, 'getClient').mockImplementation(() => ({}) as Client);
3033
});
3134

packages/core/src/integration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ export function setupIntegrations(client: Client, integrations: Integration[]):
101101

102102
/** Setup a single integration. */
103103
export function setupIntegration(client: Client, integration: Integration, integrationIndex: IntegrationIndex): void {
104+
if (integrationIndex[integration.name]) {
105+
DEBUG_BUILD && logger.log(`Integration skipped because it was already installed: ${integration.name}`);
106+
return;
107+
}
104108
integrationIndex[integration.name] = integration;
105109

106110
// `setupOnce` is only called the first time

packages/core/src/scope.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ export class Scope implements ScopeInterface {
308308
}
309309

310310
/**
311-
* @inheritDoc
311+
* Sets the Span on the scope.
312+
* @param span Span
313+
* @deprecated Instead of setting a span on a scope, use `startSpan()`/`startSpanManual()` instead.
312314
*/
313315
public setSpan(span?: Span): this {
314316
this._span = span;
@@ -317,7 +319,8 @@ export class Scope implements ScopeInterface {
317319
}
318320

319321
/**
320-
* @inheritDoc
322+
* Returns the `Span` if there is one.
323+
* @deprecated Use `getActiveSpan()` instead.
321324
*/
322325
public getSpan(): Span | undefined {
323326
return this._span;
@@ -330,7 +333,7 @@ export class Scope implements ScopeInterface {
330333
public getTransaction(): Transaction | undefined {
331334
// Often, this span (if it exists at all) will be a transaction, but it's not guaranteed to be. Regardless, it will
332335
// have a pointer to the currently-active transaction.
333-
const span = this.getSpan();
336+
const span = this._span;
334337
return span && span.transaction;
335338
}
336339

packages/core/src/server-runtime-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export class ServerRuntimeClient<
255255
return [undefined, undefined];
256256
}
257257

258+
// eslint-disable-next-line deprecation/deprecation
258259
const span = scope.getSpan();
259260
if (span) {
260261
const samplingContext = span.transaction ? span.transaction.getDynamicSamplingContext() : undefined;

packages/core/src/tracing/hubextensions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Transaction } from './transaction';
1313
/** Returns all trace headers that are currently on the top scope. */
1414
function traceHeaders(this: Hub): { [key: string]: string } {
1515
const scope = this.getScope();
16+
// eslint-disable-next-line deprecation/deprecation
1617
const span = scope.getSpan();
1718

1819
return span

packages/core/src/tracing/idletransaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export class IdleTransaction extends Transaction {
124124
// We set the transaction here on the scope so error events pick up the trace
125125
// context and attach it to the error.
126126
DEBUG_BUILD && logger.log(`Setting idle transaction on scope. Span ID: ${this.spanContext().spanId}`);
127+
// eslint-disable-next-line deprecation/deprecation
127128
_idleHub.getScope().setSpan(this);
128129
}
129130

@@ -198,6 +199,7 @@ export class IdleTransaction extends Transaction {
198199
const scope = this._idleHub.getScope();
199200
// eslint-disable-next-line deprecation/deprecation
200201
if (scope.getTransaction() === this) {
202+
// eslint-disable-next-line deprecation/deprecation
201203
scope.setSpan(undefined);
202204
}
203205
}

packages/core/src/tracing/trace.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ export function trace<T>(
143143
): T {
144144
const hub = getCurrentHub();
145145
const scope = getCurrentScope();
146+
// eslint-disable-next-line deprecation/deprecation
146147
const parentSpan = scope.getSpan();
147148

148149
const ctx = normalizeContext(context);
149150
const activeSpan = createChildSpanOrTransaction(hub, parentSpan, ctx);
150151

152+
// eslint-disable-next-line deprecation/deprecation
151153
scope.setSpan(activeSpan);
152154

153155
return handleCallbackErrors(
@@ -158,6 +160,7 @@ export function trace<T>(
158160
},
159161
() => {
160162
activeSpan && activeSpan.end();
163+
// eslint-disable-next-line deprecation/deprecation
161164
scope.setSpan(parentSpan);
162165
afterFinish();
163166
},
@@ -180,10 +183,11 @@ export function startSpan<T>(context: StartSpanOptions, callback: (span: Span |
180183

181184
return withScope(context.scope, scope => {
182185
const hub = getCurrentHub();
183-
const scopeForSpan = context.scope || scope;
184-
const parentSpan = scopeForSpan.getSpan();
186+
// eslint-disable-next-line deprecation/deprecation
187+
const parentSpan = scope.getSpan();
185188

186189
const activeSpan = createChildSpanOrTransaction(hub, parentSpan, ctx);
190+
// eslint-disable-next-line deprecation/deprecation
187191
scope.setSpan(activeSpan);
188192

189193
return handleCallbackErrors(
@@ -223,9 +227,11 @@ export function startSpanManual<T>(
223227

224228
return withScope(context.scope, scope => {
225229
const hub = getCurrentHub();
230+
// eslint-disable-next-line deprecation/deprecation
226231
const parentSpan = scope.getSpan();
227232

228233
const activeSpan = createChildSpanOrTransaction(hub, parentSpan, ctx);
234+
// eslint-disable-next-line deprecation/deprecation
229235
scope.setSpan(activeSpan);
230236

231237
function finishAndSetSpan(): void {
@@ -261,7 +267,10 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined {
261267

262268
const ctx = normalizeContext(context);
263269
const hub = getCurrentHub();
264-
const parentSpan = context.scope ? context.scope.getSpan() : getActiveSpan();
270+
const parentSpan = context.scope
271+
? // eslint-disable-next-line deprecation/deprecation
272+
context.scope.getSpan()
273+
: getActiveSpan();
265274
return parentSpan
266275
? // eslint-disable-next-line deprecation/deprecation
267276
parentSpan.startChild(ctx)
@@ -273,6 +282,7 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined {
273282
* Returns the currently active span.
274283
*/
275284
export function getActiveSpan(): Span | undefined {
285+
// eslint-disable-next-line deprecation/deprecation
276286
return getCurrentScope().getSpan();
277287
}
278288

0 commit comments

Comments
 (0)