Skip to content

Commit c47ab4e

Browse files
committed
use new functions (in backwards-compatible way for types) in serverless SDK
1 parent 530af40 commit c47ab4e

File tree

1 file changed

+24
-8
lines changed
  • packages/serverless/src/gcpfunction

1 file changed

+24
-8
lines changed

packages/serverless/src/gcpfunction/http.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
import { captureException, flush, getCurrentHub, Handlers, startTransaction } from '@sentry/node';
1+
import {
2+
addRequestDataToEvent,
3+
AddRequestDataToEventOptions,
4+
captureException,
5+
flush,
6+
getCurrentHub,
7+
startTransaction,
8+
} from '@sentry/node';
29
import { extractTraceparentData } from '@sentry/tracing';
310
import { isString, logger, parseBaggageSetMutability, stripUrlQueryAndFragment } from '@sentry/utils';
411

512
import { domainify, getActiveDomain, proxyFunction } from './../utils';
613
import { HttpFunction, WrapperOptions } from './general';
714

8-
type ParseRequestOptions = Handlers.ParseRequestOptions;
9-
10-
export interface HttpFunctionWrapperOptions extends WrapperOptions {
11-
parseRequestOptions: ParseRequestOptions;
15+
// TODO (v8 / #5257): Remove this whole old/new business and just use the new stuff
16+
interface OldHttpFunctionWrapperOptions extends WrapperOptions {
17+
/**
18+
* @deprecated Use `addRequestDataToEventOptions` instead.
19+
*/
20+
parseRequestOptions: AddRequestDataToEventOptions;
21+
}
22+
interface NewHttpFunctionWrapperOptions extends WrapperOptions {
23+
addRequestDataToEventOptions: AddRequestDataToEventOptions;
1224
}
1325

14-
const { parseRequest } = Handlers;
26+
export type HttpFunctionWrapperOptions = OldHttpFunctionWrapperOptions | NewHttpFunctionWrapperOptions;
1527

1628
/**
1729
* Wraps an HTTP function handler adding it error capture and tracing capabilities.
@@ -40,9 +52,13 @@ export function wrapHttpFunction(
4052

4153
/** */
4254
function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWrapperOptions> = {}): HttpFunction {
55+
// TODO (v8 / #5257): Switch to using `addRequestDataToEventOptions`
56+
// eslint-disable-next-line deprecation/deprecation
57+
const { parseRequestOptions } = wrapOptions as OldHttpFunctionWrapperOptions;
58+
4359
const options: HttpFunctionWrapperOptions = {
4460
flushTimeout: 2000,
45-
parseRequestOptions: {},
61+
addRequestDataToEventOptions: parseRequestOptions ? parseRequestOptions : {},
4662
...wrapOptions,
4763
};
4864
return (req, res) => {
@@ -72,7 +88,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
7288
// since functions-framework creates a domain for each incoming request.
7389
// So adding of event processors every time should not lead to memory bloat.
7490
getCurrentHub().configureScope(scope => {
75-
scope.addEventProcessor(event => parseRequest(event, req, options.parseRequestOptions));
91+
scope.addEventProcessor(event => addRequestDataToEvent(event, req, options.addRequestDataToEventOptions));
7692
// We put the transaction on the scope so users can attach children to it
7793
scope.setSpan(transaction);
7894
});

0 commit comments

Comments
 (0)