Skip to content

Commit bf1b7ec

Browse files
committed
call startTransaction directly on hub
1 parent 922fb0e commit bf1b7ec

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

packages/remix/src/utils/instrumentServer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ function makeWrappedLoader(origAction: DataFunction): DataFunction {
132132

133133
function wrapRequestHandler(origRequestHandler: RequestHandler): RequestHandler {
134134
return async function (this: unknown, request: Request, loadContext?: unknown): Promise<Response> {
135-
const currentScope = getCurrentHub().getScope();
136-
const transaction = startTransaction({
135+
const hub = getCurrentHub();
136+
const currentScope = hub.getScope();
137+
const transaction = hub.startTransaction({
137138
name: stripUrlQueryAndFragment(request.url),
138139
op: 'http.server',
139140
tags: {

packages/serverless/src/awslambda.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
/* eslint-disable max-lines */
22
import * as Sentry from '@sentry/node';
3-
import {
4-
captureException,
5-
captureMessage,
6-
flush,
7-
getCurrentHub,
8-
Scope,
9-
startTransaction,
10-
withScope,
11-
} from '@sentry/node';
3+
import { captureException, captureMessage, flush, getCurrentHub, Scope, withScope } from '@sentry/node';
124
import { extractTraceparentData } from '@sentry/tracing';
135
import { Integration } from '@sentry/types';
146
import { dsnFromString, dsnToString, isString, logger, parseBaggageSetMutability } from '@sentry/utils';
@@ -320,14 +312,15 @@ export function wrapHandler<TEvent, TResult>(
320312
eventWithHeaders.headers && isString(eventWithHeaders.headers.baggage) && eventWithHeaders.headers.baggage;
321313
const baggage = parseBaggageSetMutability(rawBaggageString, traceparentData);
322314

323-
const transaction = startTransaction({
315+
const hub = getCurrentHub();
316+
317+
const transaction = hub.startTransaction({
324318
name: context.functionName,
325319
op: 'awslambda.handler',
326320
...traceparentData,
327321
metadata: { baggage },
328322
});
329323

330-
const hub = getCurrentHub();
331324
const scope = hub.pushScope();
332325
let rv: TResult;
333326
try {

packages/serverless/src/gcpfunction/cloud_events.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureException, flush, getCurrentHub, startTransaction } from '@sentry/node';
1+
import { captureException, flush, getCurrentHub } from '@sentry/node';
22
import { logger } from '@sentry/utils';
33

44
import { domainify, getActiveDomain, proxyFunction } from '../utils';
@@ -30,15 +30,17 @@ function _wrapCloudEventFunction(
3030
...wrapOptions,
3131
};
3232
return (context, callback) => {
33-
const transaction = startTransaction({
33+
const hub = getCurrentHub();
34+
35+
const transaction = hub.startTransaction({
3436
name: context.type || '<unknown>',
3537
op: 'gcp.function.cloud_event',
3638
});
3739

3840
// getCurrentHub() is expected to use current active domain as a carrier
3941
// since functions-framework creates a domain for each incoming request.
4042
// So adding of event processors every time should not lead to memory bloat.
41-
getCurrentHub().configureScope(scope => {
43+
hub.configureScope(scope => {
4244
scope.setContext('gcp.function.context', { ...context });
4345
// We put the transaction on the scope so users can attach children to it
4446
scope.setSpan(transaction);

packages/serverless/src/gcpfunction/events.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureException, flush, getCurrentHub, startTransaction } from '@sentry/node';
1+
import { captureException, flush, getCurrentHub } from '@sentry/node';
22
import { logger } from '@sentry/utils';
33

44
import { domainify, getActiveDomain, proxyFunction } from '../utils';
@@ -30,15 +30,17 @@ function _wrapEventFunction(
3030
...wrapOptions,
3131
};
3232
return (data, context, callback) => {
33-
const transaction = startTransaction({
33+
const hub = getCurrentHub();
34+
35+
const transaction = hub.startTransaction({
3436
name: context.eventType,
3537
op: 'gcp.function.event',
3638
});
3739

3840
// getCurrentHub() is expected to use current active domain as a carrier
3941
// since functions-framework creates a domain for each incoming request.
4042
// So adding of event processors every time should not lead to memory bloat.
41-
getCurrentHub().configureScope(scope => {
43+
hub.configureScope(scope => {
4244
scope.setContext('gcp.function.context', { ...context });
4345
// We put the transaction on the scope so users can attach children to it
4446
scope.setSpan(transaction);

packages/serverless/src/gcpfunction/http.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
captureException,
55
flush,
66
getCurrentHub,
7-
startTransaction,
87
} from '@sentry/node';
98
import { extractTraceparentData } from '@sentry/tracing';
109
import { isString, logger, parseBaggageSetMutability, stripUrlQueryAndFragment } from '@sentry/utils';
@@ -83,7 +82,9 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
8382

8483
const baggage = parseBaggageSetMutability(rawBaggageString, traceparentData);
8584

86-
const transaction = startTransaction({
85+
const hub = getCurrentHub();
86+
87+
const transaction = hub.startTransaction({
8788
name: `${reqMethod} ${reqUrl}`,
8889
op: 'gcp.function.http',
8990
...traceparentData,
@@ -93,7 +94,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
9394
// getCurrentHub() is expected to use current active domain as a carrier
9495
// since functions-framework creates a domain for each incoming request.
9596
// So adding of event processors every time should not lead to memory bloat.
96-
getCurrentHub().configureScope(scope => {
97+
hub.configureScope(scope => {
9798
scope.addEventProcessor(event => addRequestDataToEvent(event, req, options.addRequestDataToEventOptions));
9899
// We put the transaction on the scope so users can attach children to it
99100
scope.setSpan(transaction);

0 commit comments

Comments
 (0)