@sentry/google-cloud-serverless 10.53.0 → 10.54.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 +0 -5
- package/build/cjs/debug-build.js.map +1 -1
- package/build/cjs/gcpfunction/cloud_events.js +30 -53
- package/build/cjs/gcpfunction/cloud_events.js.map +1 -1
- package/build/cjs/gcpfunction/events.js +29 -54
- package/build/cjs/gcpfunction/events.js.map +1 -1
- package/build/cjs/gcpfunction/http.js +20 -43
- package/build/cjs/gcpfunction/http.js.map +1 -1
- package/build/cjs/integrations/gcp-context.js +38 -0
- package/build/cjs/integrations/gcp-context.js.map +1 -0
- package/build/cjs/integrations/google-cloud-grpc.js +33 -54
- package/build/cjs/integrations/google-cloud-grpc.js.map +1 -1
- package/build/cjs/integrations/google-cloud-http.js +17 -30
- package/build/cjs/integrations/google-cloud-http.js.map +1 -1
- package/build/cjs/sdk.js +10 -17
- package/build/cjs/sdk.js.map +1 -1
- package/build/cjs/utils.js +5 -28
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/debug-build.js +0 -5
- package/build/esm/debug-build.js.map +1 -1
- package/build/esm/gcpfunction/cloud_events.js +30 -53
- package/build/esm/gcpfunction/cloud_events.js.map +1 -1
- package/build/esm/gcpfunction/events.js +29 -54
- package/build/esm/gcpfunction/events.js.map +1 -1
- package/build/esm/gcpfunction/http.js +20 -43
- package/build/esm/gcpfunction/http.js.map +1 -1
- package/build/esm/integrations/gcp-context.js +36 -0
- package/build/esm/integrations/gcp-context.js.map +1 -0
- package/build/esm/integrations/google-cloud-grpc.js +33 -54
- package/build/esm/integrations/google-cloud-grpc.js.map +1 -1
- package/build/esm/integrations/google-cloud-http.js +17 -30
- package/build/esm/integrations/google-cloud-http.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/sdk.js +10 -17
- package/build/esm/sdk.js.map +1 -1
- package/build/esm/utils.js +5 -28
- package/build/esm/utils.js.map +1 -1
- package/build/types/integrations/gcp-context.d.ts +2 -0
- package/build/types/integrations/gcp-context.d.ts.map +1 -0
- package/build/types/sdk.d.ts.map +1 -1
- package/build/types-ts3.8/integrations/gcp-context.d.ts +2 -0
- package/package.json +4 -4
package/build/cjs/debug-build.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* 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.
|
|
5
|
-
*
|
|
6
|
-
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
|
|
7
|
-
*/
|
|
8
3
|
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
9
4
|
|
|
10
5
|
exports.DEBUG_BUILD = DEBUG_BUILD;
|
|
@@ -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"],"names":[],"mappings":";;
|
|
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"],"names":[],"mappings":";;AAOO,MAAM,WAAA,IAAc,OAAA,gBAAA,KAAA,WAAA,IAAA,gBAAA;;;;"}
|
|
@@ -5,76 +5,53 @@ const node = require('@sentry/node');
|
|
|
5
5
|
const debugBuild = require('../debug-build.js');
|
|
6
6
|
const utils = require('../utils.js');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param fn Event handler
|
|
12
|
-
* @param options Options
|
|
13
|
-
* @returns Event handler
|
|
14
|
-
*/
|
|
15
|
-
function wrapCloudEventFunction(
|
|
16
|
-
fn,
|
|
17
|
-
wrapOptions = {},
|
|
18
|
-
) {
|
|
19
|
-
return utils.proxyFunction(fn, f => utils.domainify(_wrapCloudEventFunction(f, wrapOptions)));
|
|
8
|
+
function wrapCloudEventFunction(fn, wrapOptions = {}) {
|
|
9
|
+
return utils.proxyFunction(fn, (f) => utils.domainify(_wrapCloudEventFunction(f, wrapOptions)));
|
|
20
10
|
}
|
|
21
|
-
|
|
22
|
-
function _wrapCloudEventFunction(
|
|
23
|
-
fn,
|
|
24
|
-
wrapOptions = {},
|
|
25
|
-
) {
|
|
11
|
+
function _wrapCloudEventFunction(fn, wrapOptions = {}) {
|
|
26
12
|
const options = {
|
|
27
|
-
flushTimeout:
|
|
28
|
-
...wrapOptions
|
|
13
|
+
flushTimeout: 2e3,
|
|
14
|
+
...wrapOptions
|
|
29
15
|
};
|
|
30
16
|
return (context, callback) => {
|
|
31
17
|
return node.startSpanManual(
|
|
32
18
|
{
|
|
33
|
-
name: context.type ||
|
|
34
|
-
op:
|
|
19
|
+
name: context.type || "<unknown>",
|
|
20
|
+
op: "function.gcp.cloud_event",
|
|
35
21
|
attributes: {
|
|
36
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]:
|
|
37
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
38
|
-
}
|
|
22
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "component",
|
|
23
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.function.serverless.gcp_cloud_event"
|
|
24
|
+
}
|
|
39
25
|
},
|
|
40
|
-
span => {
|
|
26
|
+
(span) => {
|
|
41
27
|
const scope = node.getCurrentScope();
|
|
42
|
-
scope.setContext(
|
|
43
|
-
|
|
28
|
+
scope.setContext("gcp.function.context", { ...context });
|
|
44
29
|
const newCallback = utils.domainify((...args) => {
|
|
45
|
-
if (args[0] !== null && args[0] !==
|
|
46
|
-
node.captureException(args[0],
|
|
30
|
+
if (args[0] !== null && args[0] !== void 0) {
|
|
31
|
+
node.captureException(args[0], (scope2) => utils.markEventUnhandled(scope2, "auto.function.serverless.gcp_cloud_event"));
|
|
47
32
|
}
|
|
48
33
|
span.end();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (typeof callback === 'function') {
|
|
57
|
-
callback(...args);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
34
|
+
node.flush(options.flushTimeout).then(null, (e) => {
|
|
35
|
+
debugBuild.DEBUG_BUILD && core.debug.error(e);
|
|
36
|
+
}).then(() => {
|
|
37
|
+
if (typeof callback === "function") {
|
|
38
|
+
callback(...args);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
60
41
|
});
|
|
61
|
-
|
|
62
42
|
if (fn.length > 1) {
|
|
63
43
|
return core.handleCallbackErrors(
|
|
64
|
-
() =>
|
|
65
|
-
err => {
|
|
66
|
-
node.captureException(err,
|
|
67
|
-
}
|
|
44
|
+
() => fn(context, newCallback),
|
|
45
|
+
(err) => {
|
|
46
|
+
node.captureException(err, (scope2) => utils.markEventUnhandled(scope2, "auto.function.serverless.gcp_cloud_event"));
|
|
47
|
+
}
|
|
68
48
|
);
|
|
69
49
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
err => newCallback(err, undefined),
|
|
76
|
-
);
|
|
77
|
-
},
|
|
50
|
+
return Promise.resolve().then(() => fn(context)).then(
|
|
51
|
+
(result) => newCallback(null, result),
|
|
52
|
+
(err) => newCallback(err, void 0)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
78
55
|
);
|
|
79
56
|
};
|
|
80
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud_events.js","sources":["../../../src/gcpfunction/cloud_events.ts"],"sourcesContent":["import {\n debug,\n handleCallbackErrors,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, 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 return startSpanManual(\n {\n name: context.type || '<unknown>',\n op: 'function.gcp.cloud_event',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.serverless.gcp_cloud_event',\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"],"names":["proxyFunction","domainify","startSpanManual","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getCurrentScope","captureException","markEventUnhandled","flush","DEBUG_BUILD","debug","handleCallbackErrors"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"cloud_events.js","sources":["../../../src/gcpfunction/cloud_events.ts"],"sourcesContent":["import {\n debug,\n handleCallbackErrors,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, 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 return startSpanManual(\n {\n name: context.type || '<unknown>',\n op: 'function.gcp.cloud_event',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.serverless.gcp_cloud_event',\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"],"names":["proxyFunction","domainify","startSpanManual","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getCurrentScope","captureException","scope","markEventUnhandled","flush","DEBUG_BUILD","debug","handleCallbackErrors"],"mappings":";;;;;;;AAoBO,SAAS,sBAA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ACA,IAAA,CAAK,MAAM;AACV,YAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,cAAA,QAAA,CAAS,GAAG,IAAI,CAAA;AAAA,YAClB;AAAA,UACF,CAAC,CAAA;AAAA,QACL,CAAC,CAAA;AAED,QAAA,IAAI,EAAA,CAAG,SAAS,CAAA,EAAG;AACjB,UAAA,OAAOC,yBAAA;AAAA,YACL,MAAO,EAAA,CAAsC,OAAA,EAAS,WAAW,CAAA;AAAA,YACjE,CAAA,GAAA,KAAO;AACL,cAAAN,qBAAA,CAAiB,KAAK,CAAAC,MAAAA,KAASC,wBAAA,CAAmBD,MAAAA,EAAO,0CAA0C,CAAC,CAAA;AAAA,YACtG;AAAA,WACF;AAAA,QACF;AAEA,QAAA,OAAO,OAAA,CAAQ,SAAQ,CACpB,IAAA,CAAK,MAAO,EAAA,CAA0B,OAAO,CAAC,CAAA,CAC9C,IAAA;AAAA,UACC,CAAA,MAAA,KAAU,WAAA,CAAY,IAAA,EAAM,MAAM,CAAA;AAAA,UAClC,CAAA,GAAA,KAAO,WAAA,CAAY,GAAA,EAAK,MAAS;AAAA,SACnC;AAAA,MACJ;AAAA,KACF;AAAA,EACF,CAAA;AACF;;;;"}
|
|
@@ -5,79 +5,54 @@ const node = require('@sentry/node');
|
|
|
5
5
|
const debugBuild = require('../debug-build.js');
|
|
6
6
|
const utils = require('../utils.js');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param fn Event handler
|
|
12
|
-
* @param options Options
|
|
13
|
-
* @returns Event handler
|
|
14
|
-
*/
|
|
15
|
-
function wrapEventFunction(
|
|
16
|
-
fn,
|
|
17
|
-
wrapOptions = {},
|
|
18
|
-
) {
|
|
19
|
-
return utils.proxyFunction(fn, f => utils.domainify(_wrapEventFunction(f, wrapOptions)));
|
|
8
|
+
function wrapEventFunction(fn, wrapOptions = {}) {
|
|
9
|
+
return utils.proxyFunction(fn, (f) => utils.domainify(_wrapEventFunction(f, wrapOptions)));
|
|
20
10
|
}
|
|
21
|
-
|
|
22
|
-
/** */
|
|
23
|
-
function _wrapEventFunction(
|
|
24
|
-
fn,
|
|
25
|
-
wrapOptions = {},
|
|
26
|
-
) {
|
|
11
|
+
function _wrapEventFunction(fn, wrapOptions = {}) {
|
|
27
12
|
const options = {
|
|
28
|
-
flushTimeout:
|
|
29
|
-
...wrapOptions
|
|
13
|
+
flushTimeout: 2e3,
|
|
14
|
+
...wrapOptions
|
|
30
15
|
};
|
|
31
16
|
return (...eventFunctionArguments) => {
|
|
32
17
|
const [data, context, callback] = eventFunctionArguments;
|
|
33
|
-
|
|
34
18
|
return node.startSpanManual(
|
|
35
19
|
{
|
|
36
20
|
name: context.eventType,
|
|
37
|
-
op:
|
|
21
|
+
op: "function.gcp.event",
|
|
38
22
|
attributes: {
|
|
39
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]:
|
|
40
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
41
|
-
}
|
|
23
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "component",
|
|
24
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.function.serverless.gcp_event"
|
|
25
|
+
}
|
|
42
26
|
},
|
|
43
|
-
span => {
|
|
27
|
+
(span) => {
|
|
44
28
|
const scope = node.getCurrentScope();
|
|
45
|
-
scope.setContext(
|
|
46
|
-
|
|
29
|
+
scope.setContext("gcp.function.context", { ...context });
|
|
47
30
|
const newCallback = utils.domainify((...args) => {
|
|
48
|
-
if (args[0] !== null && args[0] !==
|
|
49
|
-
node.captureException(args[0],
|
|
31
|
+
if (args[0] !== null && args[0] !== void 0) {
|
|
32
|
+
node.captureException(args[0], (scope2) => utils.markEventUnhandled(scope2, "auto.function.serverless.gcp_event"));
|
|
50
33
|
}
|
|
51
34
|
span.end();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (typeof callback === 'function') {
|
|
60
|
-
callback(...args);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
35
|
+
node.flush(options.flushTimeout).then(null, (e) => {
|
|
36
|
+
debugBuild.DEBUG_BUILD && core.debug.error(e);
|
|
37
|
+
}).then(() => {
|
|
38
|
+
if (typeof callback === "function") {
|
|
39
|
+
callback(...args);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
63
42
|
});
|
|
64
|
-
|
|
65
43
|
if (fn.length > 2) {
|
|
66
44
|
return core.handleCallbackErrors(
|
|
67
|
-
() =>
|
|
68
|
-
err => {
|
|
69
|
-
node.captureException(err,
|
|
70
|
-
}
|
|
45
|
+
() => fn(data, context, newCallback),
|
|
46
|
+
(err) => {
|
|
47
|
+
node.captureException(err, (scope2) => utils.markEventUnhandled(scope2, "auto.function.serverless.gcp_event"));
|
|
48
|
+
}
|
|
71
49
|
);
|
|
72
50
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
err => newCallback(err, undefined),
|
|
79
|
-
);
|
|
80
|
-
},
|
|
51
|
+
return Promise.resolve().then(() => fn(data, context)).then(
|
|
52
|
+
(result) => newCallback(null, result),
|
|
53
|
+
(err) => newCallback(err, void 0)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
81
56
|
);
|
|
82
57
|
};
|
|
83
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sources":["../../../src/gcpfunction/events.ts"],"sourcesContent":["import {\n debug,\n handleCallbackErrors,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, 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 return startSpanManual(\n {\n name: context.eventType,\n op: 'function.gcp.event',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.serverless.gcp_event',\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"],"names":["proxyFunction","domainify","startSpanManual","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getCurrentScope","captureException","markEventUnhandled","flush","DEBUG_BUILD","debug","handleCallbackErrors"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"events.js","sources":["../../../src/gcpfunction/events.ts"],"sourcesContent":["import {\n debug,\n handleCallbackErrors,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { domainify, 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 return startSpanManual(\n {\n name: context.eventType,\n op: 'function.gcp.event',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.serverless.gcp_event',\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"],"names":["proxyFunction","domainify","startSpanManual","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getCurrentScope","captureException","scope","markEventUnhandled","flush","DEBUG_BUILD","debug","handleCallbackErrors"],"mappings":";;;;;;;AAoBO,SAAS,iBAAA,CACd,EAAA,EACA,WAAA,GAAoD,EAAC,EAC1B;AAC3B,EAAA,OAAOA,mBAAA,CAAc,IAAI,CAAA,CAAA,KAAKC,eAAA,CAAU,mBAAmB,CAAA,EAAG,WAAW,CAAC,CAAC,CAAA;AAC7E;AAGA,SAAS,kBAAA,CACP,EAAA,EACA,WAAA,GAAoD,EAAC,EACM;AAC3D,EAAA,MAAM,OAAA,GAAuC;AAAA,IAC3C,YAAA,EAAc,GAAA;AAAA,IACd,GAAG;AAAA,GACL;AACA,EAAA,OAAO,IAAI,sBAAA,KAAyE;AAClF,IAAA,MAAM,CAAC,IAAA,EAAM,OAAA,EAAS,QAAQ,CAAA,GAAI,sBAAA;AAElC,IAAA,OAAOC,oBAAA;AAAA,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A,EAAO,oCAAoC,CAAC,CAAA;AAAA,YAChG;AAAA,WACF;AAAA,QACF;AAEA,QAAA,OAAO,OAAA,CAAQ,SAAQ,CACpB,IAAA,CAAK,MAAO,EAAA,CAAqB,IAAA,EAAM,OAAO,CAAC,CAAA,CAC/C,IAAA;AAAA,UACC,CAAA,MAAA,KAAU,WAAA,CAAY,IAAA,EAAM,MAAM,CAAA;AAAA,UAClC,CAAA,GAAA,KAAO,WAAA,CAAY,GAAA,EAAK,MAAS;AAAA,SACnC;AAAA,MACJ;AAAA,KACF;AAAA,EACF,CAAA;AACF;;;;"}
|
|
@@ -5,75 +5,52 @@ const node = require('@sentry/node');
|
|
|
5
5
|
const debugBuild = require('../debug-build.js');
|
|
6
6
|
const utils = require('../utils.js');
|
|
7
7
|
|
|
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
|
-
*/
|
|
15
8
|
function wrapHttpFunction(fn, wrapOptions = {}) {
|
|
16
9
|
const wrap = (f) => utils.domainify(_wrapHttpFunction(f, wrapOptions));
|
|
17
|
-
|
|
18
10
|
let overrides;
|
|
19
|
-
|
|
20
|
-
// Functions emulator from firebase-tools has a hack-ish workaround that saves the actual function
|
|
21
|
-
// passed to `onRequest(...)` and in fact runs it so we need to wrap it too.
|
|
22
|
-
const emulatorFunc = (fn ).__emulator_func;
|
|
11
|
+
const emulatorFunc = fn.__emulator_func;
|
|
23
12
|
if (emulatorFunc) {
|
|
24
13
|
overrides = { __emulator_func: utils.proxyFunction(emulatorFunc, wrap) };
|
|
25
14
|
}
|
|
26
15
|
return utils.proxyFunction(fn, wrap, overrides);
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
/** */
|
|
30
17
|
function _wrapHttpFunction(fn, options) {
|
|
31
|
-
const flushTimeout = options.flushTimeout ||
|
|
18
|
+
const flushTimeout = options.flushTimeout || 2e3;
|
|
32
19
|
return (req, res) => {
|
|
33
|
-
const reqMethod = (req.method ||
|
|
34
|
-
const reqUrl = core.stripUrlQueryAndFragment(req.originalUrl || req.url ||
|
|
35
|
-
|
|
36
|
-
const sentryTrace = req.headers && core.isString(req.headers['sentry-trace']) ? req.headers['sentry-trace'] : undefined;
|
|
20
|
+
const reqMethod = (req.method || "").toUpperCase();
|
|
21
|
+
const reqUrl = core.stripUrlQueryAndFragment(req.originalUrl || req.url || "");
|
|
22
|
+
const sentryTrace = req.headers && core.isString(req.headers["sentry-trace"]) ? req.headers["sentry-trace"] : void 0;
|
|
37
23
|
const baggage = req.headers?.baggage;
|
|
38
|
-
|
|
39
24
|
return node.continueTrace({ sentryTrace, baggage }, () => {
|
|
40
25
|
const normalizedRequest = core.httpRequestToRequestData(req);
|
|
41
26
|
node.getCurrentScope().setSDKProcessingMetadata({ normalizedRequest });
|
|
42
|
-
|
|
43
27
|
return node.startSpanManual(
|
|
44
28
|
{
|
|
45
29
|
name: `${reqMethod} ${reqUrl}`,
|
|
46
|
-
op:
|
|
30
|
+
op: "function.gcp.http",
|
|
47
31
|
attributes: {
|
|
48
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]:
|
|
49
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
50
|
-
}
|
|
32
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route",
|
|
33
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.function.serverless.gcp_http"
|
|
34
|
+
}
|
|
51
35
|
},
|
|
52
|
-
span => {
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
36
|
+
(span) => {
|
|
54
37
|
const _end = res.end;
|
|
55
|
-
|
|
56
|
-
res.end = function (chunk, encoding, cb) {
|
|
38
|
+
res.end = function(chunk, encoding, cb) {
|
|
57
39
|
core.setHttpStatus(span, res.statusCode);
|
|
58
40
|
span.end();
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
.then(() => {
|
|
66
|
-
_end.call(this, chunk, encoding, cb);
|
|
67
|
-
});
|
|
41
|
+
node.flush(flushTimeout).then(null, (e) => {
|
|
42
|
+
debugBuild.DEBUG_BUILD && core.debug.error(e);
|
|
43
|
+
}).then(() => {
|
|
44
|
+
_end.call(this, chunk, encoding, cb);
|
|
45
|
+
});
|
|
68
46
|
};
|
|
69
|
-
|
|
70
47
|
return core.handleCallbackErrors(
|
|
71
48
|
() => fn(req, res),
|
|
72
|
-
err => {
|
|
73
|
-
node.captureException(err, scope => utils.markEventUnhandled(scope,
|
|
74
|
-
}
|
|
49
|
+
(err) => {
|
|
50
|
+
node.captureException(err, (scope) => utils.markEventUnhandled(scope, "auto.function.serverless.gcp_http"));
|
|
51
|
+
}
|
|
75
52
|
);
|
|
76
|
-
}
|
|
53
|
+
}
|
|
77
54
|
);
|
|
78
55
|
});
|
|
79
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sources":["../../../src/gcpfunction/http.ts"],"sourcesContent":["import {\n debug,\n handleCallbackErrors,\n httpRequestToRequestData,\n isString,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\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, 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 return startSpanManual(\n {\n name: `${reqMethod} ${reqUrl}`,\n op: 'function.gcp.http',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.serverless.gcp_http',\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"],"names":["domainify","proxyFunction","stripUrlQueryAndFragment","isString","continueTrace","httpRequestToRequestData","getCurrentScope","startSpanManual","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","setHttpStatus","flush","DEBUG_BUILD","debug","handleCallbackErrors","captureException","markEventUnhandled"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"http.js","sources":["../../../src/gcpfunction/http.ts"],"sourcesContent":["import {\n debug,\n handleCallbackErrors,\n httpRequestToRequestData,\n isString,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\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, 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 return startSpanManual(\n {\n name: `${reqMethod} ${reqUrl}`,\n op: 'function.gcp.http',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.serverless.gcp_http',\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"],"names":["domainify","proxyFunction","stripUrlQueryAndFragment","isString","continueTrace","httpRequestToRequestData","getCurrentScope","startSpanManual","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","setHttpStatus","flush","DEBUG_BUILD","debug","handleCallbackErrors","captureException","markEventUnhandled"],"mappings":";;;;;;;AAsBO,SAAS,gBAAA,CAAiB,EAAA,EAAkB,WAAA,GAAuC,EAAC,EAAiB;AAC1G,EAAA,MAAM,OAAO,CAAC,CAAA,KAAkCA,gBAAU,iBAAA,CAAkB,CAAA,EAAG,WAAW,CAAC,CAA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;AAAA,YACpC,CAACC,qCAAgC,GAAG;AAAA;AACtC,SACF;AAAA,QACA,CAAA,IAAA,KAAQ;AAEN,UAAA,MAAM,OAAO,GAAA,CAAI,GAAA;AAEjB,UAAA,GAAA,CAAI,GAAA,GAAM,SAAU,KAAA,EAA4B,QAAA,EAAkC,EAAA,EAAsB;AACtG,YAAAC,kBAAA,CAAc,IAAA,EAAM,IAAI,UAAU,CAAA;AAClC,YAAA,IAAA,CAAK,GAAA,EAAI;AAGT,YAAAC,UAAA,CAAM,YAAY,CAAA,CACf,IAAA,CAAK,IAAA,EAAM,CAAA,CAAA,KAAK;AACf,cAAAC,sBAAA,IAAeC,UAAA,CAAM,MAAM,CAAC,CAAA;AAAA,YAC9B,CAAC,CAAA,CACA,IAAA,CAAK,MAAM;AACV,cAAA,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM,KAAA,EAAO,QAAA,EAAU,EAAE,CAAA;AAAA,YACrC,CAAC,CAAA;AAAA,UACL,CAAA;AAEA,UAAA,OAAOC,yBAAA;AAAA,YACL,MAAM,EAAA,CAAG,GAAA,EAAK,GAAG,CAAA;AAAA,YACjB,CAAA,GAAA,KAAO;AACL,cAAAC,qBAAA,CAAiB,GAAA,EAAK,CAAA,KAAA,KAASC,wBAAA,CAAmB,KAAA,EAAO,mCAAmC,CAAC,CAAA;AAAA,YAC/F;AAAA,WACF;AAAA,QACF;AAAA,OACF;AAAA,IACF,CAAC,CAAA;AAAA,EACH,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
|
|
5
|
+
const GCP_CONTEXT_ATTRIBUTE_MAP = {
|
|
6
|
+
type: "gcp.function.context.type",
|
|
7
|
+
source: "gcp.function.context.source",
|
|
8
|
+
id: "gcp.function.context.id",
|
|
9
|
+
specversion: "gcp.function.context.specversion",
|
|
10
|
+
time: "gcp.function.context.time",
|
|
11
|
+
eventId: "gcp.function.context.event_id",
|
|
12
|
+
timestamp: "gcp.function.context.timestamp",
|
|
13
|
+
eventType: "gcp.function.context.event_type",
|
|
14
|
+
resource: "gcp.function.context.resource"
|
|
15
|
+
};
|
|
16
|
+
const _gcpContextIntegration = (() => {
|
|
17
|
+
return {
|
|
18
|
+
name: "GcpContext",
|
|
19
|
+
processSegmentSpan(span) {
|
|
20
|
+
const gcpContext = core.getCurrentScope().getScopeData().contexts["gcp.function.context"];
|
|
21
|
+
if (!gcpContext) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const attrs = {};
|
|
25
|
+
for (const [field, attrName] of Object.entries(GCP_CONTEXT_ATTRIBUTE_MAP)) {
|
|
26
|
+
const value = gcpContext[field];
|
|
27
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
28
|
+
attrs[attrName] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
core.safeSetSpanJSONAttributes(span, attrs);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const gcpContextIntegration = core.defineIntegration(_gcpContextIntegration);
|
|
36
|
+
|
|
37
|
+
exports.gcpContextIntegration = gcpContextIntegration;
|
|
38
|
+
//# sourceMappingURL=gcp-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcp-context.js","sources":["../../../src/integrations/gcp-context.ts"],"sourcesContent":["import type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, getCurrentScope, safeSetSpanJSONAttributes } from '@sentry/core';\n\nconst GCP_CONTEXT_ATTRIBUTE_MAP: Record<string, string> = {\n type: 'gcp.function.context.type',\n source: 'gcp.function.context.source',\n id: 'gcp.function.context.id',\n specversion: 'gcp.function.context.specversion',\n time: 'gcp.function.context.time',\n eventId: 'gcp.function.context.event_id',\n timestamp: 'gcp.function.context.timestamp',\n eventType: 'gcp.function.context.event_type',\n resource: 'gcp.function.context.resource',\n};\n\nconst _gcpContextIntegration = (() => {\n return {\n name: 'GcpContext',\n processSegmentSpan(span) {\n const gcpContext = getCurrentScope().getScopeData().contexts['gcp.function.context'];\n if (!gcpContext) {\n return;\n }\n\n const attrs: Record<string, unknown> = {};\n for (const [field, attrName] of Object.entries(GCP_CONTEXT_ATTRIBUTE_MAP)) {\n const value = gcpContext[field];\n if (typeof value === 'string' || typeof value === 'number') {\n attrs[attrName] = value;\n }\n }\n safeSetSpanJSONAttributes(span, attrs);\n },\n };\n}) satisfies IntegrationFn;\n\nexport const gcpContextIntegration = defineIntegration(_gcpContextIntegration);\n"],"names":["getCurrentScope","safeSetSpanJSONAttributes","defineIntegration"],"mappings":";;;;AAGA,MAAM,yBAAA,GAAoD;AAAA,EACxD,IAAA,EAAM,2BAAA;AAAA,EACN,MAAA,EAAQ,6BAAA;AAAA,EACR,EAAA,EAAI,yBAAA;AAAA,EACJ,WAAA,EAAa,kCAAA;AAAA,EACb,IAAA,EAAM,2BAAA;AAAA,EACN,OAAA,EAAS,+BAAA;AAAA,EACT,SAAA,EAAW,gCAAA;AAAA,EACX,SAAA,EAAW,iCAAA;AAAA,EACX,QAAA,EAAU;AACZ,CAAA;AAEA,MAAM,0BAA0B,MAAM;AACpC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,YAAA;AAAA,IACN,mBAAmB,IAAA,EAAM;AACvB,MAAA,MAAM,aAAaA,oBAAA,EAAgB,CAAE,YAAA,EAAa,CAAE,SAAS,sBAAsB,CAAA;AACnF,MAAA,IAAI,CAAC,UAAA,EAAY;AACf,QAAA;AAAA,MACF;AAEA,MAAA,MAAM,QAAiC,EAAC;AACxC,MAAA,KAAA,MAAW,CAAC,KAAA,EAAO,QAAQ,KAAK,MAAA,CAAO,OAAA,CAAQ,yBAAyB,CAAA,EAAG;AACzE,QAAA,MAAM,KAAA,GAAQ,WAAW,KAAK,CAAA;AAC9B,QAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,UAAU,QAAA,EAAU;AAC1D,UAAA,KAAA,CAAM,QAAQ,CAAA,GAAI,KAAA;AAAA,QACpB;AAAA,MACF;AACA,MAAAC,8BAAA,CAA0B,MAAM,KAAK,CAAA;AAAA,IACvC;AAAA,GACF;AACF,CAAA,CAAA;AAEO,MAAM,qBAAA,GAAwBC,uBAAkB,sBAAsB;;;;"}
|
|
@@ -4,23 +4,20 @@ const core = require('@sentry/core');
|
|
|
4
4
|
const node = require('@sentry/node');
|
|
5
5
|
|
|
6
6
|
const SERVICE_PATH_REGEX = /^(\w+)\.googleapis.com$/;
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const SETUP_CLIENTS = new WeakMap();
|
|
11
|
-
|
|
7
|
+
const INTEGRATION_NAME = "GoogleCloudGrpc";
|
|
8
|
+
const SETUP_CLIENTS = /* @__PURE__ */ new WeakMap();
|
|
12
9
|
const _googleCloudGrpcIntegration = ((options = {}) => {
|
|
13
10
|
const optional = options.optional || false;
|
|
14
11
|
return {
|
|
15
12
|
name: INTEGRATION_NAME,
|
|
16
13
|
setupOnce() {
|
|
17
14
|
try {
|
|
18
|
-
|
|
19
|
-
const gaxModule = require('google-gax');
|
|
15
|
+
const gaxModule = require("google-gax");
|
|
20
16
|
core.fill(
|
|
21
|
-
gaxModule.GrpcClient.prototype,
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
gaxModule.GrpcClient.prototype,
|
|
18
|
+
// eslint-disable-line @typescript-eslint/no-unsafe-member-access
|
|
19
|
+
"createStub",
|
|
20
|
+
wrapCreateStub
|
|
24
21
|
);
|
|
25
22
|
} catch (e) {
|
|
26
23
|
if (!optional) {
|
|
@@ -30,20 +27,14 @@ const _googleCloudGrpcIntegration = ((options = {}) => {
|
|
|
30
27
|
},
|
|
31
28
|
setup(client) {
|
|
32
29
|
SETUP_CLIENTS.set(client, true);
|
|
33
|
-
}
|
|
30
|
+
}
|
|
34
31
|
};
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Google Cloud Platform service requests tracking for GRPC APIs.
|
|
39
|
-
*/
|
|
32
|
+
});
|
|
40
33
|
const googleCloudGrpcIntegration = core.defineIntegration(_googleCloudGrpcIntegration);
|
|
41
|
-
|
|
42
|
-
/** Returns a wrapped function that returns a stub with tracing enabled */
|
|
43
34
|
function wrapCreateStub(origCreate) {
|
|
44
|
-
return async function
|
|
35
|
+
return async function(...args) {
|
|
45
36
|
const servicePath = args[1]?.servicePath;
|
|
46
|
-
if (servicePath == null || servicePath ==
|
|
37
|
+
if (servicePath == null || servicePath == void 0) {
|
|
47
38
|
return origCreate.apply(this, args);
|
|
48
39
|
}
|
|
49
40
|
const serviceIdentifier = identifyService(servicePath);
|
|
@@ -54,52 +45,40 @@ function wrapCreateStub(origCreate) {
|
|
|
54
45
|
return stub;
|
|
55
46
|
};
|
|
56
47
|
}
|
|
57
|
-
|
|
58
|
-
/** Patches the function in grpc stub to enable tracing */
|
|
59
48
|
function fillGrpcFunction(stub, serviceIdentifier, methodName) {
|
|
60
49
|
const funcObj = stub[methodName];
|
|
61
|
-
if (typeof funcObj !==
|
|
50
|
+
if (typeof funcObj !== "function") {
|
|
62
51
|
return;
|
|
63
52
|
}
|
|
64
|
-
const callType =
|
|
65
|
-
|
|
66
|
-
? 'unary call'
|
|
67
|
-
: funcObj.requestStream && !funcObj.responseStream
|
|
68
|
-
? 'client stream'
|
|
69
|
-
: !funcObj.requestStream && funcObj.responseStream
|
|
70
|
-
? 'server stream'
|
|
71
|
-
: 'bidi stream';
|
|
72
|
-
if (callType != 'unary call') {
|
|
53
|
+
const callType = !funcObj.requestStream && !funcObj.responseStream ? "unary call" : funcObj.requestStream && !funcObj.responseStream ? "client stream" : !funcObj.requestStream && funcObj.responseStream ? "server stream" : "bidi stream";
|
|
54
|
+
if (callType != "unary call") {
|
|
73
55
|
return;
|
|
74
56
|
}
|
|
75
57
|
core.fill(
|
|
76
58
|
stub,
|
|
77
59
|
methodName,
|
|
78
|
-
(orig) =>
|
|
79
|
-
(
|
|
80
|
-
|
|
81
|
-
if (typeof ret?.on !== 'function' || !SETUP_CLIENTS.has(core.getClient() )) {
|
|
82
|
-
return ret;
|
|
83
|
-
}
|
|
84
|
-
const span = node.startInactiveSpan({
|
|
85
|
-
name: `${callType} ${methodName}`,
|
|
86
|
-
onlyIfParent: true,
|
|
87
|
-
op: `grpc.${serviceIdentifier}`,
|
|
88
|
-
attributes: {
|
|
89
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.grpc.serverless',
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
ret.on('status', () => {
|
|
93
|
-
if (span) {
|
|
94
|
-
span.end();
|
|
95
|
-
}
|
|
96
|
-
});
|
|
60
|
+
(orig) => (...args) => {
|
|
61
|
+
const ret = orig.apply(stub, args);
|
|
62
|
+
if (typeof ret?.on !== "function" || !SETUP_CLIENTS.has(core.getClient())) {
|
|
97
63
|
return ret;
|
|
98
|
-
}
|
|
64
|
+
}
|
|
65
|
+
const span = node.startInactiveSpan({
|
|
66
|
+
name: `${callType} ${methodName}`,
|
|
67
|
+
onlyIfParent: true,
|
|
68
|
+
op: `grpc.${serviceIdentifier}`,
|
|
69
|
+
attributes: {
|
|
70
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.grpc.serverless"
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
ret.on("status", () => {
|
|
74
|
+
if (span) {
|
|
75
|
+
span.end();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return ret;
|
|
79
|
+
}
|
|
99
80
|
);
|
|
100
81
|
}
|
|
101
|
-
|
|
102
|
-
/** Identifies service by its address */
|
|
103
82
|
function identifyService(servicePath) {
|
|
104
83
|
const match = servicePath.match(SERVICE_PATH_REGEX);
|
|
105
84
|
return match?.[1] || servicePath;
|