@sentry/google-cloud-serverless 11.12.0 → 11.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/debug-build.js +9 -5
- package/build/cjs/debug-build.js.map +1 -1
- package/build/cjs/gcpfunction/cloud_events.js +56 -67
- package/build/cjs/gcpfunction/cloud_events.js.map +1 -1
- package/build/cjs/gcpfunction/events.js +57 -67
- package/build/cjs/gcpfunction/events.js.map +1 -1
- package/build/cjs/gcpfunction/http.js +66 -67
- package/build/cjs/gcpfunction/http.js.map +1 -1
- package/build/cjs/index.js +213 -217
- package/build/cjs/integrations/gcp-context.js +28 -34
- package/build/cjs/integrations/gcp-context.js.map +1 -1
- package/build/cjs/integrations/google-cloud-grpc.js +61 -77
- package/build/cjs/integrations/google-cloud-grpc.js.map +1 -1
- package/build/cjs/integrations/google-cloud-http.js +52 -51
- package/build/cjs/integrations/google-cloud-http.js.map +1 -1
- package/build/cjs/sdk.js +25 -24
- package/build/cjs/sdk.js.map +1 -1
- package/build/cjs/utils.js +44 -28
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/_virtual/_rolldown/runtime.js +6 -0
- package/build/esm/debug-build.js +9 -3
- package/build/esm/debug-build.js.map +1 -1
- package/build/esm/gcpfunction/cloud_events.js +56 -65
- package/build/esm/gcpfunction/cloud_events.js.map +1 -1
- package/build/esm/gcpfunction/events.js +57 -65
- package/build/esm/gcpfunction/events.js.map +1 -1
- package/build/esm/gcpfunction/http.js +66 -65
- package/build/esm/gcpfunction/http.js.map +1 -1
- package/build/esm/index.js +9 -9
- package/build/esm/integrations/gcp-context.js +27 -31
- package/build/esm/integrations/gcp-context.js.map +1 -1
- package/build/esm/integrations/google-cloud-grpc.js +61 -74
- package/build/esm/integrations/google-cloud-grpc.js.map +1 -1
- package/build/esm/integrations/google-cloud-http.js +52 -48
- package/build/esm/integrations/google-cloud-http.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/sdk.js +22 -16
- package/build/esm/sdk.js.map +1 -1
- package/build/esm/utils.js +44 -26
- package/build/esm/utils.js.map +1 -1
- package/build/import-hook.mjs +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/package.json +11 -15
- package/build/cjs/index.js.map +0 -1
- package/build/esm/index.js.map +0 -1
package/build/cjs/debug-build.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/debug-build.ts
|
|
2
|
+
/**
|
|
3
|
+
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
|
|
4
|
+
*
|
|
5
|
+
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
|
|
6
|
+
*/
|
|
7
|
+
const DEBUG_BUILD = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
|
|
5
8
|
exports.DEBUG_BUILD = DEBUG_BUILD;
|
|
6
|
-
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=debug-build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-build.js","sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"
|
|
1
|
+
{"version":3,"file":"debug-build.js","names":[],"sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"mappings":";;;;;;AAOA,MAAa,cAAe,OAAO,qBAAqB,eAAe"}
|
|
@@ -1,72 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const require_debug_build = require("../debug-build.js");
|
|
2
|
+
const require_utils = require("../utils.js");
|
|
3
|
+
let _sentry_node = require("@sentry/node");
|
|
4
|
+
let _sentry_core = require("@sentry/core");
|
|
5
|
+
let _sentry_conventions_attributes = require("@sentry/conventions/attributes");
|
|
6
|
+
let _sentry_conventions_op = require("@sentry/conventions/op");
|
|
7
|
+
// src/gcpfunction/cloud_events.ts
|
|
8
|
+
/**
|
|
9
|
+
* Wraps an event function handler adding it error capture and tracing capabilities.
|
|
10
|
+
*
|
|
11
|
+
* @param fn Event handler
|
|
12
|
+
* @param options Options
|
|
13
|
+
* @returns Event handler
|
|
14
|
+
*/
|
|
10
15
|
function wrapCloudEventFunction(fn, wrapOptions = {}) {
|
|
11
|
-
|
|
16
|
+
return require_utils.proxyFunction(fn, (f) => require_utils.domainify(_wrapCloudEventFunction(f, wrapOptions)));
|
|
12
17
|
}
|
|
13
18
|
function _wrapCloudEventFunction(fn, wrapOptions = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
if (fn.length > 1) {
|
|
55
|
-
return core.handleCallbackErrors(
|
|
56
|
-
() => fn(context, newCallback),
|
|
57
|
-
(err) => {
|
|
58
|
-
node.captureException(err, (scope2) => utils.markEventUnhandled(scope2, "auto.function.serverless.gcp_cloud_event"));
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return Promise.resolve().then(() => fn(context)).then(
|
|
63
|
-
(result) => newCallback(null, result),
|
|
64
|
-
(err) => newCallback(err, void 0)
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
};
|
|
19
|
+
const options = {
|
|
20
|
+
flushTimeout: 2e3,
|
|
21
|
+
...wrapOptions
|
|
22
|
+
};
|
|
23
|
+
return (context, callback) => {
|
|
24
|
+
const client = (0, _sentry_core.getClient)();
|
|
25
|
+
const functionName = require_utils.getFunctionName();
|
|
26
|
+
const name = client && (0, _sentry_core.hasSpanStreamingEnabled)(client) ? functionName || _sentry_core.SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : context.type || "<unknown>";
|
|
27
|
+
return (0, _sentry_node.startSpanManual)({
|
|
28
|
+
name,
|
|
29
|
+
attributes: {
|
|
30
|
+
[_sentry_conventions_attributes.SENTRY_OP]: _sentry_conventions_op.FUNCTION_GCP,
|
|
31
|
+
[_sentry_conventions_attributes.FAAS_NAME]: functionName,
|
|
32
|
+
[_sentry_conventions_attributes.FAAS_TRIGGER]: "cloud_event",
|
|
33
|
+
[_sentry_conventions_attributes.SENTRY_SEGMENT_NAME_SOURCE]: "component",
|
|
34
|
+
[_sentry_conventions_attributes.SENTRY_ORIGIN]: "auto.function.serverless.gcp_cloud_event",
|
|
35
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_TYPE]: context.type,
|
|
36
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_ID]: context.id,
|
|
37
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_SOURCE]: context.source,
|
|
38
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_SPECVERSION]: context.specversion,
|
|
39
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_TIME]: context.time
|
|
40
|
+
}
|
|
41
|
+
}, (span) => {
|
|
42
|
+
(0, _sentry_node.getCurrentScope)().setContext("gcp.function.context", { ...context });
|
|
43
|
+
const newCallback = require_utils.domainify((...args) => {
|
|
44
|
+
if (args[0] !== null && args[0] !== void 0) (0, _sentry_node.captureException)(args[0], (scope) => require_utils.markEventUnhandled(scope, "auto.function.serverless.gcp_cloud_event"));
|
|
45
|
+
span.end();
|
|
46
|
+
(0, _sentry_node.flush)(options.flushTimeout).then(null, (e) => {
|
|
47
|
+
require_debug_build.DEBUG_BUILD && _sentry_core.debug.error(e);
|
|
48
|
+
}).then(() => {
|
|
49
|
+
if (typeof callback === "function") callback(...args);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
if (fn.length > 1) return (0, _sentry_core.handleCallbackErrors)(() => fn(context, newCallback), (err) => {
|
|
53
|
+
(0, _sentry_node.captureException)(err, (scope) => require_utils.markEventUnhandled(scope, "auto.function.serverless.gcp_cloud_event"));
|
|
54
|
+
});
|
|
55
|
+
return Promise.resolve().then(() => fn(context)).then((result) => newCallback(null, result), (err) => newCallback(err, void 0));
|
|
56
|
+
});
|
|
57
|
+
};
|
|
69
58
|
}
|
|
70
|
-
|
|
71
59
|
exports.wrapCloudEventFunction = wrapCloudEventFunction;
|
|
72
|
-
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=cloud_events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud_events.js","sources":["../../../src/gcpfunction/cloud_events.ts"],"sourcesContent":["import {\n SENTRY_SEGMENT_NAME_SOURCE,\n FAAS_NAME,\n FAAS_TRIGGER,\n SENTRY_OP,\n GCP_FUNCTION_CONTEXT_TYPE,\n GCP_FUNCTION_CONTEXT_ID,\n GCP_FUNCTION_CONTEXT_SOURCE,\n GCP_FUNCTION_CONTEXT_SPECVERSION,\n GCP_FUNCTION_CONTEXT_TIME,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION_GCP } from '@sentry/conventions/op';\nimport {\n debug,\n getClient,\n handleCallbackErrors,\n hasSpanStreamingEnabled,\n SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK,\n} from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, getFunctionName, markEventUnhandled, proxyFunction } from '../utils';\nimport type { CloudEventFunction, CloudEventFunctionWithCallback, WrapperOptions } from './general';\n\nexport type CloudEventFunctionWrapperOptions = WrapperOptions;\n\n/**\n * Wraps an event function handler adding it error capture and tracing capabilities.\n *\n * @param fn Event handler\n * @param options Options\n * @returns Event handler\n */\nexport function wrapCloudEventFunction(\n fn: CloudEventFunction | CloudEventFunctionWithCallback,\n wrapOptions: Partial<CloudEventFunctionWrapperOptions> = {},\n): CloudEventFunctionWithCallback {\n return proxyFunction(fn, f => domainify(_wrapCloudEventFunction(f, wrapOptions)));\n}\n\nfunction _wrapCloudEventFunction(\n fn: CloudEventFunction | CloudEventFunctionWithCallback,\n wrapOptions: Partial<CloudEventFunctionWrapperOptions> = {},\n): CloudEventFunctionWithCallback {\n const options: CloudEventFunctionWrapperOptions = {\n flushTimeout: 2000,\n ...wrapOptions,\n };\n return (context, callback) => {\n const client = getClient();\n\n const functionName = getFunctionName();\n const name =\n client && hasSpanStreamingEnabled(client)\n ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK\n : context.type || '<unknown>';\n\n return startSpanManual(\n {\n name,\n attributes: {\n [SENTRY_OP]: FUNCTION_GCP,\n [FAAS_NAME]: functionName,\n [FAAS_TRIGGER]: 'cloud_event',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'component',\n [SENTRY_ORIGIN]: 'auto.function.serverless.gcp_cloud_event',\n [GCP_FUNCTION_CONTEXT_TYPE]: context.type,\n [GCP_FUNCTION_CONTEXT_ID]: context.id,\n [GCP_FUNCTION_CONTEXT_SOURCE]: context.source,\n [GCP_FUNCTION_CONTEXT_SPECVERSION]: context.specversion,\n [GCP_FUNCTION_CONTEXT_TIME]: context.time,\n },\n },\n span => {\n const scope = getCurrentScope();\n scope.setContext('gcp.function.context', { ...context });\n\n const newCallback = domainify((...args: unknown[]) => {\n if (args[0] !== null && args[0] !== undefined) {\n captureException(args[0], scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_cloud_event'));\n }\n span.end();\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n flush(options.flushTimeout)\n .then(null, e => {\n DEBUG_BUILD && debug.error(e);\n })\n .then(() => {\n if (typeof callback === 'function') {\n callback(...args);\n }\n });\n });\n\n if (fn.length > 1) {\n return handleCallbackErrors(\n () => (fn as CloudEventFunctionWithCallback)(context, newCallback),\n err => {\n captureException(err, scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_cloud_event'));\n },\n );\n }\n\n return Promise.resolve()\n .then(() => (fn as CloudEventFunction)(context))\n .then(\n result => newCallback(null, result),\n err => newCallback(err, undefined),\n );\n },\n );\n };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"cloud_events.js","names":["proxyFunction","domainify","getClient","getFunctionName","hasSpanStreamingEnabled","SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK","startSpanManual","SENTRY_OP","FUNCTION_GCP","FAAS_NAME","FAAS_TRIGGER","SENTRY_SEGMENT_NAME_SOURCE","SENTRY_ORIGIN","GCP_FUNCTION_CONTEXT_TYPE","GCP_FUNCTION_CONTEXT_ID","GCP_FUNCTION_CONTEXT_SOURCE","GCP_FUNCTION_CONTEXT_SPECVERSION","GCP_FUNCTION_CONTEXT_TIME","getCurrentScope","captureException","markEventUnhandled","flush","DEBUG_BUILD","debug","handleCallbackErrors"],"sources":["../../../src/gcpfunction/cloud_events.ts"],"sourcesContent":["import {\n SENTRY_SEGMENT_NAME_SOURCE,\n FAAS_NAME,\n FAAS_TRIGGER,\n SENTRY_OP,\n GCP_FUNCTION_CONTEXT_TYPE,\n GCP_FUNCTION_CONTEXT_ID,\n GCP_FUNCTION_CONTEXT_SOURCE,\n GCP_FUNCTION_CONTEXT_SPECVERSION,\n GCP_FUNCTION_CONTEXT_TIME,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION_GCP } from '@sentry/conventions/op';\nimport {\n debug,\n getClient,\n handleCallbackErrors,\n hasSpanStreamingEnabled,\n SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK,\n} from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, getFunctionName, markEventUnhandled, proxyFunction } from '../utils';\nimport type { CloudEventFunction, CloudEventFunctionWithCallback, WrapperOptions } from './general';\n\nexport type CloudEventFunctionWrapperOptions = WrapperOptions;\n\n/**\n * Wraps an event function handler adding it error capture and tracing capabilities.\n *\n * @param fn Event handler\n * @param options Options\n * @returns Event handler\n */\nexport function wrapCloudEventFunction(\n fn: CloudEventFunction | CloudEventFunctionWithCallback,\n wrapOptions: Partial<CloudEventFunctionWrapperOptions> = {},\n): CloudEventFunctionWithCallback {\n return proxyFunction(fn, f => domainify(_wrapCloudEventFunction(f, wrapOptions)));\n}\n\nfunction _wrapCloudEventFunction(\n fn: CloudEventFunction | CloudEventFunctionWithCallback,\n wrapOptions: Partial<CloudEventFunctionWrapperOptions> = {},\n): CloudEventFunctionWithCallback {\n const options: CloudEventFunctionWrapperOptions = {\n flushTimeout: 2000,\n ...wrapOptions,\n };\n return (context, callback) => {\n const client = getClient();\n\n const functionName = getFunctionName();\n const name =\n client && hasSpanStreamingEnabled(client)\n ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK\n : context.type || '<unknown>';\n\n return startSpanManual(\n {\n name,\n attributes: {\n [SENTRY_OP]: FUNCTION_GCP,\n [FAAS_NAME]: functionName,\n [FAAS_TRIGGER]: 'cloud_event',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'component',\n [SENTRY_ORIGIN]: 'auto.function.serverless.gcp_cloud_event',\n [GCP_FUNCTION_CONTEXT_TYPE]: context.type,\n [GCP_FUNCTION_CONTEXT_ID]: context.id,\n [GCP_FUNCTION_CONTEXT_SOURCE]: context.source,\n [GCP_FUNCTION_CONTEXT_SPECVERSION]: context.specversion,\n [GCP_FUNCTION_CONTEXT_TIME]: context.time,\n },\n },\n span => {\n const scope = getCurrentScope();\n scope.setContext('gcp.function.context', { ...context });\n\n const newCallback = domainify((...args: unknown[]) => {\n if (args[0] !== null && args[0] !== undefined) {\n captureException(args[0], scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_cloud_event'));\n }\n span.end();\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n flush(options.flushTimeout)\n .then(null, e => {\n DEBUG_BUILD && debug.error(e);\n })\n .then(() => {\n if (typeof callback === 'function') {\n callback(...args);\n }\n });\n });\n\n if (fn.length > 1) {\n return handleCallbackErrors(\n () => (fn as CloudEventFunctionWithCallback)(context, newCallback),\n err => {\n captureException(err, scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_cloud_event'));\n },\n );\n }\n\n return Promise.resolve()\n .then(() => (fn as CloudEventFunction)(context))\n .then(\n result => newCallback(null, result),\n err => newCallback(err, undefined),\n );\n },\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCA,SAAgB,uBACd,IACA,cAAyD,CAAC,GAC1B;CAChC,OAAOA,cAAAA,cAAc,KAAI,MAAKC,cAAAA,UAAU,wBAAwB,GAAG,WAAW,CAAC,CAAC;AAClF;AAEA,SAAS,wBACP,IACA,cAAyD,CAAC,GAC1B;CAChC,MAAM,UAA4C;EAChD,cAAc;EACd,GAAG;CACL;CACA,Q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AiB,MAAK,UAASC,cAAAA,mBAAmB,OAAO,0CAA0C,CAAC;GACtG,CACF;GAGF,OAAO,QAAQ,QAAQ,CAAC,CACrB,WAAY,GAA0B,OAAO,CAAC,CAAC,CAC/C,MACC,WAAU,YAAY,MAAM,MAAM,IAClC,QAAO,YAAY,KAAK,KAAA,CAAS,CACnC;EACJ,CACF;CACF;AACF"}
|
|
@@ -1,72 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const require_debug_build = require("../debug-build.js");
|
|
2
|
+
const require_utils = require("../utils.js");
|
|
3
|
+
let _sentry_node = require("@sentry/node");
|
|
4
|
+
let _sentry_core = require("@sentry/core");
|
|
5
|
+
let _sentry_conventions_attributes = require("@sentry/conventions/attributes");
|
|
6
|
+
let _sentry_conventions_op = require("@sentry/conventions/op");
|
|
7
|
+
// src/gcpfunction/events.ts
|
|
8
|
+
/**
|
|
9
|
+
* Wraps an event function handler adding it error capture and tracing capabilities.
|
|
10
|
+
*
|
|
11
|
+
* @param fn Event handler
|
|
12
|
+
* @param options Options
|
|
13
|
+
* @returns Event handler
|
|
14
|
+
*/
|
|
10
15
|
function wrapEventFunction(fn, wrapOptions = {}) {
|
|
11
|
-
|
|
16
|
+
return require_utils.proxyFunction(fn, (f) => require_utils.domainify(_wrapEventFunction(f, wrapOptions)));
|
|
12
17
|
}
|
|
18
|
+
/** */
|
|
13
19
|
function _wrapEventFunction(fn, wrapOptions = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
if (fn.length > 2) {
|
|
55
|
-
return core.handleCallbackErrors(
|
|
56
|
-
() => fn(data, context, newCallback),
|
|
57
|
-
(err) => {
|
|
58
|
-
node.captureException(err, (scope2) => utils.markEventUnhandled(scope2, "auto.function.serverless.gcp_event"));
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return Promise.resolve().then(() => fn(data, context)).then(
|
|
63
|
-
(result) => newCallback(null, result),
|
|
64
|
-
(err) => newCallback(err, void 0)
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
};
|
|
20
|
+
const options = {
|
|
21
|
+
flushTimeout: 2e3,
|
|
22
|
+
...wrapOptions
|
|
23
|
+
};
|
|
24
|
+
return (...eventFunctionArguments) => {
|
|
25
|
+
const [data, context, callback] = eventFunctionArguments;
|
|
26
|
+
const client = (0, _sentry_core.getClient)();
|
|
27
|
+
const functionName = require_utils.getFunctionName();
|
|
28
|
+
const name = client && (0, _sentry_core.hasSpanStreamingEnabled)(client) ? functionName || _sentry_core.SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : context.eventType;
|
|
29
|
+
return (0, _sentry_node.startSpanManual)({
|
|
30
|
+
name,
|
|
31
|
+
attributes: {
|
|
32
|
+
[_sentry_conventions_attributes.SENTRY_OP]: _sentry_conventions_op.FUNCTION_GCP,
|
|
33
|
+
[_sentry_conventions_attributes.FAAS_NAME]: functionName,
|
|
34
|
+
[_sentry_conventions_attributes.FAAS_TRIGGER]: "event",
|
|
35
|
+
[_sentry_conventions_attributes.SENTRY_SEGMENT_NAME_SOURCE]: "component",
|
|
36
|
+
[_sentry_conventions_attributes.SENTRY_ORIGIN]: "auto.function.serverless.gcp_event",
|
|
37
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_EVENT_TYPE]: context.eventType,
|
|
38
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_EVENT_ID]: context.eventId,
|
|
39
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_RESOURCE]: context.resource,
|
|
40
|
+
[_sentry_conventions_attributes.GCP_FUNCTION_CONTEXT_TIMESTAMP]: context.timestamp
|
|
41
|
+
}
|
|
42
|
+
}, (span) => {
|
|
43
|
+
(0, _sentry_node.getCurrentScope)().setContext("gcp.function.context", { ...context });
|
|
44
|
+
const newCallback = require_utils.domainify((...args) => {
|
|
45
|
+
if (args[0] !== null && args[0] !== void 0) (0, _sentry_node.captureException)(args[0], (scope) => require_utils.markEventUnhandled(scope, "auto.function.serverless.gcp_event"));
|
|
46
|
+
span.end();
|
|
47
|
+
(0, _sentry_node.flush)(options.flushTimeout).then(null, (e) => {
|
|
48
|
+
require_debug_build.DEBUG_BUILD && _sentry_core.debug.error(e);
|
|
49
|
+
}).then(() => {
|
|
50
|
+
if (typeof callback === "function") callback(...args);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
if (fn.length > 2) return (0, _sentry_core.handleCallbackErrors)(() => fn(data, context, newCallback), (err) => {
|
|
54
|
+
(0, _sentry_node.captureException)(err, (scope) => require_utils.markEventUnhandled(scope, "auto.function.serverless.gcp_event"));
|
|
55
|
+
});
|
|
56
|
+
return Promise.resolve().then(() => fn(data, context)).then((result) => newCallback(null, result), (err) => newCallback(err, void 0));
|
|
57
|
+
});
|
|
58
|
+
};
|
|
69
59
|
}
|
|
70
|
-
|
|
71
60
|
exports.wrapEventFunction = wrapEventFunction;
|
|
72
|
-
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sources":["../../../src/gcpfunction/events.ts"],"sourcesContent":["import {\n SENTRY_SEGMENT_NAME_SOURCE,\n FAAS_NAME,\n FAAS_TRIGGER,\n SENTRY_OP,\n GCP_FUNCTION_CONTEXT_EVENT_TYPE,\n GCP_FUNCTION_CONTEXT_EVENT_ID,\n GCP_FUNCTION_CONTEXT_RESOURCE,\n GCP_FUNCTION_CONTEXT_TIMESTAMP,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION_GCP } from '@sentry/conventions/op';\nimport {\n debug,\n getClient,\n handleCallbackErrors,\n hasSpanStreamingEnabled,\n SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK,\n} from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, getFunctionName, markEventUnhandled, proxyFunction } from '../utils';\nimport type { EventFunction, EventFunctionWithCallback, WrapperOptions } from './general';\n\nexport type EventFunctionWrapperOptions = WrapperOptions;\n\n/**\n * Wraps an event function handler adding it error capture and tracing capabilities.\n *\n * @param fn Event handler\n * @param options Options\n * @returns Event handler\n */\nexport function wrapEventFunction(\n fn: EventFunction | EventFunctionWithCallback,\n wrapOptions: Partial<EventFunctionWrapperOptions> = {},\n): EventFunctionWithCallback {\n return proxyFunction(fn, f => domainify(_wrapEventFunction(f, wrapOptions)));\n}\n\n/** */\nfunction _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>(\n fn: F,\n wrapOptions: Partial<EventFunctionWrapperOptions> = {},\n): (...args: Parameters<F>) => ReturnType<F> | Promise<void> {\n const options: EventFunctionWrapperOptions = {\n flushTimeout: 2000,\n ...wrapOptions,\n };\n return (...eventFunctionArguments: Parameters<F>): ReturnType<F> | Promise<void> => {\n const [data, context, callback] = eventFunctionArguments;\n\n const client = getClient();\n\n const functionName = getFunctionName();\n const name =\n client && hasSpanStreamingEnabled(client)\n ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK\n : context.eventType;\n\n return startSpanManual(\n {\n name,\n attributes: {\n [SENTRY_OP]: FUNCTION_GCP,\n [FAAS_NAME]: functionName,\n [FAAS_TRIGGER]: 'event',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'component',\n [SENTRY_ORIGIN]: 'auto.function.serverless.gcp_event',\n [GCP_FUNCTION_CONTEXT_EVENT_TYPE]: context.eventType,\n [GCP_FUNCTION_CONTEXT_EVENT_ID]: context.eventId,\n [GCP_FUNCTION_CONTEXT_RESOURCE]: context.resource,\n [GCP_FUNCTION_CONTEXT_TIMESTAMP]: context.timestamp,\n },\n },\n span => {\n const scope = getCurrentScope();\n scope.setContext('gcp.function.context', { ...context });\n\n const newCallback = domainify((...args: unknown[]) => {\n if (args[0] !== null && args[0] !== undefined) {\n captureException(args[0], scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_event'));\n }\n span.end();\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n flush(options.flushTimeout)\n .then(null, e => {\n DEBUG_BUILD && debug.error(e);\n })\n .then(() => {\n if (typeof callback === 'function') {\n callback(...args);\n }\n });\n });\n\n if (fn.length > 2) {\n return handleCallbackErrors(\n () => (fn as EventFunctionWithCallback)(data, context, newCallback),\n err => {\n captureException(err, scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_event'));\n },\n );\n }\n\n return Promise.resolve()\n .then(() => (fn as EventFunction)(data, context))\n .then(\n result => newCallback(null, result),\n err => newCallback(err, undefined),\n );\n },\n );\n };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"events.js","names":["proxyFunction","domainify","getClient","getFunctionName","hasSpanStreamingEnabled","SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK","startSpanManual","SENTRY_OP","FUNCTION_GCP","FAAS_NAME","FAAS_TRIGGER","SENTRY_SEGMENT_NAME_SOURCE","SENTRY_ORIGIN","GCP_FUNCTION_CONTEXT_EVENT_TYPE","GCP_FUNCTION_CONTEXT_EVENT_ID","GCP_FUNCTION_CONTEXT_RESOURCE","GCP_FUNCTION_CONTEXT_TIMESTAMP","getCurrentScope","captureException","markEventUnhandled","flush","DEBUG_BUILD","debug","handleCallbackErrors"],"sources":["../../../src/gcpfunction/events.ts"],"sourcesContent":["import {\n SENTRY_SEGMENT_NAME_SOURCE,\n FAAS_NAME,\n FAAS_TRIGGER,\n SENTRY_OP,\n GCP_FUNCTION_CONTEXT_EVENT_TYPE,\n GCP_FUNCTION_CONTEXT_EVENT_ID,\n GCP_FUNCTION_CONTEXT_RESOURCE,\n GCP_FUNCTION_CONTEXT_TIMESTAMP,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION_GCP } from '@sentry/conventions/op';\nimport {\n debug,\n getClient,\n handleCallbackErrors,\n hasSpanStreamingEnabled,\n SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK,\n} from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, getFunctionName, markEventUnhandled, proxyFunction } from '../utils';\nimport type { EventFunction, EventFunctionWithCallback, WrapperOptions } from './general';\n\nexport type EventFunctionWrapperOptions = WrapperOptions;\n\n/**\n * Wraps an event function handler adding it error capture and tracing capabilities.\n *\n * @param fn Event handler\n * @param options Options\n * @returns Event handler\n */\nexport function wrapEventFunction(\n fn: EventFunction | EventFunctionWithCallback,\n wrapOptions: Partial<EventFunctionWrapperOptions> = {},\n): EventFunctionWithCallback {\n return proxyFunction(fn, f => domainify(_wrapEventFunction(f, wrapOptions)));\n}\n\n/** */\nfunction _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>(\n fn: F,\n wrapOptions: Partial<EventFunctionWrapperOptions> = {},\n): (...args: Parameters<F>) => ReturnType<F> | Promise<void> {\n const options: EventFunctionWrapperOptions = {\n flushTimeout: 2000,\n ...wrapOptions,\n };\n return (...eventFunctionArguments: Parameters<F>): ReturnType<F> | Promise<void> => {\n const [data, context, callback] = eventFunctionArguments;\n\n const client = getClient();\n\n const functionName = getFunctionName();\n const name =\n client && hasSpanStreamingEnabled(client)\n ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK\n : context.eventType;\n\n return startSpanManual(\n {\n name,\n attributes: {\n [SENTRY_OP]: FUNCTION_GCP,\n [FAAS_NAME]: functionName,\n [FAAS_TRIGGER]: 'event',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'component',\n [SENTRY_ORIGIN]: 'auto.function.serverless.gcp_event',\n [GCP_FUNCTION_CONTEXT_EVENT_TYPE]: context.eventType,\n [GCP_FUNCTION_CONTEXT_EVENT_ID]: context.eventId,\n [GCP_FUNCTION_CONTEXT_RESOURCE]: context.resource,\n [GCP_FUNCTION_CONTEXT_TIMESTAMP]: context.timestamp,\n },\n },\n span => {\n const scope = getCurrentScope();\n scope.setContext('gcp.function.context', { ...context });\n\n const newCallback = domainify((...args: unknown[]) => {\n if (args[0] !== null && args[0] !== undefined) {\n captureException(args[0], scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_event'));\n }\n span.end();\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n flush(options.flushTimeout)\n .then(null, e => {\n DEBUG_BUILD && debug.error(e);\n })\n .then(() => {\n if (typeof callback === 'function') {\n callback(...args);\n }\n });\n });\n\n if (fn.length > 2) {\n return handleCallbackErrors(\n () => (fn as EventFunctionWithCallback)(data, context, newCallback),\n err => {\n captureException(err, scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_event'));\n },\n );\n }\n\n return Promise.resolve()\n .then(() => (fn as EventFunction)(data, context))\n .then(\n result => newCallback(null, result),\n err => newCallback(err, undefined),\n );\n },\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAiCA,SAAgB,kBACd,IACA,cAAoD,CAAC,GAC1B;CAC3B,OAAOA,cAAAA,cAAc,KAAI,MAAKC,cAAAA,UAAU,mBAAmB,GAAG,WAAW,CAAC,CAAC;AAC7E;;AAGA,SAAS,mBACP,IACA,cAA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AiC,MAAM,SAAS,WAAW,IAClE,QAAO;IACLL,CAAAA,GAAAA,aAAAA,iBAAAA,CAAiB,MAAK,UAASC,cAAAA,mBAAmB,OAAO,oCAAoC,CAAC;GAChG,CACF;GAGF,OAAO,QAAQ,QAAQ,CAAC,CACrB,WAAY,GAAqB,MAAM,OAAO,CAAC,CAAC,CAChD,MACC,WAAU,YAAY,MAAM,MAAM,IAClC,QAAO,YAAY,KAAK,KAAA,CAAS,CACnC;EACJ,CACF;CACF;AACF"}
|
|
@@ -1,72 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const require_debug_build = require("../debug-build.js");
|
|
2
|
+
const require_utils = require("../utils.js");
|
|
3
|
+
let _sentry_node = require("@sentry/node");
|
|
4
|
+
let _sentry_core = require("@sentry/core");
|
|
5
|
+
let _sentry_conventions_attributes = require("@sentry/conventions/attributes");
|
|
6
|
+
let _sentry_conventions_op = require("@sentry/conventions/op");
|
|
7
|
+
// src/gcpfunction/http.ts
|
|
8
|
+
/**
|
|
9
|
+
* Wraps an HTTP function handler adding it error capture and tracing capabilities.
|
|
10
|
+
*
|
|
11
|
+
* @param fn HTTP Handler
|
|
12
|
+
* @param options Options
|
|
13
|
+
* @returns HTTP handler
|
|
14
|
+
*/
|
|
10
15
|
function wrapHttpFunction(fn, wrapOptions = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return utils.proxyFunction(fn, wrap, overrides);
|
|
16
|
+
const wrap = (f) => require_utils.domainify(_wrapHttpFunction(f, wrapOptions));
|
|
17
|
+
let overrides;
|
|
18
|
+
const emulatorFunc = fn.__emulator_func;
|
|
19
|
+
if (emulatorFunc) overrides = { __emulator_func: require_utils.proxyFunction(emulatorFunc, wrap) };
|
|
20
|
+
return require_utils.proxyFunction(fn, wrap, overrides);
|
|
18
21
|
}
|
|
22
|
+
/** */
|
|
19
23
|
function _wrapHttpFunction(fn, options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
};
|
|
24
|
+
const flushTimeout = options.flushTimeout || 2e3;
|
|
25
|
+
return (req, res) => {
|
|
26
|
+
const reqMethod = (req.method || "").toUpperCase();
|
|
27
|
+
const reqUrl = (0, _sentry_core.stripUrlQueryAndFragment)(req.originalUrl || req.url || "");
|
|
28
|
+
const sentryTrace = req.headers && (0, _sentry_core.isString)(req.headers["sentry-trace"]) ? req.headers["sentry-trace"] : void 0;
|
|
29
|
+
const baggage = req.headers?.baggage;
|
|
30
|
+
return (0, _sentry_node.continueTrace)({
|
|
31
|
+
sentryTrace,
|
|
32
|
+
baggage
|
|
33
|
+
}, () => {
|
|
34
|
+
const normalizedRequest = (0, _sentry_core.httpRequestToRequestData)(req);
|
|
35
|
+
(0, _sentry_node.getCurrentScope)().setSDKProcessingMetadata({ normalizedRequest });
|
|
36
|
+
const functionName = require_utils.getFunctionName();
|
|
37
|
+
const client = (0, _sentry_core.getClient)();
|
|
38
|
+
const hasSpanStreaming = client && (0, _sentry_core.hasSpanStreamingEnabled)(client);
|
|
39
|
+
const name = hasSpanStreaming ? functionName || _sentry_core.SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : `${reqMethod} ${reqUrl}`;
|
|
40
|
+
return (0, _sentry_node.startSpanManual)({
|
|
41
|
+
name,
|
|
42
|
+
attributes: {
|
|
43
|
+
[_sentry_conventions_attributes.SENTRY_OP]: _sentry_conventions_op.FUNCTION_GCP,
|
|
44
|
+
[_sentry_conventions_attributes.FAAS_NAME]: functionName,
|
|
45
|
+
[_sentry_conventions_attributes.FAAS_TRIGGER]: "http",
|
|
46
|
+
[_sentry_conventions_attributes.SENTRY_SEGMENT_NAME_SOURCE]: hasSpanStreaming ? "component" : "route",
|
|
47
|
+
[_sentry_conventions_attributes.SENTRY_ORIGIN]: "auto.function.serverless.gcp_http",
|
|
48
|
+
[_sentry_conventions_attributes.HTTP_REQUEST_METHOD]: reqMethod || void 0,
|
|
49
|
+
[_sentry_conventions_attributes.URL_PATH]: reqUrl || void 0
|
|
50
|
+
}
|
|
51
|
+
}, (span) => {
|
|
52
|
+
const _end = res.end;
|
|
53
|
+
res.end = function(chunk, encoding, cb) {
|
|
54
|
+
(0, _sentry_core.setHttpStatus)(span, res.statusCode);
|
|
55
|
+
span.end();
|
|
56
|
+
(0, _sentry_node.flush)(flushTimeout).then(null, (e) => {
|
|
57
|
+
require_debug_build.DEBUG_BUILD && _sentry_core.debug.error(e);
|
|
58
|
+
}).then(() => {
|
|
59
|
+
_end.call(this, chunk, encoding, cb);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return (0, _sentry_core.handleCallbackErrors)(() => fn(req, res), (err) => {
|
|
63
|
+
(0, _sentry_node.captureException)(err, (scope) => require_utils.markEventUnhandled(scope, "auto.function.serverless.gcp_http"));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
69
68
|
}
|
|
70
|
-
|
|
71
69
|
exports.wrapHttpFunction = wrapHttpFunction;
|
|
72
|
-
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sources":["../../../src/gcpfunction/http.ts"],"sourcesContent":["import {\n SENTRY_SEGMENT_NAME_SOURCE,\n FAAS_NAME,\n FAAS_TRIGGER,\n HTTP_REQUEST_METHOD,\n SENTRY_OP,\n URL_PATH,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION_GCP } from '@sentry/conventions/op';\nimport {\n debug,\n getClient,\n handleCallbackErrors,\n hasSpanStreamingEnabled,\n httpRequestToRequestData,\n isString,\n SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK,\n setHttpStatus,\n stripUrlQueryAndFragment,\n} from '@sentry/core';\nimport { captureException, continueTrace, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, getFunctionName, markEventUnhandled, proxyFunction } from '../utils';\nimport type { HttpFunction, WrapperOptions } from './general';\n\n/**\n * Wraps an HTTP function handler adding it error capture and tracing capabilities.\n *\n * @param fn HTTP Handler\n * @param options Options\n * @returns HTTP handler\n */\nexport function wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<WrapperOptions> = {}): HttpFunction {\n const wrap = (f: HttpFunction): HttpFunction => domainify(_wrapHttpFunction(f, wrapOptions));\n\n let overrides: Record<PropertyKey, unknown> | undefined;\n\n // Functions emulator from firebase-tools has a hack-ish workaround that saves the actual function\n // passed to `onRequest(...)` and in fact runs it so we need to wrap it too.\n const emulatorFunc = (fn as HttpFunction & { __emulator_func?: HttpFunction }).__emulator_func;\n if (emulatorFunc) {\n overrides = { __emulator_func: proxyFunction(emulatorFunc, wrap) };\n }\n return proxyFunction(fn, wrap, overrides);\n}\n\n/** */\nfunction _wrapHttpFunction(fn: HttpFunction, options: Partial<WrapperOptions>): HttpFunction {\n const flushTimeout = options.flushTimeout || 2000;\n return (req, res) => {\n const reqMethod = (req.method || '').toUpperCase();\n const reqUrl = stripUrlQueryAndFragment(req.originalUrl || req.url || '');\n\n const sentryTrace = req.headers && isString(req.headers['sentry-trace']) ? req.headers['sentry-trace'] : undefined;\n const baggage = req.headers?.baggage;\n\n return continueTrace({ sentryTrace, baggage }, () => {\n const normalizedRequest = httpRequestToRequestData(req);\n getCurrentScope().setSDKProcessingMetadata({ normalizedRequest });\n\n const functionName = getFunctionName();\n\n const client = getClient();\n const hasSpanStreaming = client && hasSpanStreamingEnabled(client);\n const name = hasSpanStreaming ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : `${reqMethod} ${reqUrl}`;\n\n return startSpanManual(\n {\n name,\n attributes: {\n [SENTRY_OP]: FUNCTION_GCP,\n [FAAS_NAME]: functionName,\n [FAAS_TRIGGER]: 'http',\n [SENTRY_SEGMENT_NAME_SOURCE]: hasSpanStreaming ? 'component' : 'route',\n [SENTRY_ORIGIN]: 'auto.function.serverless.gcp_http',\n // The method and path used to be the span name; they stay on the span so that\n // information survives the low-cardinality rename.\n [HTTP_REQUEST_METHOD]: reqMethod || undefined,\n [URL_PATH]: reqUrl || undefined,\n },\n },\n span => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const _end = res.end;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n res.end = function (chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): any {\n setHttpStatus(span, res.statusCode);\n span.end();\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n flush(flushTimeout)\n .then(null, e => {\n DEBUG_BUILD && debug.error(e);\n })\n .then(() => {\n _end.call(this, chunk, encoding, cb);\n });\n };\n\n return handleCallbackErrors(\n () => fn(req, res),\n err => {\n captureException(err, scope => markEventUnhandled(scope, 'auto.function.serverless.gcp_http'));\n },\n );\n },\n );\n });\n };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"http.js","names":["domainify","proxyFunction","stripUrlQueryAndFragment","isString","continueTrace","httpRequestToRequestData","getCurrentScope","getFunctionName","getClient","hasSpanStreamingEnabled","SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK","startSpanManual","SENTRY_OP","FUNCTION_GCP","FAAS_NAME","FAAS_TRIGGER","SENTRY_SEGMENT_NAME_SOURCE","SENTRY_ORIGIN","HTTP_REQUEST_METHOD","URL_PATH","setHttpStatus","flush","DEBUG_BUILD","debug","handleCallbackErrors","captureException","markEventUnhandled"],"sources":["../../../src/gcpfunction/http.ts"],"sourcesContent":["import {\n SENTRY_SEGMENT_NAME_SOURCE,\n FAAS_NAME,\n FAAS_TRIGGER,\n HTTP_REQUEST_METHOD,\n SENTRY_OP,\n URL_PATH,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION_GCP } from '@sentry/conventions/op';\nimport {\n debug,\n getClient,\n handleCallbackErrors,\n hasSpanStreamingEnabled,\n httpRequestToRequestData,\n isString,\n SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK,\n setHttpStatus,\n stripUrlQueryAndFragment,\n} from '@sentry/core';\nimport { captureException, continueTrace, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, getFunctionName, markEventUnhandled, proxyFunction } from '../utils';\nimport type { HttpFunction, WrapperOptions } from './general';\n\n/**\n * Wraps an HTTP function handler adding it error capture and tracing capabilities.\n *\n * @param fn HTTP Handler\n * @param options Options\n * @returns HTTP handler\n */\nexport function wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<WrapperOptions> = {}): HttpFunction {\n const wrap = (f: HttpFunction): HttpFunction => domainify(_wrapHttpFunction(f, wrapOptions));\n\n let overrides: Record<PropertyKey, unknown> | undefined;\n\n // Functions emulator from firebase-tools has a hack-ish workaround that saves the actual function\n // passed to `onRequest(...)` and in fact runs it so we need to wrap it too.\n const emulatorFunc = (fn as HttpFunction & { __emulator_func?: HttpFunction }).__emulator_func;\n if (emulatorFunc) {\n overrides = { __emulator_func: proxyFunction(emulatorFunc, wrap) };\n }\n return proxyFunction(fn, wrap, overrides);\n}\n\n/** */\nfunction _wrapHttpFunction(fn: HttpFunction, options: Partial<WrapperOptions>): HttpFunction {\n const flushTimeout = options.flushTimeout || 2000;\n return (req, res) => {\n const reqMethod = (req.method || '').toUpperCase();\n const reqUrl = stripUrlQueryAndFragment(req.originalUrl || req.url || '');\n\n const sentryTrace = req.headers && isString(req.headers['sentry-trace']) ? req.headers['sentry-trace'] : undefined;\n const baggage = req.headers?.baggage;\n\n return continueTrace({ sentryTrace, baggage }, () => {\n const normalizedRequest = httpRequestToRequestData(req);\n getCurrentScope().setSDKProcessingMetadata({ normalizedRequest });\n\n const functionName = getFunctionName();\n\n const client = getClient();\n const hasSpanStreaming = client && hasSpanStreamingEnabled(client);\n const name = hasSpanStreaming ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : `${reqMethod} ${reqUrl}`;\n\n return startSpanManual(\n {\n name,\n attributes: {\n [SENTRY_OP]: FUNCTION_GCP,\n [FAAS_NAME]: functionName,\n [FAAS_TRIGGER]: 'http',\n [SENTRY_SEGMENT_NAME_SOURCE]: hasSpanStreaming ? 'component' : 'route',\n [SENTRY_ORIGIN]: 'auto.function.serverless.gcp_http',\n // The method and path used to be the span name; they stay on the span so that\n // information survives the low-cardinality rename.\n [HTTP_REQUEST_METHOD]: reqMethod || undefined,\n [URL_PATH]: reqUrl || undefined,\n },\n },\n span => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const _end = res.end;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n res.end = function (chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): any {\n setHttpStatus(span, res.statusCode);\n span.end();\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n flush(flushTimeout)\n .then(null, e => {\n DEBUG_BUILD && debug.error(e);\n })\n .then(() => {\n _end.call(this, chunk, encoding, cb);\n });\n };\n\n return handleCallbackErrors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