@sentry/google-cloud-serverless 11.12.0 → 11.14.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
|
@@ -1,70 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { DEBUG_BUILD } from "../debug-build.js";
|
|
2
|
+
import { domainify, getFunctionName, markEventUnhandled, proxyFunction } from "../utils.js";
|
|
3
|
+
import { captureException, flush, getCurrentScope, startSpanManual } from "@sentry/node";
|
|
4
|
+
import { SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK, debug, getClient, handleCallbackErrors, hasSpanStreamingEnabled } from "@sentry/core";
|
|
5
|
+
import { FAAS_NAME, FAAS_TRIGGER, GCP_FUNCTION_CONTEXT_ID, GCP_FUNCTION_CONTEXT_SOURCE, GCP_FUNCTION_CONTEXT_SPECVERSION, GCP_FUNCTION_CONTEXT_TIME, GCP_FUNCTION_CONTEXT_TYPE, SENTRY_OP, SENTRY_ORIGIN, SENTRY_SEGMENT_NAME_SOURCE } from "@sentry/conventions/attributes";
|
|
6
|
+
import { FUNCTION_GCP } from "@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
|
+
*/
|
|
8
15
|
function wrapCloudEventFunction(fn, wrapOptions = {}) {
|
|
9
|
-
|
|
16
|
+
return proxyFunction(fn, (f) => domainify(_wrapCloudEventFunction(f, wrapOptions)));
|
|
10
17
|
}
|
|
11
18
|
function _wrapCloudEventFunction(fn, wrapOptions = {}) {
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
if (fn.length > 1) {
|
|
53
|
-
return handleCallbackErrors(
|
|
54
|
-
() => fn(context, newCallback),
|
|
55
|
-
(err) => {
|
|
56
|
-
captureException(err, (scope2) => markEventUnhandled(scope2, "auto.function.serverless.gcp_cloud_event"));
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
return Promise.resolve().then(() => fn(context)).then(
|
|
61
|
-
(result) => newCallback(null, result),
|
|
62
|
-
(err) => newCallback(err, void 0)
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
};
|
|
19
|
+
const options = {
|
|
20
|
+
flushTimeout: 2e3,
|
|
21
|
+
...wrapOptions
|
|
22
|
+
};
|
|
23
|
+
return (context, callback) => {
|
|
24
|
+
const client = getClient();
|
|
25
|
+
const functionName = getFunctionName();
|
|
26
|
+
const name = client && hasSpanStreamingEnabled(client) ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : context.type || "<unknown>";
|
|
27
|
+
return startSpanManual({
|
|
28
|
+
name,
|
|
29
|
+
attributes: {
|
|
30
|
+
[SENTRY_OP]: FUNCTION_GCP,
|
|
31
|
+
[FAAS_NAME]: functionName,
|
|
32
|
+
[FAAS_TRIGGER]: "cloud_event",
|
|
33
|
+
[SENTRY_SEGMENT_NAME_SOURCE]: "component",
|
|
34
|
+
[SENTRY_ORIGIN]: "auto.function.serverless.gcp_cloud_event",
|
|
35
|
+
[GCP_FUNCTION_CONTEXT_TYPE]: context.type,
|
|
36
|
+
[GCP_FUNCTION_CONTEXT_ID]: context.id,
|
|
37
|
+
[GCP_FUNCTION_CONTEXT_SOURCE]: context.source,
|
|
38
|
+
[GCP_FUNCTION_CONTEXT_SPECVERSION]: context.specversion,
|
|
39
|
+
[GCP_FUNCTION_CONTEXT_TIME]: context.time
|
|
40
|
+
}
|
|
41
|
+
}, (span) => {
|
|
42
|
+
getCurrentScope().setContext("gcp.function.context", { ...context });
|
|
43
|
+
const newCallback = domainify((...args) => {
|
|
44
|
+
if (args[0] !== null && args[0] !== void 0) captureException(args[0], (scope) => markEventUnhandled(scope, "auto.function.serverless.gcp_cloud_event"));
|
|
45
|
+
span.end();
|
|
46
|
+
flush(options.flushTimeout).then(null, (e) => {
|
|
47
|
+
DEBUG_BUILD && debug.error(e);
|
|
48
|
+
}).then(() => {
|
|
49
|
+
if (typeof callback === "function") callback(...args);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
if (fn.length > 1) return handleCallbackErrors(() => fn(context, newCallback), (err) => {
|
|
53
|
+
captureException(err, (scope) => 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
|
+
};
|
|
67
58
|
}
|
|
68
|
-
|
|
69
59
|
export { wrapCloudEventFunction };
|
|
70
|
-
|
|
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":[],"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,OAAO,cAAc,KAAI,MAAK,UAAU,wBAAwB,GAAG,WAAW,CAAC,CAAC;AAClF;AAEA,SAAS,wBACP,IACA,cAAyD,CAAC,GAC1B;CAChC,MAAM,UAA4C;EAChD,cAAc;EACd,GAAG;CACL;CACA,QAAQ,SAAS,aAAa;EAC5B,MAAM,SAAS,UAAU;EAEzB,MAAM,eAAe,gBAAgB;EACrC,MAAM,OACJ,UAAU,wBAAwB,MAAM,IACpC,gBAAgB,yCAChB,QAAQ,QAAQ;EAEtB,OAAO,gBACL;GACE;GACA,YAAY;KACT,YAAY;KACZ,YAAY;KACZ,eAAe;KACf,6BAA6B;KAC7B,gBAAgB;KAChB,4BAA4B,QAAQ;KACpC,0BAA0B,QAAQ;KAClC,8BAA8B,QAAQ;KACtC,mCAAmC,QAAQ;KAC3C,4BAA4B,QAAQ;GACvC;EACF,IACA,SAAQ;GACQ,gBACV,CAAC,CAAC,WAAW,wBAAwB,EAAE,GAAG,QAAQ,CAAC;GAEvD,MAAM,cAAc,WAAW,GAAG,SAAoB;IACpD,IAAI,KAAK,OAAO,QAAQ,KAAK,OAAO,KAAA,GAClC,iBAAiB,KAAK,KAAI,UAAS,mBAAmB,OAAO,0CAA0C,CAAC;IAE1G,KAAK,IAAI;IAGT,MAAM,QAAQ,YAAY,CAAC,CACxB,KAAK,OAAM,MAAK;KACf,eAAe,MAAM,MAAM,CAAC;IAC9B,CAAC,CAAC,CACD,WAAW;KACV,IAAI,OAAO,aAAa,YACtB,SAAS,GAAG,IAAI;IAEpB,CAAC;GACL,CAAC;GAED,IAAI,GAAG,SAAS,GACd,OAAO,2BACE,GAAsC,SAAS,WAAW,IACjE,QAAO;IACL,iBAAiB,MAAK,UAAS,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,70 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { DEBUG_BUILD } from "../debug-build.js";
|
|
2
|
+
import { domainify, getFunctionName, markEventUnhandled, proxyFunction } from "../utils.js";
|
|
3
|
+
import { captureException, flush, getCurrentScope, startSpanManual } from "@sentry/node";
|
|
4
|
+
import { SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK, debug, getClient, handleCallbackErrors, hasSpanStreamingEnabled } from "@sentry/core";
|
|
5
|
+
import { FAAS_NAME, FAAS_TRIGGER, GCP_FUNCTION_CONTEXT_EVENT_ID, GCP_FUNCTION_CONTEXT_EVENT_TYPE, GCP_FUNCTION_CONTEXT_RESOURCE, GCP_FUNCTION_CONTEXT_TIMESTAMP, SENTRY_OP, SENTRY_ORIGIN, SENTRY_SEGMENT_NAME_SOURCE } from "@sentry/conventions/attributes";
|
|
6
|
+
import { FUNCTION_GCP } from "@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
|
+
*/
|
|
8
15
|
function wrapEventFunction(fn, wrapOptions = {}) {
|
|
9
|
-
|
|
16
|
+
return proxyFunction(fn, (f) => domainify(_wrapEventFunction(f, wrapOptions)));
|
|
10
17
|
}
|
|
18
|
+
/** */
|
|
11
19
|
function _wrapEventFunction(fn, wrapOptions = {}) {
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
if (fn.length > 2) {
|
|
53
|
-
return handleCallbackErrors(
|
|
54
|
-
() => fn(data, context, newCallback),
|
|
55
|
-
(err) => {
|
|
56
|
-
captureException(err, (scope2) => markEventUnhandled(scope2, "auto.function.serverless.gcp_event"));
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
return Promise.resolve().then(() => fn(data, context)).then(
|
|
61
|
-
(result) => newCallback(null, result),
|
|
62
|
-
(err) => newCallback(err, void 0)
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
};
|
|
20
|
+
const options = {
|
|
21
|
+
flushTimeout: 2e3,
|
|
22
|
+
...wrapOptions
|
|
23
|
+
};
|
|
24
|
+
return (...eventFunctionArguments) => {
|
|
25
|
+
const [data, context, callback] = eventFunctionArguments;
|
|
26
|
+
const client = getClient();
|
|
27
|
+
const functionName = getFunctionName();
|
|
28
|
+
const name = client && hasSpanStreamingEnabled(client) ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : context.eventType;
|
|
29
|
+
return startSpanManual({
|
|
30
|
+
name,
|
|
31
|
+
attributes: {
|
|
32
|
+
[SENTRY_OP]: FUNCTION_GCP,
|
|
33
|
+
[FAAS_NAME]: functionName,
|
|
34
|
+
[FAAS_TRIGGER]: "event",
|
|
35
|
+
[SENTRY_SEGMENT_NAME_SOURCE]: "component",
|
|
36
|
+
[SENTRY_ORIGIN]: "auto.function.serverless.gcp_event",
|
|
37
|
+
[GCP_FUNCTION_CONTEXT_EVENT_TYPE]: context.eventType,
|
|
38
|
+
[GCP_FUNCTION_CONTEXT_EVENT_ID]: context.eventId,
|
|
39
|
+
[GCP_FUNCTION_CONTEXT_RESOURCE]: context.resource,
|
|
40
|
+
[GCP_FUNCTION_CONTEXT_TIMESTAMP]: context.timestamp
|
|
41
|
+
}
|
|
42
|
+
}, (span) => {
|
|
43
|
+
getCurrentScope().setContext("gcp.function.context", { ...context });
|
|
44
|
+
const newCallback = domainify((...args) => {
|
|
45
|
+
if (args[0] !== null && args[0] !== void 0) captureException(args[0], (scope) => markEventUnhandled(scope, "auto.function.serverless.gcp_event"));
|
|
46
|
+
span.end();
|
|
47
|
+
flush(options.flushTimeout).then(null, (e) => {
|
|
48
|
+
DEBUG_BUILD && debug.error(e);
|
|
49
|
+
}).then(() => {
|
|
50
|
+
if (typeof callback === "function") callback(...args);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
if (fn.length > 2) return handleCallbackErrors(() => fn(data, context, newCallback), (err) => {
|
|
54
|
+
captureException(err, (scope) => 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
|
+
};
|
|
67
59
|
}
|
|
68
|
-
|
|
69
60
|
export { wrapEventFunction };
|
|
70
|
-
|
|
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":[],"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,OAAO,cAAc,KAAI,MAAK,UAAU,mBAAmB,GAAG,WAAW,CAAC,CAAC;AAC7E;;AAGA,SAAS,mBACP,IACA,cAAoD,CAAC,GACM;CAC3D,MAAM,UAAuC;EAC3C,cAAc;EACd,GAAG;CACL;CACA,QAAQ,GAAG,2BAAyE;EAClF,MAAM,CAAC,MAAM,SAAS,YAAY;EAElC,MAAM,SAAS,UAAU;EAEzB,MAAM,eAAe,gBAAgB;EACrC,MAAM,OACJ,UAAU,wBAAwB,MAAM,IACpC,gBAAgB,yCAChB,QAAQ;EAEd,OAAO,gBACL;GACE;GACA,YAAY;KACT,YAAY;KACZ,YAAY;KACZ,eAAe;KACf,6BAA6B;KAC7B,gBAAgB;KAChB,kCAAkC,QAAQ;KAC1C,gCAAgC,QAAQ;KACxC,gCAAgC,QAAQ;KACxC,iCAAiC,QAAQ;GAC5C;EACF,IACA,SAAQ;GACQ,gBACV,CAAC,CAAC,WAAW,wBAAwB,EAAE,GAAG,QAAQ,CAAC;GAEvD,MAAM,cAAc,WAAW,GAAG,SAAoB;IACpD,IAAI,KAAK,OAAO,QAAQ,KAAK,OAAO,KAAA,GAClC,iBAAiB,KAAK,KAAI,UAAS,mBAAmB,OAAO,oCAAoC,CAAC;IAEpG,KAAK,IAAI;IAGT,MAAM,QAAQ,YAAY,CAAC,CACxB,KAAK,OAAM,MAAK;KACf,eAAe,MAAM,MAAM,CAAC;IAC9B,CAAC,CAAC,CACD,WAAW;KACV,IAAI,OAAO,aAAa,YACtB,SAAS,GAAG,IAAI;IAEpB,CAAC;GACL,CAAC;GAED,IAAI,GAAG,SAAS,GACd,OAAO,2BACE,GAAiC,MAAM,SAAS,WAAW,IAClE,QAAO;IACL,iBAAiB,MAAK,UAAS,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,70 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { DEBUG_BUILD } from "../debug-build.js";
|
|
2
|
+
import { domainify, getFunctionName, markEventUnhandled, proxyFunction } from "../utils.js";
|
|
3
|
+
import { captureException, continueTrace, flush, getCurrentScope, startSpanManual } from "@sentry/node";
|
|
4
|
+
import { SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK, debug, getClient, handleCallbackErrors, hasSpanStreamingEnabled, httpRequestToRequestData, isString, setHttpStatus, stripUrlQueryAndFragment } from "@sentry/core";
|
|
5
|
+
import { FAAS_NAME, FAAS_TRIGGER, HTTP_REQUEST_METHOD, SENTRY_OP, SENTRY_ORIGIN, SENTRY_SEGMENT_NAME_SOURCE, URL_PATH } from "@sentry/conventions/attributes";
|
|
6
|
+
import { FUNCTION_GCP } from "@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
|
+
*/
|
|
8
15
|
function wrapHttpFunction(fn, wrapOptions = {}) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return proxyFunction(fn, wrap, overrides);
|
|
16
|
+
const wrap = (f) => domainify(_wrapHttpFunction(f, wrapOptions));
|
|
17
|
+
let overrides;
|
|
18
|
+
const emulatorFunc = fn.__emulator_func;
|
|
19
|
+
if (emulatorFunc) overrides = { __emulator_func: proxyFunction(emulatorFunc, wrap) };
|
|
20
|
+
return proxyFunction(fn, wrap, overrides);
|
|
16
21
|
}
|
|
22
|
+
/** */
|
|
17
23
|
function _wrapHttpFunction(fn, options) {
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
};
|
|
24
|
+
const flushTimeout = options.flushTimeout || 2e3;
|
|
25
|
+
return (req, res) => {
|
|
26
|
+
const reqMethod = (req.method || "").toUpperCase();
|
|
27
|
+
const reqUrl = stripUrlQueryAndFragment(req.originalUrl || req.url || "");
|
|
28
|
+
const sentryTrace = req.headers && isString(req.headers["sentry-trace"]) ? req.headers["sentry-trace"] : void 0;
|
|
29
|
+
const baggage = req.headers?.baggage;
|
|
30
|
+
return continueTrace({
|
|
31
|
+
sentryTrace,
|
|
32
|
+
baggage
|
|
33
|
+
}, () => {
|
|
34
|
+
const normalizedRequest = httpRequestToRequestData(req);
|
|
35
|
+
getCurrentScope().setSDKProcessingMetadata({ normalizedRequest });
|
|
36
|
+
const functionName = getFunctionName();
|
|
37
|
+
const client = getClient();
|
|
38
|
+
const hasSpanStreaming = client && hasSpanStreamingEnabled(client);
|
|
39
|
+
const name = hasSpanStreaming ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : `${reqMethod} ${reqUrl}`;
|
|
40
|
+
return startSpanManual({
|
|
41
|
+
name,
|
|
42
|
+
attributes: {
|
|
43
|
+
[SENTRY_OP]: FUNCTION_GCP,
|
|
44
|
+
[FAAS_NAME]: functionName,
|
|
45
|
+
[FAAS_TRIGGER]: "http",
|
|
46
|
+
[SENTRY_SEGMENT_NAME_SOURCE]: hasSpanStreaming ? "component" : "route",
|
|
47
|
+
[SENTRY_ORIGIN]: "auto.function.serverless.gcp_http",
|
|
48
|
+
[HTTP_REQUEST_METHOD]: reqMethod || void 0,
|
|
49
|
+
[URL_PATH]: reqUrl || void 0
|
|
50
|
+
}
|
|
51
|
+
}, (span) => {
|
|
52
|
+
const _end = res.end;
|
|
53
|
+
res.end = function(chunk, encoding, cb) {
|
|
54
|
+
setHttpStatus(span, res.statusCode);
|
|
55
|
+
span.end();
|
|
56
|
+
flush(flushTimeout).then(null, (e) => {
|
|
57
|
+
DEBUG_BUILD && debug.error(e);
|
|
58
|
+
}).then(() => {
|
|
59
|
+
_end.call(this, chunk, encoding, cb);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return handleCallbackErrors(() => fn(req, res), (err) => {
|
|
63
|
+
captureException(err, (scope) => markEventUnhandled(scope, "auto.function.serverless.gcp_http"));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
67
68
|
}
|
|
68
|
-
|
|
69
69
|
export { wrapHttpFunction };
|
|
70
|
-
|
|
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":[],"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"],"mappings":";;;;;;;;;;;;;;AAiCA,SAAgB,iBAAiB,IAAkB,cAAuC,CAAC,GAAiB;CAC1G,MAAM,QAAQ,MAAkC,UAAU,kBAAkB,GAAG,WAAW,CAAC;CAE3F,IAAI;CAIJ,MAAM,eAAgB,GAAyD;CAC/E,IAAI,cACF,YAAY,EAAE,iBAAiB,cAAc,cAAc,IAAI,EAAE;CAEnE,OAAO,cAAc,IAAI,MAAM,SAAS;AAC1C;;AAGA,SAAS,kBAAkB,IAAkB,SAAgD;CAC3F,MAAM,eAAe,QAAQ,gBAAgB;CAC7C,QAAQ,KAAK,QAAQ;EACnB,MAAM,aAAa,IAAI,UAAU,GAAA,CAAI,YAAY;EACjD,MAAM,SAAS,yBAAyB,IAAI,eAAe,IAAI,OAAO,EAAE;EAExE,MAAM,cAAc,IAAI,WAAW,SAAS,IAAI,QAAQ,eAAe,IAAI,IAAI,QAAQ,kBAAkB,KAAA;EACzG,MAAM,UAAU,IAAI,SAAS;EAE7B,OAAO,cAAc;GAAE;GAAa;EAAQ,SAAS;GACnD,MAAM,oBAAoB,yBAAyB,GAAG;GACtD,gBAAgB,CAAC,CAAC,yBAAyB,EAAE,kBAAkB,CAAC;GAEhE,MAAM,eAAe,gBAAgB;GAErC,MAAM,SAAS,UAAU;GACzB,MAAM,mBAAmB,UAAU,wBAAwB,MAAM;GACjE,MAAM,OAAO,mBAAmB,gBAAgB,yCAAyC,GAAG,UAAU,GAAG;GAEzG,OAAO,gBACL;IACE;IACA,YAAY;MACT,YAAY;MACZ,YAAY;MACZ,eAAe;MACf,6BAA6B,mBAAmB,cAAc;MAC9D,gBAAgB;MAGhB,sBAAsB,aAAa,KAAA;MACnC,WAAW,UAAU,KAAA;IACxB;GACF,IACA,SAAQ;IAEN,MAAM,OAAO,IAAI;IAEjB,IAAI,MAAM,SAAU,OAA4B,UAAkC,IAAsB;KACtG,cAAc,MAAM,IAAI,UAAU;KAClC,KAAK,IAAI;KAGT,MAAM,YAAY,CAAC,CAChB,KAAK,OAAM,MAAK;MACf,eAAe,MAAM,MAAM,CAAC;KAC9B,CAAC,CAAC,CACD,WAAW;MACV,KAAK,KAAK,MAAM,OAAO,UAAU,EAAE;KACrC,CAAC;IACL;IAEA,OAAO,2BACC,GAAG,KAAK,GAAG,IACjB,QAAO;KACL,iBAAiB,MAAK,UAAS,mBAAmB,OAAO,mCAAmC,CAAC;IAC/F,CACF;GACF,CACF;EACF,CAAC;CACH;AACF"}
|
package/build/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { getDefaultIntegrations, init } from "./sdk.js";
|
|
2
|
+
import { googleCloudHttpIntegration } from "./integrations/google-cloud-http.js";
|
|
3
|
+
import { googleCloudGrpcIntegration } from "./integrations/google-cloud-grpc.js";
|
|
4
|
+
import { wrapCloudEventFunction } from "./gcpfunction/cloud_events.js";
|
|
5
|
+
import { wrapHttpFunction } from "./gcpfunction/http.js";
|
|
6
|
+
import { wrapEventFunction } from "./gcpfunction/events.js";
|
|
7
|
+
import { BullMQTelemetry, NODE_VERSION, NodeClient, OpenFeatureIntegrationHook, SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, Scope, SentryMastraExporter, addBreadcrumb, addEventProcessor, addIntegration, amqplibIntegration, anrIntegration, anthropicAIIntegration, awsIntegration, awsLambdaWebIntegration, bindScopeToEmitter, buildLaunchDarklyFlagUsedHandler, captureCheckIn, captureEvent, captureException, captureFeedback, captureMessage, captureSession, childProcessIntegration, close, consoleIntegration, consoleLoggingIntegration, contextLinesIntegration, continueTrace, createConsolaReporter, createFlueInstrumentation, createGetModuleFromFilename, createLangChainCallbackHandler, createSentryWinstonTransport, createTransport, cron, cronJobIntegration, dataloaderIntegration, defaultStackParser, disableAnrDetectionForCallback, endSession, eveConversationHook, eveInstrumentation, eveIntegration, eventFiltersIntegration, expressErrorHandler, expressIntegration, fastifyIntegration, featureFlagsIntegration, firebaseIntegration, flush, fsIntegration, functionToStringIntegration, genericPoolIntegration, getActiveSpan, getAutoPerformanceIntegrations, getClient, getCurrentScope, getGlobalScope, getInstrumentedModuleNames, getIsolationScope, getOtlpTracesEndpoint, getRootSpan, getSentryRelease, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, getTraceMetaTags, getTunnelPath, googleGenAIIntegration, graphqlIntegration, groqIntegration, growthbookIntegration, handleTunnelRequest, handleTunnelRequestIfMatched, hapiIntegration, honoIntegration, honoMiddleware, httpHeadersToSpanAttributes, httpIntegration, httpServerIntegration, httpServerSpansIntegration, initOpenTelemetry, instrumentAnthropicAiClient, instrumentCreateReactAgent, instrumentGoogleGenAIClient, instrumentLangChainEmbeddings, instrumentMistralAiClient, instrumentOpenAiClient, instrumentPostgresJsSql, instrumentStateGraph, instrumentStateGraphCompile, instrumentSupabaseClient, instrumentTypeSafeClient, isEnabled, isInitialized, isTunnelRequest, kafkaIntegration, knexIntegration, koaIntegration, langChainIntegration, langGraphIntegration, lastEventId, launchDarklyIntegration, linkedErrorsIntegration, localVariablesIntegration, logger, lruMemoizerIntegration, makeNodeTransport, mastraIntegration, mcpServerIntegration, metrics, mistralAIIntegration, moduleMetadataIntegration, modulesIntegration, mongoIntegration, mongooseIntegration, mysql2Integration, mysqlIntegration, nativeNodeFetchIntegration, neonIntegration, nitroIntegration, nodeContextIntegration, nodeCronIntegration, nodeRuntimeMetricsIntegration, nodeScheduleIntegration, onUncaughtExceptionIntegration, onUnhandledRejectionIntegration, openAIIntegration, openFeatureIntegration, openTelemetryIntegration, parameterize, piAiIntegration, piDurableIntegration, pinoIntegration, postgresIntegration, postgresJsIntegration, prismaIntegration, processSessionIntegration, profiler, redisIntegration, requestDataIntegration, serveTunnelIntegration, setAttribute, setAttributes, setContext, setConversationId, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, setupExpressErrorHandler, setupHapiErrorHandler, setupKoaErrorHandler, spanStreamingIntegration, spanToBaggageHeader, spanToJSON, spanToStaticSpanJSON, spanToTraceHeader, spotlightIntegration, startInactiveSpan, startNewTrace, startSession, startSpan, startSpanManual, statsigIntegration, supabaseIntegration, suppressTracing, systemErrorIntegration, tediousIntegration, togetherAIIntegration, trpcMiddleware, typesafeIntegration, unleashIntegration, updateSpanName, vercelAIIntegration, winterCGHeadersToDict, withActiveSpan, withIsolationScope, withMonitor, withScope, withStaticSpan, withStreamedSpan, workerThreadsIntegration, wrapMcpServerWithSentry, zodErrorsIntegration } from "@sentry/node";
|
|
8
|
+
import { captureConsoleIntegration, dedupeIntegration, extraErrorDataIntegration, rewriteFramesIntegration } from "@sentry/core";
|
|
9
|
+
export { BullMQTelemetry, NODE_VERSION, NodeClient, OpenFeatureIntegrationHook, SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, Scope, SentryMastraExporter, addBreadcrumb, addEventProcessor, addIntegration, amqplibIntegration, anrIntegration, anthropicAIIntegration, awsIntegration, awsLambdaWebIntegration, bindScopeToEmitter, buildLaunchDarklyFlagUsedHandler, captureCheckIn, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, captureSession, childProcessIntegration, close, consoleIntegration, consoleLoggingIntegration, contextLinesIntegration, continueTrace, createConsolaReporter, createFlueInstrumentation, createGetModuleFromFilename, createLangChainCallbackHandler, createSentryWinstonTransport, createTransport, cron, cronJobIntegration, dataloaderIntegration, dedupeIntegration, defaultStackParser, disableAnrDetectionForCallback, endSession, eveConversationHook, eveInstrumentation, eveIntegration, eventFiltersIntegration, expressErrorHandler, expressIntegration, extraErrorDataIntegration, fastifyIntegration, featureFlagsIntegration, firebaseIntegration, flush, fsIntegration, functionToStringIntegration, genericPoolIntegration, getActiveSpan, getAutoPerformanceIntegrations, getClient, getCurrentScope, getDefaultIntegrations, getGlobalScope, getInstrumentedModuleNames, getIsolationScope, getOtlpTracesEndpoint, getRootSpan, getSentryRelease, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, getTraceMetaTags, getTunnelPath, googleCloudGrpcIntegration, googleCloudHttpIntegration, googleGenAIIntegration, graphqlIntegration, groqIntegration, growthbookIntegration, handleTunnelRequest, handleTunnelRequestIfMatched, hapiIntegration, honoIntegration, honoMiddleware, httpHeadersToSpanAttributes, httpIntegration, httpServerIntegration, httpServerSpansIntegration, init, initOpenTelemetry, instrumentAnthropicAiClient, instrumentCreateReactAgent, instrumentGoogleGenAIClient, instrumentLangChainEmbeddings, instrumentMistralAiClient, instrumentOpenAiClient, instrumentPostgresJsSql, instrumentStateGraph, instrumentStateGraphCompile, instrumentSupabaseClient, instrumentTypeSafeClient, isEnabled, isInitialized, isTunnelRequest, kafkaIntegration, knexIntegration, koaIntegration, langChainIntegration, langGraphIntegration, lastEventId, launchDarklyIntegration, linkedErrorsIntegration, localVariablesIntegration, logger, lruMemoizerIntegration, makeNodeTransport, mastraIntegration, mcpServerIntegration, metrics, mistralAIIntegration, moduleMetadataIntegration, modulesIntegration, mongoIntegration, mongooseIntegration, mysql2Integration, mysqlIntegration, nativeNodeFetchIntegration, neonIntegration, nitroIntegration, nodeContextIntegration, nodeCronIntegration, nodeRuntimeMetricsIntegration, nodeScheduleIntegration, onUncaughtExceptionIntegration, onUnhandledRejectionIntegration, openAIIntegration, openFeatureIntegration, openTelemetryIntegration, parameterize, piAiIntegration, piDurableIntegration, pinoIntegration, postgresIntegration, postgresJsIntegration, prismaIntegration, processSessionIntegration, profiler, redisIntegration, requestDataIntegration, rewriteFramesIntegration, serveTunnelIntegration, setAttribute, setAttributes, setContext, setConversationId, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, setupExpressErrorHandler, setupHapiErrorHandler, setupKoaErrorHandler, spanStreamingIntegration, spanToBaggageHeader, spanToJSON, spanToStaticSpanJSON, spanToTraceHeader, spotlightIntegration, startInactiveSpan, startNewTrace, startSession, startSpan, startSpanManual, statsigIntegration, supabaseIntegration, suppressTracing, systemErrorIntegration, tediousIntegration, togetherAIIntegration, trpcMiddleware, typesafeIntegration, unleashIntegration, updateSpanName, vercelAIIntegration, winterCGHeadersToDict, withActiveSpan, withIsolationScope, withMonitor, withScope, withStaticSpan, withStreamedSpan, workerThreadsIntegration, wrapCloudEventFunction, wrapEventFunction, wrapHttpFunction, wrapMcpServerWithSentry, zodErrorsIntegration };
|