|
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'; |
2 | 9 | import { extractTraceparentData } from '@sentry/tracing';
|
3 | 10 | import { isString, logger, parseBaggageString, stripUrlQueryAndFragment } from '@sentry/utils';
|
4 | 11 |
|
5 | 12 | import { domainify, getActiveDomain, proxyFunction } from './../utils';
|
6 | 13 | import { HttpFunction, WrapperOptions } from './general';
|
7 | 14 |
|
8 |
| -type ParseRequestOptions = Handlers.ParseRequestOptions; |
9 |
| - |
10 |
| -export interface HttpFunctionWrapperOptions extends WrapperOptions { |
11 |
| - parseRequestOptions: ParseRequestOptions; |
| 15 | +// TODO (v8 / #5190): 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; |
12 | 24 | }
|
13 | 25 |
|
14 |
| -const { parseRequest } = Handlers; |
| 26 | +export type HttpFunctionWrapperOptions = OldHttpFunctionWrapperOptions | NewHttpFunctionWrapperOptions; |
15 | 27 |
|
16 | 28 | /**
|
17 | 29 | * Wraps an HTTP function handler adding it error capture and tracing capabilities.
|
@@ -40,9 +52,13 @@ export function wrapHttpFunction(
|
40 | 52 |
|
41 | 53 | /** */
|
42 | 54 | function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWrapperOptions> = {}): HttpFunction {
|
| 55 | + // TODO (v8 / #5190): Switch to using `addRequestDataToEventOptions` |
| 56 | + // eslint-disable-next-line deprecation/deprecation |
| 57 | + const { parseRequestOptions } = wrapOptions as OldHttpFunctionWrapperOptions; |
| 58 | + |
43 | 59 | const options: HttpFunctionWrapperOptions = {
|
44 | 60 | flushTimeout: 2000,
|
45 |
| - parseRequestOptions: {}, |
| 61 | + addRequestDataToEventOptions: parseRequestOptions ? parseRequestOptions : {}, |
46 | 62 | ...wrapOptions,
|
47 | 63 | };
|
48 | 64 | return (req, res) => {
|
@@ -72,7 +88,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
|
72 | 88 | // since functions-framework creates a domain for each incoming request.
|
73 | 89 | // So adding of event processors every time should not lead to memory bloat.
|
74 | 90 | getCurrentHub().configureScope(scope => {
|
75 |
| - scope.addEventProcessor(event => parseRequest(event, req, options.parseRequestOptions)); |
| 91 | + scope.addEventProcessor(event => addRequestDataToEvent(event, req, options.addRequestDataToEventOptions)); |
76 | 92 | // We put the transaction on the scope so users can attach children to it
|
77 | 93 | scope.setSpan(transaction);
|
78 | 94 | });
|
|
0 commit comments