Skip to content

Commit 9f5b9a4

Browse files
author
Luca Forstner
committed
meta: Partially deprecate continueTrace
1 parent 4097c4a commit 9f5b9a4

File tree

2 files changed

+71
-22
lines changed

2 files changed

+71
-22
lines changed

MIGRATION.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,32 @@ be removed. Instead, use the new performance APIs:
179179

180180
You can [read more about the new performance APIs here](./docs/v8-new-performance-apis.md).
181181

182+
## Deprecate variations of `Sentry.continueTrace()`
183+
184+
The version of `Sentry.continueTrace()` which does not take a callback argument will be removed in favor of the version
185+
that does. Additionally, the callback argument will not receive an argument with the next major version.
186+
187+
Use `Sentry.continueTrace()` as follows:
188+
189+
```ts
190+
app.get('/your-route', req => {
191+
Sentry.withIsolationScope(isolationScope => {
192+
Sentry.continueTrace(
193+
{
194+
sentryTrace: req.headers.get('sentry-trace'),
195+
baggage: req.headers.get('baggage'),
196+
},
197+
() => {
198+
// All events recorded in this callback will be associated with the incoming trace. For example:
199+
Sentry.startSpan({ name: '/my-route' }, async () => {
200+
await doExpensiveWork();
201+
});
202+
},
203+
);
204+
});
205+
});
206+
```
207+
182208
## Deprecate `Sentry.lastEventId()` and `hub.lastEventId()`
183209

184210
`Sentry.lastEventId()` sometimes causes race conditions, so we are deprecating it in favour of the `beforeSend`

packages/core/src/tracing/trace.ts

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -224,31 +224,54 @@ export function getActiveSpan(): Span | undefined {
224224
return getCurrentScope().getSpan();
225225
}
226226

227-
export function continueTrace({
228-
sentryTrace,
229-
baggage,
230-
}: {
231-
sentryTrace: Parameters<typeof tracingContextFromHeaders>[0];
232-
baggage: Parameters<typeof tracingContextFromHeaders>[1];
233-
}): Partial<TransactionContext>;
234-
export function continueTrace<V>(
235-
{
227+
interface ContinueTrace {
228+
/**
229+
* Continue a trace from `sentry-trace` and `baggage` values.
230+
* These values can be obtained from incoming request headers,
231+
* or in the browser from `<meta name="sentry-trace">` and `<meta name="baggage">` HTML tags.
232+
*
233+
* @deprecated Use the version of this function taking a callback as second parameter instead:
234+
*
235+
* ```
236+
* Sentry.continueTrace(sentryTrace: '...', baggage: '...' }, () => {
237+
* // ...
238+
* })
239+
* ```
240+
*
241+
*/
242+
({
236243
sentryTrace,
237244
baggage,
238245
}: {
239246
sentryTrace: Parameters<typeof tracingContextFromHeaders>[0];
240247
baggage: Parameters<typeof tracingContextFromHeaders>[1];
241-
},
242-
callback: (transactionContext: Partial<TransactionContext>) => V,
243-
): V;
244-
/**
245-
* Continue a trace from `sentry-trace` and `baggage` values.
246-
* These values can be obtained from incoming request headers,
247-
* or in the browser from `<meta name="sentry-trace">` and `<meta name="baggage">` HTML tags.
248-
*
249-
* The callback receives a transactionContext that may be used for `startTransaction` or `startSpan`.
250-
*/
251-
export function continueTrace<V>(
248+
}): Partial<TransactionContext>;
249+
250+
/**
251+
* Continue a trace from `sentry-trace` and `baggage` values.
252+
* These values can be obtained from incoming request headers, or in the browser from `<meta name="sentry-trace">`
253+
* and `<meta name="baggage">` HTML tags.
254+
*
255+
* Spans started with `startSpan`, `startSpanManual` and `startInactiveSpan`, within the callback will automatically
256+
* be attached to the incoming trace.
257+
*
258+
* Deprecation notice: In the next major version of the SDK the provided callback will not receive a transaction
259+
* context argument.
260+
*/
261+
<V>(
262+
{
263+
sentryTrace,
264+
baggage,
265+
}: {
266+
sentryTrace: Parameters<typeof tracingContextFromHeaders>[0];
267+
baggage: Parameters<typeof tracingContextFromHeaders>[1];
268+
},
269+
// TODO(v8): Remove parameter from this callback.
270+
callback: (transactionContext: Partial<TransactionContext>) => V,
271+
): V;
272+
}
273+
274+
export const continueTrace: ContinueTrace = <V>(
252275
{
253276
sentryTrace,
254277
baggage,
@@ -257,7 +280,7 @@ export function continueTrace<V>(
257280
baggage: Parameters<typeof tracingContextFromHeaders>[1];
258281
},
259282
callback?: (transactionContext: Partial<TransactionContext>) => V,
260-
): V | Partial<TransactionContext> {
283+
): V | Partial<TransactionContext> => {
261284
const currentScope = getCurrentScope();
262285

263286
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
@@ -283,7 +306,7 @@ export function continueTrace<V>(
283306
}
284307

285308
return callback(transactionContext);
286-
}
309+
};
287310

288311
function createChildSpanOrTransaction(
289312
hub: Hub,

0 commit comments

Comments
 (0)