@sentry/node 10.66.0 → 10.68.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/index.js +21 -19
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/http.js +2 -1
- package/build/cjs/integrations/http.js.map +1 -1
- package/build/cjs/integrations/tracing/dataloader/vendored/instrumentation.js +13 -3
- package/build/cjs/integrations/tracing/dataloader/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/koa/vendored/utils.js +4 -1
- package/build/cjs/integrations/tracing/koa/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js +1 -1
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/mongo/vendored/patches.js +8 -9
- package/build/cjs/integrations/tracing/mongo/vendored/patches.js.map +1 -1
- package/build/cjs/integrations/tracing/mongo/vendored/utils.js +5 -118
- package/build/cjs/integrations/tracing/mongo/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/mongoose/vendored/mongoose.js +33 -23
- package/build/cjs/integrations/tracing/mongoose/vendored/mongoose.js.map +1 -1
- package/build/cjs/integrations/tracing/mongoose/vendored/utils.js +0 -16
- package/build/cjs/integrations/tracing/mongoose/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/redis/cache.js +1 -1
- package/build/cjs/integrations/tracing/redis/cache.js.map +1 -1
- package/build/cjs/sdk/index.js +11 -0
- package/build/cjs/sdk/index.js.map +1 -1
- package/build/cjs/sdk/initOtel.js +26 -2
- package/build/cjs/sdk/initOtel.js.map +1 -1
- package/build/cjs/utils/redisCache.js +4 -0
- package/build/cjs/utils/redisCache.js.map +1 -1
- package/build/esm/index.js +2 -2
- package/build/esm/integrations/http.js +3 -2
- package/build/esm/integrations/http.js.map +1 -1
- package/build/esm/integrations/tracing/dataloader/vendored/instrumentation.js +13 -3
- package/build/esm/integrations/tracing/dataloader/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/koa/vendored/utils.js +5 -2
- package/build/esm/integrations/tracing/koa/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/langgraph/instrumentation.js +2 -2
- package/build/esm/integrations/tracing/langgraph/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/mongo/vendored/patches.js +3 -4
- package/build/esm/integrations/tracing/mongo/vendored/patches.js.map +1 -1
- package/build/esm/integrations/tracing/mongo/vendored/utils.js +6 -118
- package/build/esm/integrations/tracing/mongo/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/mongoose/vendored/mongoose.js +35 -25
- package/build/esm/integrations/tracing/mongoose/vendored/mongoose.js.map +1 -1
- package/build/esm/integrations/tracing/mongoose/vendored/utils.js +1 -16
- package/build/esm/integrations/tracing/mongoose/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/redis/cache.js +2 -2
- package/build/esm/integrations/tracing/redis/cache.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/sdk/index.js +11 -1
- package/build/esm/sdk/index.js.map +1 -1
- package/build/esm/sdk/initOtel.js +27 -3
- package/build/esm/sdk/initOtel.js.map +1 -1
- package/build/esm/utils/redisCache.js +4 -1
- package/build/esm/utils/redisCache.js.map +1 -1
- package/build/types/index.d.ts +2 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/http.d.ts.map +1 -1
- package/build/types/integrations/tracing/dataloader/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/koa/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongo/vendored/patches.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongo/vendored/utils.d.ts +6 -15
- package/build/types/integrations/tracing/mongo/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongoose/vendored/mongoose.d.ts +0 -1
- package/build/types/integrations/tracing/mongoose/vendored/mongoose.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongoose/vendored/utils.d.ts +1 -3
- package/build/types/integrations/tracing/mongoose/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/redis/cache.d.ts.map +1 -1
- package/build/types/integrations/tracing/vercelai/types.d.ts +2 -18
- package/build/types/integrations/tracing/vercelai/types.d.ts.map +1 -1
- package/build/types/sdk/index.d.ts +18 -0
- package/build/types/sdk/index.d.ts.map +1 -1
- package/build/types/sdk/initOtel.d.ts.map +1 -1
- package/build/types/utils/redisCache.d.ts +2 -1
- package/build/types/utils/redisCache.d.ts.map +1 -1
- package/build/types-ts3.8/index.d.ts +2 -2
- package/build/types-ts3.8/integrations/tracing/mongo/vendored/utils.d.ts +6 -15
- package/build/types-ts3.8/integrations/tracing/mongoose/vendored/mongoose.d.ts +0 -1
- package/build/types-ts3.8/integrations/tracing/mongoose/vendored/utils.d.ts +1 -3
- package/build/types-ts3.8/integrations/tracing/vercelai/types.d.ts +2 -18
- package/build/types-ts3.8/sdk/index.d.ts +18 -0
- package/build/types-ts3.8/utils/redisCache.d.ts +2 -1
- package/package.json +5 -5
- package/build/cjs/integrations/tracing/mongo/vendored/internal-types.js +0 -14
- package/build/cjs/integrations/tracing/mongo/vendored/internal-types.js.map +0 -1
- package/build/cjs/integrations/tracing/mongo/vendored/semconv.js +0 -10
- package/build/cjs/integrations/tracing/mongo/vendored/semconv.js.map +0 -1
- package/build/cjs/integrations/tracing/mongoose/vendored/semconv.js +0 -6
- package/build/cjs/integrations/tracing/mongoose/vendored/semconv.js.map +0 -1
- package/build/esm/integrations/tracing/mongo/vendored/internal-types.js +0 -12
- package/build/esm/integrations/tracing/mongo/vendored/internal-types.js.map +0 -1
- package/build/esm/integrations/tracing/mongo/vendored/semconv.js +0 -6
- package/build/esm/integrations/tracing/mongo/vendored/semconv.js.map +0 -1
- package/build/esm/integrations/tracing/mongoose/vendored/semconv.js +0 -4
- package/build/esm/integrations/tracing/mongoose/vendored/semconv.js.map +0 -1
- package/build/types/integrations/tracing/mongo/vendored/semconv.d.ts +0 -17
- package/build/types/integrations/tracing/mongo/vendored/semconv.d.ts.map +0 -1
- package/build/types/integrations/tracing/mongoose/vendored/semconv.d.ts +0 -9
- package/build/types/integrations/tracing/mongoose/vendored/semconv.d.ts.map +0 -1
- package/build/types-ts3.8/integrations/tracing/mongo/vendored/semconv.d.ts +0 -17
- package/build/types-ts3.8/integrations/tracing/mongoose/vendored/semconv.d.ts +0 -9
|
@@ -1,125 +1,13 @@
|
|
|
1
|
-
import { getActiveSpan,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { MongodbCommandType } from './internal-types.js';
|
|
1
|
+
import { getActiveSpan, SPAN_STATUS_ERROR, withActiveSpan } from '@sentry/core';
|
|
2
|
+
import { getV3SpanAttributes as getV3SpanAttributes$1, getV4SpanAttributes as getV4SpanAttributes$1 } from '@sentry/server-utils';
|
|
3
|
+
export { getV3CommandOperation, startMongoSpan } from '@sentry/server-utils';
|
|
5
4
|
|
|
6
5
|
const ORIGIN = "auto.db.otel.mongo";
|
|
7
|
-
function serializeDbStatement(commandObj) {
|
|
8
|
-
return JSON.stringify(scrubStatement(commandObj));
|
|
9
|
-
}
|
|
10
|
-
function scrubStatement(value) {
|
|
11
|
-
if (Array.isArray(value)) {
|
|
12
|
-
return value.map((element) => scrubStatement(element));
|
|
13
|
-
}
|
|
14
|
-
if (isCommandObj(value)) {
|
|
15
|
-
const initial = {};
|
|
16
|
-
return Object.entries(value).map(([key, element]) => [key, scrubStatement(element)]).reduce((prev, current) => {
|
|
17
|
-
if (isCommandEntry(current)) {
|
|
18
|
-
prev[current[0]] = current[1];
|
|
19
|
-
}
|
|
20
|
-
return prev;
|
|
21
|
-
}, initial);
|
|
22
|
-
}
|
|
23
|
-
return "?";
|
|
24
|
-
}
|
|
25
|
-
function isCommandObj(value) {
|
|
26
|
-
return isObjectLike(value) && !isBuffer(value);
|
|
27
|
-
}
|
|
28
|
-
function isBuffer(value) {
|
|
29
|
-
return typeof Buffer !== "undefined" && Buffer.isBuffer(value);
|
|
30
|
-
}
|
|
31
|
-
function isCommandEntry(value) {
|
|
32
|
-
return Array.isArray(value);
|
|
33
|
-
}
|
|
34
|
-
function getCommandType(command) {
|
|
35
|
-
if (command.createIndexes !== void 0) {
|
|
36
|
-
return MongodbCommandType.CREATE_INDEXES;
|
|
37
|
-
} else if (command.findandmodify !== void 0) {
|
|
38
|
-
return MongodbCommandType.FIND_AND_MODIFY;
|
|
39
|
-
} else if (command.ismaster !== void 0) {
|
|
40
|
-
return MongodbCommandType.IS_MASTER;
|
|
41
|
-
} else if (command.count !== void 0) {
|
|
42
|
-
return MongodbCommandType.COUNT;
|
|
43
|
-
} else if (command.aggregate !== void 0) {
|
|
44
|
-
return MongodbCommandType.AGGREGATE;
|
|
45
|
-
} else {
|
|
46
|
-
return MongodbCommandType.UNKNOWN;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
6
|
function getV4SpanAttributes(connectionCtx, ns, command, operation) {
|
|
50
|
-
|
|
51
|
-
if (connectionCtx) {
|
|
52
|
-
const hostParts = typeof connectionCtx.address === "string" ? connectionCtx.address.split(":") : "";
|
|
53
|
-
if (hostParts.length === 2) {
|
|
54
|
-
host = hostParts[0];
|
|
55
|
-
port = hostParts[1];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
let commandObj;
|
|
59
|
-
if (command?.documents && command.documents[0]) {
|
|
60
|
-
commandObj = command.documents[0];
|
|
61
|
-
} else if (command?.cursors) {
|
|
62
|
-
commandObj = command.cursors;
|
|
63
|
-
} else {
|
|
64
|
-
commandObj = command;
|
|
65
|
-
}
|
|
66
|
-
return getSpanAttributes(ns.db, ns.collection, host, port, commandObj, operation);
|
|
7
|
+
return getV4SpanAttributes$1(connectionCtx, ns, command, operation, ORIGIN);
|
|
67
8
|
}
|
|
68
9
|
function getV3SpanAttributes(ns, topology, command, operation) {
|
|
69
|
-
|
|
70
|
-
let port;
|
|
71
|
-
if (topology?.s) {
|
|
72
|
-
host = topology.s.options?.host ?? topology.s.host;
|
|
73
|
-
port = (topology.s.options?.port ?? topology.s.port)?.toString();
|
|
74
|
-
if (host == null || port == null) {
|
|
75
|
-
const address = topology.description?.address;
|
|
76
|
-
if (address) {
|
|
77
|
-
const addressSegments = address.split(":");
|
|
78
|
-
host = addressSegments[0];
|
|
79
|
-
port = addressSegments[1];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const [dbName, dbCollection] = ns.toString().split(".");
|
|
84
|
-
const commandObj = command?.query ?? command?.q ?? command;
|
|
85
|
-
return getSpanAttributes(dbName, dbCollection, host, port, commandObj, operation);
|
|
86
|
-
}
|
|
87
|
-
function getSpanAttributes(dbName, dbCollection, host, port, commandObj, operation) {
|
|
88
|
-
const attributes = {
|
|
89
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
90
|
-
// eslint-disable-next-line typescript/no-deprecated
|
|
91
|
-
[DB_SYSTEM]: DB_SYSTEM_VALUE_MONGODB,
|
|
92
|
-
// eslint-disable-next-line typescript/no-deprecated
|
|
93
|
-
[DB_NAME]: dbName,
|
|
94
|
-
// eslint-disable-next-line typescript/no-deprecated
|
|
95
|
-
[ATTR_DB_MONGODB_COLLECTION]: dbCollection,
|
|
96
|
-
// eslint-disable-next-line typescript/no-deprecated
|
|
97
|
-
[DB_OPERATION]: operation,
|
|
98
|
-
// eslint-disable-next-line typescript/no-deprecated
|
|
99
|
-
[ATTR_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`
|
|
100
|
-
};
|
|
101
|
-
if (host && port) {
|
|
102
|
-
attributes[NET_PEER_NAME] = host;
|
|
103
|
-
const portNumber = parseInt(port, 10);
|
|
104
|
-
if (!isNaN(portNumber)) {
|
|
105
|
-
attributes[NET_PEER_PORT] = portNumber;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (commandObj) {
|
|
109
|
-
try {
|
|
110
|
-
attributes[DB_STATEMENT] = serializeDbStatement(commandObj);
|
|
111
|
-
} catch {
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return attributes;
|
|
115
|
-
}
|
|
116
|
-
function startMongoSpan(attributes) {
|
|
117
|
-
return startInactiveSpan({
|
|
118
|
-
// eslint-disable-next-line typescript/no-deprecated
|
|
119
|
-
name: `mongodb.${attributes[DB_OPERATION] || "command"}`,
|
|
120
|
-
kind: SPAN_KIND.CLIENT,
|
|
121
|
-
attributes
|
|
122
|
-
});
|
|
10
|
+
return getV3SpanAttributes$1(ns, topology, command, operation, ORIGIN);
|
|
123
11
|
}
|
|
124
12
|
function patchEnd(span, resultHandler) {
|
|
125
13
|
const parentSpan = getActiveSpan();
|
|
@@ -142,5 +30,5 @@ function shouldSkipInstrumentation() {
|
|
|
142
30
|
return !getActiveSpan();
|
|
143
31
|
}
|
|
144
32
|
|
|
145
|
-
export {
|
|
33
|
+
export { getV3SpanAttributes, getV4SpanAttributes, patchEnd, shouldSkipInstrumentation };
|
|
146
34
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/mongo/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongodb\n * - Upstream version: @opentelemetry/instrumentation-mongodb@0.71.0\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n getActiveSpan,\n isObjectLike,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n withActiveSpan,\n} from '@sentry/core';\nimport {\n DB_NAME,\n DB_OPERATION,\n DB_STATEMENT,\n DB_SYSTEM,\n NET_PEER_NAME,\n NET_PEER_PORT,\n} from '@sentry/conventions/attributes';\nimport { ATTR_DB_CONNECTION_STRING, ATTR_DB_MONGODB_COLLECTION, DB_SYSTEM_VALUE_MONGODB } from './semconv';\nimport type { MongodbNamespace, MongoInternalCommand, MongoInternalTopology } from './internal-types';\nimport { MongodbCommandType } from './internal-types';\n\nconst ORIGIN = 'auto.db.otel.mongo';\n\n/**\n * Replaces values in the command object with '?', hiding PII and helping grouping.\n */\nfunction serializeDbStatement(commandObj: Record<string, unknown>): string {\n return JSON.stringify(scrubStatement(commandObj));\n}\n\nfunction scrubStatement(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(element => scrubStatement(element));\n }\n\n if (isCommandObj(value)) {\n const initial: Record<string, unknown> = {};\n return Object.entries(value)\n .map(([key, element]) => [key, scrubStatement(element)])\n .reduce((prev, current) => {\n if (isCommandEntry(current)) {\n prev[current[0]] = current[1];\n }\n return prev;\n }, initial);\n }\n\n // A value like string or number, possibly contains PII, scrub it\n return '?';\n}\n\nfunction isCommandObj(value: Record<string, unknown> | unknown): value is Record<string, unknown> {\n return isObjectLike(value) && !isBuffer(value);\n}\n\nfunction isBuffer(value: unknown): boolean {\n return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);\n}\n\nfunction isCommandEntry(value: [string, unknown] | unknown): value is [string, unknown] {\n return Array.isArray(value);\n}\n\n/**\n * Get the mongodb command type from the object.\n */\nexport function getCommandType(command: MongoInternalCommand): MongodbCommandType {\n if (command.createIndexes !== undefined) {\n return MongodbCommandType.CREATE_INDEXES;\n } else if (command.findandmodify !== undefined) {\n return MongodbCommandType.FIND_AND_MODIFY;\n } else if (command.ismaster !== undefined) {\n return MongodbCommandType.IS_MASTER;\n } else if (command.count !== undefined) {\n return MongodbCommandType.COUNT;\n } else if (command.aggregate !== undefined) {\n return MongodbCommandType.AGGREGATE;\n } else {\n return MongodbCommandType.UNKNOWN;\n }\n}\n\n/**\n * Determine a span's attributes by fetching related metadata from the v4 connection context.\n */\nexport function getV4SpanAttributes(\n connectionCtx: any,\n ns: MongodbNamespace,\n command?: any,\n operation?: string,\n): SpanAttributes {\n let host, port: undefined | string;\n if (connectionCtx) {\n const hostParts = typeof connectionCtx.address === 'string' ? connectionCtx.address.split(':') : '';\n if (hostParts.length === 2) {\n host = hostParts[0];\n port = hostParts[1];\n }\n }\n let commandObj: Record<string, unknown>;\n if (command?.documents && command.documents[0]) {\n commandObj = command.documents[0];\n } else if (command?.cursors) {\n commandObj = command.cursors;\n } else {\n commandObj = command;\n }\n\n return getSpanAttributes(ns.db, ns.collection, host, port, commandObj, operation);\n}\n\n/**\n * Determine a span's attributes by fetching related metadata from the v3 topology.\n */\nexport function getV3SpanAttributes(\n ns: string,\n topology: MongoInternalTopology,\n command?: MongoInternalCommand,\n operation?: string | undefined,\n): SpanAttributes {\n let host: undefined | string;\n let port: undefined | string;\n if (topology?.s) {\n host = topology.s.options?.host ?? topology.s.host;\n port = (topology.s.options?.port ?? topology.s.port)?.toString();\n if (host == null || port == null) {\n const address = topology.description?.address;\n if (address) {\n const addressSegments = address.split(':');\n host = addressSegments[0];\n port = addressSegments[1];\n }\n }\n }\n\n // The namespace is a combination of the database name and the name of the\n // collection or index, like so: [database-name].[collection-or-index-name].\n // It could be a string or an instance of MongoDBNamespace, as such we\n // always coerce to a string to extract db and collection.\n const [dbName, dbCollection] = ns.toString().split('.');\n const commandObj = command?.query ?? command?.q ?? command;\n\n return getSpanAttributes(dbName, dbCollection, host, port, commandObj, operation);\n}\n\nfunction getSpanAttributes(\n dbName?: string,\n dbCollection?: string,\n host?: undefined | string,\n port?: undefined | string,\n commandObj?: any,\n operation?: string | undefined,\n): SpanAttributes {\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n // eslint-disable-next-line typescript/no-deprecated\n [DB_SYSTEM]: DB_SYSTEM_VALUE_MONGODB,\n // eslint-disable-next-line typescript/no-deprecated\n [DB_NAME]: dbName,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_MONGODB_COLLECTION]: dbCollection,\n // eslint-disable-next-line typescript/no-deprecated\n [DB_OPERATION]: operation,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,\n };\n\n if (host && port) {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[NET_PEER_NAME] = host;\n const portNumber = parseInt(port, 10);\n if (!isNaN(portNumber)) {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[NET_PEER_PORT] = portNumber;\n }\n }\n\n if (commandObj) {\n try {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[DB_STATEMENT] = serializeDbStatement(commandObj);\n } catch {\n // ignore serialization errors — the statement is best-effort metadata\n }\n }\n\n return attributes;\n}\n\nexport function startMongoSpan(attributes: SpanAttributes): Span {\n return startInactiveSpan({\n // eslint-disable-next-line typescript/no-deprecated\n name: `mongodb.${attributes[DB_OPERATION] || 'command'}`,\n kind: SPAN_KIND.CLIENT,\n attributes,\n });\n}\n\n/**\n * Wraps the result handler so it ends the span (with error status on failure) and runs the\n * original callback re-activated under the parent span — mongodb loses the async context when\n * it invokes the callback on a later tick.\n */\nexport function patchEnd(span: Span | undefined, resultHandler: Function): Function {\n const parentSpan = getActiveSpan();\n let spanEnded = false;\n\n return function patchedEnd(this: {}, ...args: unknown[]) {\n if (!spanEnded) {\n spanEnded = true;\n const error = args[0];\n if (span) {\n if (error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message });\n }\n span.end();\n }\n }\n\n return withActiveSpan(parentSpan ?? null, () => resultHandler.apply(this, args));\n };\n}\n\n// The instrumentation only creates spans when there is an active parent span, to avoid emitting\n// orphaned mongodb spans.\nexport function shouldSkipInstrumentation(): boolean {\n return !getActiveSpan();\n}\n"],"names":[],"mappings":";;;;;AAgCA,MAAM,MAAA,GAAS,oBAAA;AAKf,SAAS,qBAAqB,UAAA,EAA6C;AACzE,EAAA,OAAO,IAAA,C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AAM,KAAA,GAAQ,KAAK,CAAC,CAAA;AACpB,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,UAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,mBAAmB,OAAA,EAAS,KAAA,CAAM,SAAS,CAAA;AAAA,QACpE;AACA,QAAA,IAAA,CAAK,GAAA,EAAI;AAAA,MACX;AAAA,IACF;AAEA,IAAA,OAAO,cAAA,CAAe,cAAc,IAAA,EAAM,MAAM,cAAc,KAAA,CAAM,IAAA,EAAM,IAAI,CAAC,CAAA;AAAA,EACjF,CAAA;AACF;AAIO,SAAS,yBAAA,GAAqC;AACnD,EAAA,OAAO,CAAC,aAAA,EAAc;AACxB;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/mongo/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongodb\n * - Upstream version: @opentelemetry/instrumentation-mongodb@0.71.0\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n * - The db/net attribute extraction, `db.statement` scrubbing and span\n * builder are shared with the orchestrion mongodb integration in\n * `@sentry/server-utils` so the two emit an identical span shape.\n * Only the OTel-specific callback/context helpers below remain here.\n */\n\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport { getActiveSpan, SPAN_STATUS_ERROR, withActiveSpan } from '@sentry/core';\nimport {\n getV3CommandOperation,\n getV3SpanAttributes as sharedGetV3SpanAttributes,\n getV4SpanAttributes as sharedGetV4SpanAttributes,\n startMongoSpan,\n} from '@sentry/server-utils';\n\nconst ORIGIN = 'auto.db.otel.mongo';\n\nexport { getV3CommandOperation, startMongoSpan };\n\n/** Determine a span's attributes from the v4 connection context (OTel origin). */\nexport function getV4SpanAttributes(connectionCtx: any, ns: any, command?: any, operation?: string): SpanAttributes {\n return sharedGetV4SpanAttributes(connectionCtx, ns, command, operation, ORIGIN);\n}\n\n/** Determine a span's attributes from the v3 topology (OTel origin). */\nexport function getV3SpanAttributes(ns: string, topology: any, command?: any, operation?: string): SpanAttributes {\n return sharedGetV3SpanAttributes(ns, topology, command, operation, ORIGIN);\n}\n\n/**\n * Wraps the result handler so it ends the span (with error status on failure) and runs the\n * original callback re-activated under the parent span — mongodb loses the async context when\n * it invokes the callback on a later tick.\n */\nexport function patchEnd(span: Span | undefined, resultHandler: Function): Function {\n const parentSpan = getActiveSpan();\n let spanEnded = false;\n\n return function patchedEnd(this: {}, ...args: unknown[]) {\n if (!spanEnded) {\n spanEnded = true;\n const error = args[0];\n if (span) {\n if (error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message });\n }\n span.end();\n }\n }\n\n return withActiveSpan(parentSpan ?? null, () => resultHandler.apply(this, args));\n };\n}\n\n// The instrumentation only creates spans when there is an active parent span, to avoid emitting\n// orphaned mongodb spans.\nexport function shouldSkipInstrumentation(): boolean {\n return !getActiveSpan();\n}\n"],"names":["sharedGetV4SpanAttributes","sharedGetV3SpanAttributes"],"mappings":";;;;AAuBA,MAAM,MAAA,GAAS,oBAAA;AAKR,SAAS,mBAAA,CAAoB,aAAA,EAAoB,EAAA,EAAS,OAAA,EAAe,SAAA,EAAoC;AAClH,EAAA,OAAOA,qBAAA,CAA0B,aAAA,EAAe,EAAA,EAAI,OAAA,EAAS,WAAW,MAAM,CAAA;AAChF;AAGO,SAAS,mBAAA,CAAoB,EAAA,EAAY,QAAA,EAAe,OAAA,EAAe,SAAA,EAAoC;AAChH,EAAA,OAAOC,qBAAA,CAA0B,EAAA,EAAI,QAAA,EAAU,OAAA,EAAS,WAAW,MAAM,CAAA;AAC3E;AAOO,SAAS,QAAA,CAAS,MAAwB,aAAA,EAAmC;AAClF,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,IAAI,SAAA,GAAY,KAAA;AAEhB,EAAA,OAAO,SAAS,cAAwB,IAAA,EAAiB;AACvD,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,SAAA,GAAY,IAAA;AACZ,MAAA,MAAM,KAAA,GAAQ,KAAK,CAAC,CAAA;AACpB,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,UAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,mBAAmB,OAAA,EAAS,KAAA,CAAM,SAAS,CAAA;AAAA,QACpE;AACA,QAAA,IAAA,CAAK,GAAA,EAAI;AAAA,MACX;AAAA,IACF;AAEA,IAAA,OAAO,cAAA,CAAe,cAAc,IAAA,EAAM,MAAM,cAAc,KAAA,CAAM,IAAA,EAAM,IAAI,CAAC,CAAA;AAAA,EACjF,CAAA;AACF;AAIO,SAAS,yBAAA,GAAqC;AACnD,EAAA,OAAO,CAAC,aAAA,EAAc;AACxB;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { SDK_VERSION, getActiveSpan, withActiveSpan } from '@sentry/core';
|
|
3
|
+
import { startMongooseLegacySpan } from '@sentry/server-utils';
|
|
4
|
+
import { handleCallbackResponse, handlePromiseResponse } from './utils.js';
|
|
5
5
|
|
|
6
6
|
const PACKAGE_NAME = "@sentry/instrumentation-mongoose";
|
|
7
7
|
const ORIGIN = "auto.db.otel.mongoose";
|
|
@@ -109,7 +109,13 @@ class MongooseInstrumentation extends InstrumentationBase {
|
|
|
109
109
|
return (originalAggregate) => {
|
|
110
110
|
return function exec(callback) {
|
|
111
111
|
const parentSpan = this[_STORED_PARENT_SPAN];
|
|
112
|
-
const span =
|
|
112
|
+
const span = startMongooseLegacySpan({
|
|
113
|
+
collection: this._model.collection,
|
|
114
|
+
modelName: this._model?.modelName,
|
|
115
|
+
operation: "aggregate",
|
|
116
|
+
origin: ORIGIN,
|
|
117
|
+
parentSpan
|
|
118
|
+
});
|
|
113
119
|
return self._handleResponse(span, originalAggregate, this, arguments, callback);
|
|
114
120
|
};
|
|
115
121
|
};
|
|
@@ -122,7 +128,13 @@ class MongooseInstrumentation extends InstrumentationBase {
|
|
|
122
128
|
return originalExec.apply(this, arguments);
|
|
123
129
|
}
|
|
124
130
|
const parentSpan = this[_STORED_PARENT_SPAN];
|
|
125
|
-
const span =
|
|
131
|
+
const span = startMongooseLegacySpan({
|
|
132
|
+
collection: this.mongooseCollection,
|
|
133
|
+
modelName: this.model.modelName,
|
|
134
|
+
operation: this.op,
|
|
135
|
+
origin: ORIGIN,
|
|
136
|
+
parentSpan
|
|
137
|
+
});
|
|
126
138
|
return self._handleResponse(span, originalExec, this, arguments, callback);
|
|
127
139
|
};
|
|
128
140
|
};
|
|
@@ -131,7 +143,12 @@ class MongooseInstrumentation extends InstrumentationBase {
|
|
|
131
143
|
const self = this;
|
|
132
144
|
return (originalOnModelFunction) => {
|
|
133
145
|
return function method(options, callback) {
|
|
134
|
-
const span =
|
|
146
|
+
const span = startMongooseLegacySpan({
|
|
147
|
+
collection: this.constructor.collection,
|
|
148
|
+
modelName: this.constructor.modelName,
|
|
149
|
+
operation: op,
|
|
150
|
+
origin: ORIGIN
|
|
151
|
+
});
|
|
135
152
|
if (options instanceof Function) {
|
|
136
153
|
callback = options;
|
|
137
154
|
}
|
|
@@ -150,7 +167,12 @@ class MongooseInstrumentation extends InstrumentationBase {
|
|
|
150
167
|
} else if (typeof options === "function") {
|
|
151
168
|
actualCallback = options;
|
|
152
169
|
}
|
|
153
|
-
const span =
|
|
170
|
+
const span = startMongooseLegacySpan({
|
|
171
|
+
collection: this.constructor.collection,
|
|
172
|
+
modelName: this.constructor.modelName,
|
|
173
|
+
operation: op,
|
|
174
|
+
origin: ORIGIN
|
|
175
|
+
});
|
|
154
176
|
const result = self._handleResponse(span, originalMethod, this, arguments, actualCallback);
|
|
155
177
|
if (result && typeof result === "object") {
|
|
156
178
|
result[_ALREADY_INSTRUMENTED] = true;
|
|
@@ -166,7 +188,12 @@ class MongooseInstrumentation extends InstrumentationBase {
|
|
|
166
188
|
if (typeof options === "function") {
|
|
167
189
|
callback = options;
|
|
168
190
|
}
|
|
169
|
-
const span =
|
|
191
|
+
const span = startMongooseLegacySpan({
|
|
192
|
+
collection: this.collection,
|
|
193
|
+
modelName: this.modelName,
|
|
194
|
+
operation: op,
|
|
195
|
+
origin: ORIGIN
|
|
196
|
+
});
|
|
170
197
|
return self._handleResponse(span, original, this, arguments, callback);
|
|
171
198
|
};
|
|
172
199
|
};
|
|
@@ -193,23 +220,6 @@ class MongooseInstrumentation extends InstrumentationBase {
|
|
|
193
220
|
};
|
|
194
221
|
};
|
|
195
222
|
}
|
|
196
|
-
_startSpan(collection, modelName, operation, parentSpan) {
|
|
197
|
-
const attributes = {
|
|
198
|
-
...getAttributesFromCollection(collection),
|
|
199
|
-
// oxlint-disable-next-line typescript/no-deprecated
|
|
200
|
-
[DB_OPERATION]: operation,
|
|
201
|
-
// oxlint-disable-next-line typescript/no-deprecated
|
|
202
|
-
[DB_SYSTEM]: "mongoose",
|
|
203
|
-
// keep for backwards compatibility
|
|
204
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN
|
|
205
|
-
};
|
|
206
|
-
return startInactiveSpan({
|
|
207
|
-
name: `mongoose.${modelName}.${operation}`,
|
|
208
|
-
kind: SPAN_KIND.CLIENT,
|
|
209
|
-
attributes,
|
|
210
|
-
parentSpan
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
223
|
_handleResponse(span, exec, originalThis, args, callback) {
|
|
214
224
|
return withActiveSpan(span, () => {
|
|
215
225
|
if (callback instanceof Function) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoose.js","sources":["../../../../../../src/integrations/tracing/mongoose/vendored/mongoose.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongoose\n * - Upstream version: @opentelemetry/instrumentation-mongoose@0.64.0\n * - Types vendored from mongoose as simplified interfaces\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\nimport {\n type InstrumentationConfig,\n InstrumentationBase,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\nimport { DB_OPERATION, DB_SYSTEM } from '@sentry/conventions/attributes';\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n getActiveSpan,\n SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n startInactiveSpan,\n withActiveSpan,\n} from '@sentry/core';\nimport type * as mongoose from './mongoose-types';\nimport { getAttributesFromCollection, handleCallbackResponse, handlePromiseResponse } from './utils';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-mongoose';\nconst ORIGIN = 'auto.db.otel.mongoose';\n\ntype MongooseModuleExports = typeof mongoose;\n\n// The raw imported `mongoose` module: either the CJS object itself, or an ESM\n// namespace wrapper exposing the same shape under `.default`.\ntype MongooseModule = MongooseModuleExports & {\n default?: MongooseModuleExports;\n [Symbol.toStringTag]?: string;\n};\n\nconst contextCaptureFunctionsCommon = [\n 'deleteOne',\n 'deleteMany',\n 'find',\n 'findOne',\n 'estimatedDocumentCount',\n 'countDocuments',\n 'distinct',\n 'where',\n '$where',\n 'findOneAndUpdate',\n 'findOneAndDelete',\n 'findOneAndReplace',\n];\n\nconst contextCaptureFunctions6 = ['remove', 'count', 'findOneAndRemove', ...contextCaptureFunctionsCommon];\nconst contextCaptureFunctions7 = ['count', 'findOneAndRemove', ...contextCaptureFunctionsCommon];\nconst contextCaptureFunctions8 = [...contextCaptureFunctionsCommon];\n\nfunction getContextCaptureFunctions(moduleVersion: string | undefined): string[] {\n /* istanbul ignore next */\n if (!moduleVersion) {\n return contextCaptureFunctionsCommon;\n } else if (moduleVersion.startsWith('6.') || moduleVersion.startsWith('5.')) {\n return contextCaptureFunctions6;\n } else if (moduleVersion.startsWith('7.')) {\n return contextCaptureFunctions7;\n } else {\n return contextCaptureFunctions8;\n }\n}\n\nfunction instrumentRemove(moduleVersion: string | undefined): boolean {\n return (moduleVersion && (moduleVersion.startsWith('5.') || moduleVersion.startsWith('6.'))) || false;\n}\n\n/**\n * 8.21.0 changed Document.updateOne/deleteOne so that the Query is not fully built when Query.exec() is called.\n * @param moduleVersion\n */\nfunction needsDocumentMethodPatch(moduleVersion: string | undefined): boolean {\n if (!moduleVersion || !moduleVersion.startsWith('8.')) {\n return false;\n }\n\n const minor = parseInt(moduleVersion.split('.')[1]!, 10);\n return minor >= 21;\n}\n\n// when mongoose functions are called, we store the original call context\n// and then set it as the parent for the spans created by Query/Aggregate exec()\n// calls. this bypass the unlinked spans issue on thenables await operations.\nexport const _STORED_PARENT_SPAN: unique symbol = Symbol('stored-parent-span');\n\n// Prevents double-instrumentation when doc.updateOne/deleteOne (Mongoose 8.21.0+)\n// creates a span and returns a Query that also calls exec()\nexport const _ALREADY_INSTRUMENTED: unique symbol = Symbol('already-instrumented');\n\nexport class MongooseInstrumentation extends InstrumentationBase<InstrumentationConfig> {\n constructor(config: InstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n }\n\n protected init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n 'mongoose',\n // mongoose >= 9.7.0 publishes via diagnostics_channel and is instrumented by\n // `subscribeMongooseDiagnosticChannels` instead, so this IITM patcher must not\n // overlap it — otherwise every operation would emit two mongoose spans.\n ['>=5.9.7 <9.7.0'],\n this.patch.bind(this),\n this.unpatch.bind(this),\n );\n return module;\n }\n\n private patch(module: MongooseModule, moduleVersion: string | undefined) {\n const moduleExports: MongooseModuleExports =\n module[Symbol.toStringTag] === 'Module' && module.default ? module.default : module;\n\n this._wrap(moduleExports.Model.prototype, 'save', this.patchOnModelMethods('save'));\n // mongoose applies this code on module require:\n // Model.prototype.$save = Model.prototype.save;\n // which captures the save function before it is patched.\n // so we need to apply the same logic after instrumenting the save function.\n moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;\n\n if (instrumentRemove(moduleVersion)) {\n this._wrap(moduleExports.Model.prototype, 'remove', this.patchOnModelMethods('remove'));\n }\n\n // Mongoose 8.21.0+ changed Document.updateOne()/deleteOne() so that the Query is not fully built when Query.exec() is called.\n if (needsDocumentMethodPatch(moduleVersion)) {\n this._wrap(moduleExports.Model.prototype, 'updateOne', this._patchDocumentUpdateMethods('updateOne'));\n this._wrap(moduleExports.Model.prototype, 'deleteOne', this._patchDocumentUpdateMethods('deleteOne'));\n }\n\n this._wrap(moduleExports.Query.prototype, 'exec', this.patchQueryExec());\n this._wrap(moduleExports.Aggregate.prototype, 'exec', this.patchAggregateExec());\n\n const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);\n\n contextCaptureFunctions.forEach((funcName: string) => {\n this._wrap(moduleExports.Query.prototype, funcName as any, this.patchAndCaptureSpanContext(funcName));\n });\n this._wrap(moduleExports.Model, 'aggregate', this.patchModelAggregate());\n\n this._wrap(moduleExports.Model, 'insertMany', this.patchModelStatic('insertMany'));\n this._wrap(moduleExports.Model, 'bulkWrite', this.patchModelStatic('bulkWrite'));\n\n return moduleExports;\n }\n\n private unpatch(module: MongooseModule, moduleVersion: string | undefined): void {\n const moduleExports: MongooseModuleExports =\n module[Symbol.toStringTag] === 'Module' && module.default ? module.default : module;\n\n const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);\n\n this._unwrap(moduleExports.Model.prototype, 'save');\n // revert the patch for $save which we applied by aliasing it to patched `save`\n moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;\n\n if (instrumentRemove(moduleVersion)) {\n this._unwrap(moduleExports.Model.prototype, 'remove');\n }\n\n if (needsDocumentMethodPatch(moduleVersion)) {\n this._unwrap(moduleExports.Model.prototype, 'updateOne');\n this._unwrap(moduleExports.Model.prototype, 'deleteOne');\n }\n\n this._unwrap(moduleExports.Query.prototype, 'exec');\n this._unwrap(moduleExports.Aggregate.prototype, 'exec');\n\n contextCaptureFunctions.forEach((funcName: string) => {\n this._unwrap(moduleExports.Query.prototype, funcName as any);\n });\n this._unwrap(moduleExports.Model, 'aggregate');\n\n this._unwrap(moduleExports.Model, 'insertMany');\n this._unwrap(moduleExports.Model, 'bulkWrite');\n }\n\n private patchAggregateExec() {\n const self = this;\n return (originalAggregate: Function) => {\n return function exec(this: any, callback?: Function) {\n const parentSpan = this[_STORED_PARENT_SPAN];\n const span = self._startSpan(this._model.collection, this._model?.modelName, 'aggregate', parentSpan);\n\n return self._handleResponse(span, originalAggregate, this, arguments, callback);\n };\n };\n }\n\n private patchQueryExec() {\n const self = this;\n return (originalExec: Function) => {\n return function exec(this: any, callback?: Function) {\n // Skip if already instrumented by document instance method patch\n if (this[_ALREADY_INSTRUMENTED]) {\n return originalExec.apply(this, arguments);\n }\n\n const parentSpan = this[_STORED_PARENT_SPAN];\n const span = self._startSpan(this.mongooseCollection, this.model.modelName, this.op, parentSpan);\n\n return self._handleResponse(span, originalExec, this, arguments, callback);\n };\n };\n }\n\n private patchOnModelMethods(op: string) {\n const self = this;\n return (originalOnModelFunction: Function) => {\n return function method(this: any, options?: any, callback?: Function) {\n const span = self._startSpan(this.constructor.collection, this.constructor.modelName, op);\n\n if (options instanceof Function) {\n // oxlint-disable-next-line no-param-reassign\n callback = options;\n }\n\n return self._handleResponse(span, originalOnModelFunction, this, arguments, callback);\n };\n };\n }\n\n // Patch document instance methods (doc.updateOne/deleteOne) for Mongoose 8.21.0+.\n private _patchDocumentUpdateMethods(op: string) {\n const self = this;\n return (originalMethod: Function) => {\n return function method(this: any, update?: any, options?: any, callback?: Function) {\n // determine actual callback since different argument patterns are allowed\n let actualCallback: Function | undefined = callback;\n if (typeof update === 'function') {\n actualCallback = update;\n } else if (typeof options === 'function') {\n actualCallback = options;\n }\n\n const span = self._startSpan(this.constructor.collection, this.constructor.modelName, op);\n\n const result = self._handleResponse(span, originalMethod, this, arguments, actualCallback);\n\n // Mark returned Query to prevent double-instrumentation when exec() is eventually called\n if (result && typeof result === 'object') {\n result[_ALREADY_INSTRUMENTED] = true;\n }\n\n return result;\n };\n };\n }\n\n private patchModelStatic(op: string) {\n const self = this;\n return (original: Function) => {\n return function patchedStatic(this: any, docsOrOps: any, options?: any, callback?: Function) {\n if (typeof options === 'function') {\n // oxlint-disable-next-line no-param-reassign\n callback = options;\n }\n\n const span = self._startSpan(this.collection, this.modelName, op);\n\n return self._handleResponse(span, original, this, arguments, callback);\n };\n };\n }\n\n // we want to capture the otel span on the object which is calling exec.\n // in the special case of aggregate, we need have no function to path\n // on the Aggregate object to capture the context on, so we patch\n // the aggregate of Model, and set the context on the Aggregate object\n private patchModelAggregate() {\n return (original: Function) => {\n return function captureSpanContext(this: any) {\n const currentSpan = getActiveSpan();\n const aggregate = original.apply(this, arguments);\n if (aggregate) aggregate[_STORED_PARENT_SPAN] = currentSpan;\n return aggregate;\n };\n };\n }\n\n private patchAndCaptureSpanContext(_funcName: string) {\n return (original: Function) => {\n return function captureSpanContext(this: any) {\n this[_STORED_PARENT_SPAN] = getActiveSpan();\n return original.apply(this, arguments);\n };\n };\n }\n\n private _startSpan(collection: mongoose.Collection, modelName: string, operation: string, parentSpan?: Span): Span {\n const attributes: SpanAttributes = {\n ...getAttributesFromCollection(collection),\n // oxlint-disable-next-line typescript/no-deprecated\n [DB_OPERATION]: operation,\n // oxlint-disable-next-line typescript/no-deprecated\n [DB_SYSTEM]: 'mongoose', // keep for backwards compatibility\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n };\n\n return startInactiveSpan({\n name: `mongoose.${modelName}.${operation}`,\n kind: SPAN_KIND.CLIENT,\n attributes,\n parentSpan,\n });\n }\n\n private _handleResponse(span: Span, exec: Function, originalThis: any, args: IArguments, callback?: Function) {\n // Activate the span while the underlying operation runs so that nested instrumentation\n // (e.g. the mongodb driver spans) is parented to this span. `withActiveSpan` returns the\n // callback's result untouched, so lazy mongoose Query thenables are handed back unexecuted.\n return withActiveSpan(span, () => {\n if (callback instanceof Function) {\n return handleCallbackResponse(callback, exec, originalThis, span, args);\n } else {\n const response = exec.apply(originalThis, args);\n return handlePromiseResponse(response, span);\n }\n });\n }\n}\n"],"names":[],"mappings":";;;;;AA+BA,MAAM,YAAA,GAAe,kCAAA;AACrB,MAAM,MAAA,GAAS,uBAAA;AAWf,MAAM,6BAAA,GAAgC;AAAA,EACpC,WAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,wBAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAA;AAEA,MAAM,2BAA2B,CAAC,QAAA,EAAU,OAAA,EAAS,kBAAA,EAAoB,GAAG,6BAA6B,CAAA;AACzG,MAAM,wBAAA,GAA2B,CAAC,OAAA,EAAS,kBAAA,EAAoB,GAAG,6BAA6B,CAAA;AAC/F,MAAM,wBAAA,GAA2B,CAAC,GAAG,6BAA6B,CAAA;AAElE,SAAS,2BAA2B,aAAA,EAA6C;AAE/E,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,OAAO,6BAAA;AAAA,EACT,CAAA,MAAA,IAAW,cAAc,UAAA,CAAW,IAAI,KAAK,aAAA,CAAc,UAAA,CAAW,IAAI,CAAA,EAAG;AAC3E,IAAA,OAAO,wBAAA;AAAA,EACT,CAAA,MAAA,IAAW,aAAA,CAAc,UAAA,CAAW,IAAI,CAAA,EAAG;AACzC,IAAA,OAAO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A,EACH;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"mongoose.js","sources":["../../../../../../src/integrations/tracing/mongoose/vendored/mongoose.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongoose\n * - Upstream version: @opentelemetry/instrumentation-mongoose@0.64.0\n * - Types vendored from mongoose as simplified interfaces\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\nimport {\n type InstrumentationConfig,\n InstrumentationBase,\n type InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\nimport type { Span } from '@sentry/core';\nimport { getActiveSpan, SDK_VERSION, withActiveSpan } from '@sentry/core';\nimport { startMongooseLegacySpan } from '@sentry/server-utils';\nimport type * as mongoose from './mongoose-types';\nimport { handleCallbackResponse, handlePromiseResponse } from './utils';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-mongoose';\nconst ORIGIN = 'auto.db.otel.mongoose';\n\ntype MongooseModuleExports = typeof mongoose;\n\n// The raw imported `mongoose` module: either the CJS object itself, or an ESM\n// namespace wrapper exposing the same shape under `.default`.\ntype MongooseModule = MongooseModuleExports & {\n default?: MongooseModuleExports;\n [Symbol.toStringTag]?: string;\n};\n\nconst contextCaptureFunctionsCommon = [\n 'deleteOne',\n 'deleteMany',\n 'find',\n 'findOne',\n 'estimatedDocumentCount',\n 'countDocuments',\n 'distinct',\n 'where',\n '$where',\n 'findOneAndUpdate',\n 'findOneAndDelete',\n 'findOneAndReplace',\n];\n\nconst contextCaptureFunctions6 = ['remove', 'count', 'findOneAndRemove', ...contextCaptureFunctionsCommon];\nconst contextCaptureFunctions7 = ['count', 'findOneAndRemove', ...contextCaptureFunctionsCommon];\nconst contextCaptureFunctions8 = [...contextCaptureFunctionsCommon];\n\nfunction getContextCaptureFunctions(moduleVersion: string | undefined): string[] {\n /* istanbul ignore next */\n if (!moduleVersion) {\n return contextCaptureFunctionsCommon;\n } else if (moduleVersion.startsWith('6.') || moduleVersion.startsWith('5.')) {\n return contextCaptureFunctions6;\n } else if (moduleVersion.startsWith('7.')) {\n return contextCaptureFunctions7;\n } else {\n return contextCaptureFunctions8;\n }\n}\n\nfunction instrumentRemove(moduleVersion: string | undefined): boolean {\n return (moduleVersion && (moduleVersion.startsWith('5.') || moduleVersion.startsWith('6.'))) || false;\n}\n\n/**\n * 8.21.0 changed Document.updateOne/deleteOne so that the Query is not fully built when Query.exec() is called.\n * @param moduleVersion\n */\nfunction needsDocumentMethodPatch(moduleVersion: string | undefined): boolean {\n if (!moduleVersion || !moduleVersion.startsWith('8.')) {\n return false;\n }\n\n const minor = parseInt(moduleVersion.split('.')[1]!, 10);\n return minor >= 21;\n}\n\n// when mongoose functions are called, we store the original call context\n// and then set it as the parent for the spans created by Query/Aggregate exec()\n// calls. this bypass the unlinked spans issue on thenables await operations.\nexport const _STORED_PARENT_SPAN: unique symbol = Symbol('stored-parent-span');\n\n// Prevents double-instrumentation when doc.updateOne/deleteOne (Mongoose 8.21.0+)\n// creates a span and returns a Query that also calls exec()\nexport const _ALREADY_INSTRUMENTED: unique symbol = Symbol('already-instrumented');\n\nexport class MongooseInstrumentation extends InstrumentationBase<InstrumentationConfig> {\n constructor(config: InstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n }\n\n protected init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n 'mongoose',\n // mongoose >= 9.7.0 publishes via diagnostics_channel and is instrumented by\n // `subscribeMongooseDiagnosticChannels` instead, so this IITM patcher must not\n // overlap it — otherwise every operation would emit two mongoose spans.\n ['>=5.9.7 <9.7.0'],\n this.patch.bind(this),\n this.unpatch.bind(this),\n );\n return module;\n }\n\n private patch(module: MongooseModule, moduleVersion: string | undefined) {\n const moduleExports: MongooseModuleExports =\n module[Symbol.toStringTag] === 'Module' && module.default ? module.default : module;\n\n this._wrap(moduleExports.Model.prototype, 'save', this.patchOnModelMethods('save'));\n // mongoose applies this code on module require:\n // Model.prototype.$save = Model.prototype.save;\n // which captures the save function before it is patched.\n // so we need to apply the same logic after instrumenting the save function.\n moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;\n\n if (instrumentRemove(moduleVersion)) {\n this._wrap(moduleExports.Model.prototype, 'remove', this.patchOnModelMethods('remove'));\n }\n\n // Mongoose 8.21.0+ changed Document.updateOne()/deleteOne() so that the Query is not fully built when Query.exec() is called.\n if (needsDocumentMethodPatch(moduleVersion)) {\n this._wrap(moduleExports.Model.prototype, 'updateOne', this._patchDocumentUpdateMethods('updateOne'));\n this._wrap(moduleExports.Model.prototype, 'deleteOne', this._patchDocumentUpdateMethods('deleteOne'));\n }\n\n this._wrap(moduleExports.Query.prototype, 'exec', this.patchQueryExec());\n this._wrap(moduleExports.Aggregate.prototype, 'exec', this.patchAggregateExec());\n\n const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);\n\n contextCaptureFunctions.forEach((funcName: string) => {\n this._wrap(moduleExports.Query.prototype, funcName as any, this.patchAndCaptureSpanContext(funcName));\n });\n this._wrap(moduleExports.Model, 'aggregate', this.patchModelAggregate());\n\n this._wrap(moduleExports.Model, 'insertMany', this.patchModelStatic('insertMany'));\n this._wrap(moduleExports.Model, 'bulkWrite', this.patchModelStatic('bulkWrite'));\n\n return moduleExports;\n }\n\n private unpatch(module: MongooseModule, moduleVersion: string | undefined): void {\n const moduleExports: MongooseModuleExports =\n module[Symbol.toStringTag] === 'Module' && module.default ? module.default : module;\n\n const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);\n\n this._unwrap(moduleExports.Model.prototype, 'save');\n // revert the patch for $save which we applied by aliasing it to patched `save`\n moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;\n\n if (instrumentRemove(moduleVersion)) {\n this._unwrap(moduleExports.Model.prototype, 'remove');\n }\n\n if (needsDocumentMethodPatch(moduleVersion)) {\n this._unwrap(moduleExports.Model.prototype, 'updateOne');\n this._unwrap(moduleExports.Model.prototype, 'deleteOne');\n }\n\n this._unwrap(moduleExports.Query.prototype, 'exec');\n this._unwrap(moduleExports.Aggregate.prototype, 'exec');\n\n contextCaptureFunctions.forEach((funcName: string) => {\n this._unwrap(moduleExports.Query.prototype, funcName as any);\n });\n this._unwrap(moduleExports.Model, 'aggregate');\n\n this._unwrap(moduleExports.Model, 'insertMany');\n this._unwrap(moduleExports.Model, 'bulkWrite');\n }\n\n private patchAggregateExec() {\n const self = this;\n return (originalAggregate: Function) => {\n return function exec(this: any, callback?: Function) {\n const parentSpan = this[_STORED_PARENT_SPAN];\n const span = startMongooseLegacySpan({\n collection: this._model.collection,\n modelName: this._model?.modelName,\n operation: 'aggregate',\n origin: ORIGIN,\n parentSpan,\n });\n\n return self._handleResponse(span, originalAggregate, this, arguments, callback);\n };\n };\n }\n\n private patchQueryExec() {\n const self = this;\n return (originalExec: Function) => {\n return function exec(this: any, callback?: Function) {\n // Skip if already instrumented by document instance method patch\n if (this[_ALREADY_INSTRUMENTED]) {\n return originalExec.apply(this, arguments);\n }\n\n const parentSpan = this[_STORED_PARENT_SPAN];\n const span = startMongooseLegacySpan({\n collection: this.mongooseCollection,\n modelName: this.model.modelName,\n operation: this.op,\n origin: ORIGIN,\n parentSpan,\n });\n\n return self._handleResponse(span, originalExec, this, arguments, callback);\n };\n };\n }\n\n private patchOnModelMethods(op: string) {\n const self = this;\n return (originalOnModelFunction: Function) => {\n return function method(this: any, options?: any, callback?: Function) {\n const span = startMongooseLegacySpan({\n collection: this.constructor.collection,\n modelName: this.constructor.modelName,\n operation: op,\n origin: ORIGIN,\n });\n\n if (options instanceof Function) {\n // oxlint-disable-next-line no-param-reassign\n callback = options;\n }\n\n return self._handleResponse(span, originalOnModelFunction, this, arguments, callback);\n };\n };\n }\n\n // Patch document instance methods (doc.updateOne/deleteOne) for Mongoose 8.21.0+.\n private _patchDocumentUpdateMethods(op: string) {\n const self = this;\n return (originalMethod: Function) => {\n return function method(this: any, update?: any, options?: any, callback?: Function) {\n // determine actual callback since different argument patterns are allowed\n let actualCallback: Function | undefined = callback;\n if (typeof update === 'function') {\n actualCallback = update;\n } else if (typeof options === 'function') {\n actualCallback = options;\n }\n\n const span = startMongooseLegacySpan({\n collection: this.constructor.collection,\n modelName: this.constructor.modelName,\n operation: op,\n origin: ORIGIN,\n });\n\n const result = self._handleResponse(span, originalMethod, this, arguments, actualCallback);\n\n // Mark returned Query to prevent double-instrumentation when exec() is eventually called\n if (result && typeof result === 'object') {\n result[_ALREADY_INSTRUMENTED] = true;\n }\n\n return result;\n };\n };\n }\n\n private patchModelStatic(op: string) {\n const self = this;\n return (original: Function) => {\n return function patchedStatic(this: any, docsOrOps: any, options?: any, callback?: Function) {\n if (typeof options === 'function') {\n // oxlint-disable-next-line no-param-reassign\n callback = options;\n }\n\n const span = startMongooseLegacySpan({\n collection: this.collection,\n modelName: this.modelName,\n operation: op,\n origin: ORIGIN,\n });\n\n return self._handleResponse(span, original, this, arguments, callback);\n };\n };\n }\n\n // we want to capture the otel span on the object which is calling exec.\n // in the special case of aggregate, we need have no function to path\n // on the Aggregate object to capture the context on, so we patch\n // the aggregate of Model, and set the context on the Aggregate object\n private patchModelAggregate() {\n return (original: Function) => {\n return function captureSpanContext(this: any) {\n const currentSpan = getActiveSpan();\n const aggregate = original.apply(this, arguments);\n if (aggregate) aggregate[_STORED_PARENT_SPAN] = currentSpan;\n return aggregate;\n };\n };\n }\n\n private patchAndCaptureSpanContext(_funcName: string) {\n return (original: Function) => {\n return function captureSpanContext(this: any) {\n this[_STORED_PARENT_SPAN] = getActiveSpan();\n return original.apply(this, arguments);\n };\n };\n }\n\n private _handleResponse(span: Span, exec: Function, originalThis: any, args: IArguments, callback?: Function) {\n // Activate the span while the underlying operation runs so that nested instrumentation\n // (e.g. the mongodb driver spans) is parented to this span. `withActiveSpan` returns the\n // callback's result untouched, so lazy mongoose Query thenables are handed back unexecuted.\n return withActiveSpan(span, () => {\n if (callback instanceof Function) {\n return handleCallbackResponse(callback, exec, originalThis, span, args);\n } else {\n const response = exec.apply(originalThis, args);\n return handlePromiseResponse(response, span);\n }\n });\n }\n}\n"],"names":[],"mappings":";;;;;AAwBA,MAAM,YAAA,GAAe,kCAAA;AACrB,MAAM,MAAA,GAAS,uBAAA;AAWf,MAAM,6BAAA,GAAgC;AAAA,EACpC,WAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,wBAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAA;AAEA,MAAM,2BAA2B,CAAC,QAAA,EAAU,OAAA,EAAS,kBAAA,EAAoB,GAAG,6BAA6B,CAAA;AACzG,MAAM,wBAAA,GAA2B,CAAC,OAAA,EAAS,kBAAA,EAAoB,GAAG,6BAA6B,CAAA;AAC/F,MAAM,wBAAA,GAA2B,CAAC,GAAG,6BAA6B,CAAA;AAElE,SAAS,2BAA2B,aAAA,EAA6C;AAE/E,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,OAAO,6BAAA;AAAA,EACT,CAAA,MAAA,IAAW,cAAc,UAAA,CAAW,IAAI,KAAK,aAAA,CAAc,UAAA,CAAW,IAAI,CAAA,EAAG;AAC3E,IAAA,OAAO,wBAAA;AAAA,EACT,CAAA,MAAA,IAAW,aAAA,CAAc,UAAA,CAAW,IAAI,CAAA,EAAG;AACzC,IAAA,OAAO,wBAAA;AAAA,EACT,CAAA,MAAO;AACL,IAAA,OAAO,wBAAA;AAAA,EACT;AACF;AAEA,SAAS,iBAAiB,aAAA,EAA4C;AACpE,EAAA,OAAQ,aAAA,KAAkB,cAAc,UAAA,CAAW,IAAI,KAAK,aAAA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cAAc,aAAA,EAAc;AAClC,QAAA,MAAM,SAAA,GAAY,QAAA,CAAS,KAAA,CAAM,IAAA,EAAM,SAAS,CAAA;AAChD,QAAA,IAAI,SAAA,EAAW,SAAA,CAAU,mBAAmB,CAAA,GAAI,WAAA;AAChD,QAAA,OAAO,SAAA;AAAA,MACT,CAAA;AAAA,IACF,CAAA;AAAA,EACF;AAAA,EAEQ,2BAA2B,SAAA,EAAmB;AACpD,IAAA,OAAO,CAAC,QAAA,KAAuB;AAC7B,MAAA,OAAO,SAAS,kBAAA,GAA8B;AAC5C,QAAA,IAAA,CAAK,mBAAmB,IAAI,aAAA,EAAc;AAC1C,QAAA,OAAO,QAAA,CAAS,KAAA,CAAM,IAAA,EAAM,SAAS,CAAA;AAAA,MACvC,CAAA;AAAA,IACF,CAAA;AAAA,EACF;AAAA,EAEQ,eAAA,CAAgB,IAAA,EAAY,IAAA,EAAgB,YAAA,EAAmB,MAAkB,QAAA,EAAqB;AAI5G,IAAA,OAAO,cAAA,CAAe,MAAM,MAAM;AAChC,MAAA,IAAI,oBAAoB,QAAA,EAAU;AAChC,QAAA,OAAO,sBAAA,CAAuB,QAAA,EAAU,IAAA,EAAM,YAAA,EAAc,MAAM,IAAI,CAAA;AAAA,MACxE,CAAA,MAAO;AACL,QAAA,MAAM,QAAA,GAAW,IAAA,CAAK,KAAA,CAAM,YAAA,EAAc,IAAI,CAAA;AAC9C,QAAA,OAAO,qBAAA,CAAsB,UAAU,IAAI,CAAA;AAAA,MAC7C;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF;;;;"}
|
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import { NET_PEER_PORT, NET_PEER_NAME, DB_USER, DB_NAME } from '@sentry/conventions/attributes';
|
|
2
1
|
import { SPAN_STATUS_ERROR } from '@sentry/core';
|
|
3
|
-
import { ATTR_DB_MONGODB_COLLECTION } from './semconv.js';
|
|
4
2
|
|
|
5
|
-
function getAttributesFromCollection(collection) {
|
|
6
|
-
return {
|
|
7
|
-
// oxlint-disable-next-line typescript/no-deprecated
|
|
8
|
-
[ATTR_DB_MONGODB_COLLECTION]: collection.name,
|
|
9
|
-
// oxlint-disable-next-line typescript/no-deprecated
|
|
10
|
-
[DB_NAME]: collection.conn.name,
|
|
11
|
-
[DB_USER]: collection.conn.user,
|
|
12
|
-
// oxlint-disable-next-line typescript/no-deprecated
|
|
13
|
-
[NET_PEER_NAME]: collection.conn.host,
|
|
14
|
-
// oxlint-disable-next-line typescript/no-deprecated
|
|
15
|
-
[NET_PEER_PORT]: collection.conn.port
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
3
|
function setErrorStatus(span, error) {
|
|
19
4
|
span.setStatus({
|
|
20
5
|
code: SPAN_STATUS_ERROR,
|
|
@@ -49,5 +34,5 @@ function handleCallbackResponse(callback, exec, originalThis, span, args) {
|
|
|
49
34
|
return exec.apply(originalThis, args);
|
|
50
35
|
}
|
|
51
36
|
|
|
52
|
-
export {
|
|
37
|
+
export { handleCallbackResponse, handlePromiseResponse };
|
|
53
38
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/mongoose/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongoose\n * - Upstream version: @opentelemetry/instrumentation-mongoose@0.64.0\n * - Types vendored from mongoose as simplified interfaces\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\nimport
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/mongoose/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongoose\n * - Upstream version: @opentelemetry/instrumentation-mongoose@0.64.0\n * - Types vendored from mongoose as simplified interfaces\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\nimport type { Span } from '@sentry/core';\nimport { SPAN_STATUS_ERROR } from '@sentry/core';\nimport type { MongooseError } from './mongoose-types';\n\nfunction setErrorStatus(span: Span, error: MongooseError): void {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: `${error.message} ${error.code ? `\\nMongoose Error Code: ${error.code}` : ''}`,\n });\n}\n\nexport function handlePromiseResponse(execResponse: any, span: Span): any {\n if (!(execResponse instanceof Promise)) {\n span.end();\n return execResponse;\n }\n\n return execResponse\n .catch((err: any) => {\n setErrorStatus(span, err);\n throw err;\n })\n .finally(() => span.end());\n}\n\nexport function handleCallbackResponse(\n callback: Function,\n exec: Function,\n originalThis: any,\n span: Span,\n args: IArguments,\n) {\n let callbackArgumentIndex = 0;\n if (args.length === 2) {\n callbackArgumentIndex = 1;\n } else if (args.length === 3) {\n callbackArgumentIndex = 2;\n }\n\n args[callbackArgumentIndex] = (err: Error, response: any): any => {\n if (err) {\n setErrorStatus(span, err);\n }\n\n span.end();\n return callback(err, response);\n };\n\n return exec.apply(originalThis, args);\n}\n"],"names":[],"mappings":";;AAeA,SAAS,cAAA,CAAe,MAAY,KAAA,EAA4B;AAC9D,EAAA,IAAA,CAAK,SAAA,CAAU;AAAA,IACb,IAAA,EAAM,iBAAA;AAAA,IACN,SAAS,CAAA,EAAG,KAAA,CAAM,OAAO,CAAA,CAAA,EAAI,MAAM,IAAA,GAAO;AAAA,qBAAA,EAA0B,KAAA,CAAM,IAAI,CAAA,CAAA,GAAK,EAAE,CAAA;AAAA,GACtF,CAAA;AACH;AAEO,SAAS,qBAAA,CAAsB,cAAmB,IAAA,EAAiB;AACxE,EAAA,IAAI,EAAE,wBAAwB,OAAA,CAAA,EAAU;AACtC,IAAA,IAAA,CAAK,GAAA,EAAI;AACT,IAAA,OAAO,YAAA;AAAA,EACT;AAEA,EAAA,OAAO,YAAA,CACJ,KAAA,CAAM,CAAC,GAAA,KAAa;AACnB,IAAA,cAAA,CAAe,MAAM,GAAG,CAAA;AACxB,IAAA,MAAM,GAAA;AAAA,EACR,CAAC,CAAA,CACA,OAAA,CAAQ,MAAM,IAAA,CAAK,KAAK,CAAA;AAC7B;AAEO,SAAS,sBAAA,CACd,QAAA,EACA,IAAA,EACA,YAAA,EACA,MACA,IAAA,EACA;AACA,EAAA,IAAI,qBAAA,GAAwB,CAAA;AAC5B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACrB,IAAA,qBAAA,GAAwB,CAAA;AAAA,EAC1B,CAAA,MAAA,IAAW,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC5B,IAAA,qBAAA,GAAwB,CAAA;AAAA,EAC1B;AAEA,EAAA,IAAA,CAAK,qBAAqB,CAAA,GAAI,CAAC,GAAA,EAAY,QAAA,KAAuB;AAChE,IAAA,IAAI,GAAA,EAAK;AACP,MAAA,cAAA,CAAe,MAAM,GAAG,CAAA;AAAA,IAC1B;AAEA,IAAA,IAAA,CAAK,GAAA,EAAI;AACT,IAAA,OAAO,QAAA,CAAS,KAAK,QAAQ,CAAA;AAAA,EAC/B,CAAA;AAEA,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,YAAA,EAAc,IAAI,CAAA;AACtC;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spanToJSON, SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE, SEMANTIC_ATTRIBUTE_CACHE_HIT, SEMANTIC_ATTRIBUTE_CACHE_KEY, SEMANTIC_ATTRIBUTE_SENTRY_OP, truncate } from '@sentry/core';
|
|
2
|
-
import { getCacheKeySafely, getCacheOperation, shouldConsiderForCache, calculateCacheItemSize,
|
|
2
|
+
import { getCacheKeySafely, getCacheOperation, shouldConsiderForCache, isInCommands, calculateCacheItemSize, REMOVE_COMMANDS, GET_COMMANDS } from '../../../utils/redisCache.js';
|
|
3
3
|
|
|
4
4
|
let _redisOptions = {};
|
|
5
5
|
function setRedisOptions(options) {
|
|
@@ -17,7 +17,7 @@ const cacheResponseHook = (span, redisCommand, cmdArgs, response) => {
|
|
|
17
17
|
if (networkPeerPort && networkPeerAddress) {
|
|
18
18
|
span.setAttributes({ "network.peer.address": networkPeerAddress, "network.peer.port": networkPeerPort });
|
|
19
19
|
}
|
|
20
|
-
const cacheItemSize = calculateCacheItemSize(response);
|
|
20
|
+
const cacheItemSize = isInCommands(REMOVE_COMMANDS, redisCommand) ? void 0 : calculateCacheItemSize(response);
|
|
21
21
|
if (cacheItemSize) {
|
|
22
22
|
span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE, cacheItemSize);
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sources":["../../../../../src/integrations/tracing/redis/cache.ts"],"sourcesContent":["import type { Span } from '@sentry/core';\nimport {\n SEMANTIC_ATTRIBUTE_CACHE_HIT,\n SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE,\n SEMANTIC_ATTRIBUTE_CACHE_KEY,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n spanToJSON,\n truncate,\n} from '@sentry/core';\nimport type { IORedisCommandArgs } from '../../../utils/redisCache';\nimport {\n calculateCacheItemSize,\n GET_COMMANDS,\n getCacheKeySafely,\n getCacheOperation,\n isInCommands,\n shouldConsiderForCache,\n} from '../../../utils/redisCache';\nimport type { IORedisResponseCustomAttributeFunction } from './vendored/types';\n\n// This module deliberately does NOT import the vendored OTel `IORedisInstrumentation`/\n// `RedisInstrumentation`, so the orchestrion opt-in can pull `cacheResponseHook`\n// without dragging the OTel redis instrumentation into its module graph.\n\nexport interface RedisOptions {\n /**\n * Define cache prefixes for cache keys that should be captured as a cache span.\n *\n * Setting this to, for example, `['user:']` will capture cache keys that start with `user:`.\n */\n cachePrefixes?: string[];\n /**\n * Maximum length of the cache key added to the span description. If the key exceeds this length, it will be truncated.\n *\n * Passing `0` will use the full cache key without truncation.\n *\n * By default, the full cache key is used.\n */\n maxCacheKeyLength?: number;\n}\n\n/* Only exported for testing purposes */\nexport let _redisOptions: RedisOptions = {};\n\n/** Set the options consumed by {@link cacheResponseHook}. */\nexport function setRedisOptions(options: RedisOptions): void {\n _redisOptions = options;\n}\n\n/* Only exported for testing purposes */\nexport const cacheResponseHook: IORedisResponseCustomAttributeFunction = (\n span: Span,\n redisCommand: string,\n cmdArgs: IORedisCommandArgs,\n response: unknown,\n) => {\n const safeKey = getCacheKeySafely(redisCommand, cmdArgs);\n const cacheOperation = getCacheOperation(redisCommand);\n\n if (\n !safeKey ||\n !cacheOperation ||\n !_redisOptions.cachePrefixes ||\n !shouldConsiderForCache(redisCommand, safeKey, _redisOptions.cachePrefixes)\n ) {\n // not relevant for cache\n return;\n }\n\n // otel/ioredis seems to be using the old standard, as there was a change to those params: https://github.com/open-telemetry/opentelemetry-specification/issues/3199\n // We are using params based on the docs: https://opentelemetry.io/docs/specs/semconv/attributes-registry/network/\n // Fall back to stable semconv attributes (server.address/server.port) when\n // old-semconv ones are absent, eg OTEL_SEMCONV_STABILITY_OPT_IN=database\n // set for node-redis v4/v5.\n const spanData = spanToJSON(span).data;\n const networkPeerAddress = spanData['net.peer.name'] ?? spanData['server.address'];\n const networkPeerPort = spanData['net.peer.port'] ?? spanData['server.port'];\n if (networkPeerPort && networkPeerAddress) {\n span.setAttributes({ 'network.peer.address': networkPeerAddress, 'network.peer.port': networkPeerPort });\n }\n\n const cacheItemSize = calculateCacheItemSize(response);\n\n if (cacheItemSize) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE, cacheItemSize);\n }\n\n if (isInCommands(GET_COMMANDS, redisCommand) && cacheItemSize !== undefined) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, cacheItemSize > 0);\n }\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: cacheOperation,\n [SEMANTIC_ATTRIBUTE_CACHE_KEY]: safeKey,\n });\n\n // todo: change to string[] once EAP supports it\n const spanDescription = safeKey.join(', ');\n\n span.updateName(\n _redisOptions.maxCacheKeyLength ? truncate(spanDescription, _redisOptions.maxCacheKeyLength) : spanDescription,\n );\n};\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"cache.js","sources":["../../../../../src/integrations/tracing/redis/cache.ts"],"sourcesContent":["import type { Span } from '@sentry/core';\nimport {\n SEMANTIC_ATTRIBUTE_CACHE_HIT,\n SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE,\n SEMANTIC_ATTRIBUTE_CACHE_KEY,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n spanToJSON,\n truncate,\n} from '@sentry/core';\nimport type { IORedisCommandArgs } from '../../../utils/redisCache';\nimport {\n calculateCacheItemSize,\n GET_COMMANDS,\n getCacheKeySafely,\n getCacheOperation,\n isInCommands,\n REMOVE_COMMANDS,\n shouldConsiderForCache,\n} from '../../../utils/redisCache';\nimport type { IORedisResponseCustomAttributeFunction } from './vendored/types';\n\n// This module deliberately does NOT import the vendored OTel `IORedisInstrumentation`/\n// `RedisInstrumentation`, so the orchestrion opt-in can pull `cacheResponseHook`\n// without dragging the OTel redis instrumentation into its module graph.\n\nexport interface RedisOptions {\n /**\n * Define cache prefixes for cache keys that should be captured as a cache span.\n *\n * Setting this to, for example, `['user:']` will capture cache keys that start with `user:`.\n */\n cachePrefixes?: string[];\n /**\n * Maximum length of the cache key added to the span description. If the key exceeds this length, it will be truncated.\n *\n * Passing `0` will use the full cache key without truncation.\n *\n * By default, the full cache key is used.\n */\n maxCacheKeyLength?: number;\n}\n\n/* Only exported for testing purposes */\nexport let _redisOptions: RedisOptions = {};\n\n/** Set the options consumed by {@link cacheResponseHook}. */\nexport function setRedisOptions(options: RedisOptions): void {\n _redisOptions = options;\n}\n\n/* Only exported for testing purposes */\nexport const cacheResponseHook: IORedisResponseCustomAttributeFunction = (\n span: Span,\n redisCommand: string,\n cmdArgs: IORedisCommandArgs,\n response: unknown,\n) => {\n const safeKey = getCacheKeySafely(redisCommand, cmdArgs);\n const cacheOperation = getCacheOperation(redisCommand);\n\n if (\n !safeKey ||\n !cacheOperation ||\n !_redisOptions.cachePrefixes ||\n !shouldConsiderForCache(redisCommand, safeKey, _redisOptions.cachePrefixes)\n ) {\n // not relevant for cache\n return;\n }\n\n // otel/ioredis seems to be using the old standard, as there was a change to those params: https://github.com/open-telemetry/opentelemetry-specification/issues/3199\n // We are using params based on the docs: https://opentelemetry.io/docs/specs/semconv/attributes-registry/network/\n // Fall back to stable semconv attributes (server.address/server.port) when\n // old-semconv ones are absent, eg OTEL_SEMCONV_STABILITY_OPT_IN=database\n // set for node-redis v4/v5.\n const spanData = spanToJSON(span).data;\n const networkPeerAddress = spanData['net.peer.name'] ?? spanData['server.address'];\n const networkPeerPort = spanData['net.peer.port'] ?? spanData['server.port'];\n if (networkPeerPort && networkPeerAddress) {\n span.setAttributes({ 'network.peer.address': networkPeerAddress, 'network.peer.port': networkPeerPort });\n }\n\n // A remove response is a delete-count, not a cached value, so its size is meaningless.\n const cacheItemSize = isInCommands(REMOVE_COMMANDS, redisCommand) ? undefined : calculateCacheItemSize(response);\n\n if (cacheItemSize) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE, cacheItemSize);\n }\n\n if (isInCommands(GET_COMMANDS, redisCommand) && cacheItemSize !== undefined) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, cacheItemSize > 0);\n }\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: cacheOperation,\n [SEMANTIC_ATTRIBUTE_CACHE_KEY]: safeKey,\n });\n\n // todo: change to string[] once EAP supports it\n const spanDescription = safeKey.join(', ');\n\n span.updateName(\n _red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CAAK,YAAA,CAAa,4BAAA,EAA8B,aAAA,GAAgB,CAAC,CAAA;AAAA,EACnE;AAEA,EAAA,IAAA,CAAK,aAAA,CAAc;AAAA,IACjB,CAAC,4BAA4B,GAAG,cAAA;AAAA,IAChC,CAAC,4BAA4B,GAAG;AAAA,GACjC,CAAA;AAGD,EAAA,MAAM,eAAA,GAAkB,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA;AAEzC,EAAA,IAAA,CAAK,UAAA;AAAA,IACH,cAAc,iBAAA,GAAoB,QAAA,CAAS,eAAA,EAAiB,aAAA,CAAc,iBAAiB,CAAA,GAAI;AAAA,GACjG;AACF;;;;"}
|
package/build/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"10.
|
|
1
|
+
{"type":"module","version":"10.68.0","sideEffects":false}
|
package/build/esm/sdk/index.js
CHANGED
|
@@ -20,6 +20,16 @@ function getDefaultIntegrations(options) {
|
|
|
20
20
|
...hasSpansEnabled(options) ? getAutoPerformanceIntegrations() : []
|
|
21
21
|
];
|
|
22
22
|
}
|
|
23
|
+
function applyDiagnosticsChannelInjectionIntegrations(integrations, options) {
|
|
24
|
+
if (isDiagnosticsChannelInjectionEnabled() && hasSpansEnabled(options)) {
|
|
25
|
+
const diagnosticsChannelInjection = resolveDiagnosticsChannelInjection();
|
|
26
|
+
if (diagnosticsChannelInjection) {
|
|
27
|
+
const replaced = new Set(diagnosticsChannelInjection.replacedOtelIntegrationNames);
|
|
28
|
+
return [...integrations.filter((i) => !replaced.has(i.name)), ...diagnosticsChannelInjection.integrations];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return integrations;
|
|
32
|
+
}
|
|
23
33
|
function init(options = {}) {
|
|
24
34
|
return _init(options, getDefaultIntegrations);
|
|
25
35
|
}
|
|
@@ -56,5 +66,5 @@ function initWithoutDefaultIntegrations(options = {}) {
|
|
|
56
66
|
return _init(options, () => []);
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
export { getDefaultIntegrations, getDefaultIntegrationsWithoutPerformance, init, initWithoutDefaultIntegrations };
|
|
69
|
+
export { applyDiagnosticsChannelInjectionIntegrations, getDefaultIntegrations, getDefaultIntegrationsWithoutPerformance, init, initWithoutDefaultIntegrations };
|
|
60
70
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/sdk/index.ts"],"sourcesContent":["import type { Integration, Options } from '@sentry/core';\nimport { applySdkMetadata, hasSpansEnabled } from '@sentry/core';\nimport type { NodeClient } from '@sentry/node-core';\nimport {\n getDefaultIntegrations as getNodeCoreDefaultIntegrations,\n init as initNodeCore,\n validateOpenTelemetrySetup,\n} from '@sentry/node-core';\nimport { httpIntegration } from '../integrations/http';\nimport { nativeNodeFetchIntegration } from '../integrations/node-fetch';\nimport { getAutoPerformanceIntegrations } from '../integrations/tracing';\nimport type { NodeOptions } from '../types';\nimport {\n isDiagnosticsChannelInjectionEnabled,\n resolveDiagnosticsChannelInjection,\n} from './diagnosticsChannelInjection';\nimport { initOpenTelemetry } from './initOtel';\n\n/**\n * Get default integrations, excluding performance.\n */\nexport function getDefaultIntegrationsWithoutPerformance(): Integration[] {\n const nodeCoreIntegrations = getNodeCoreDefaultIntegrations();\n\n // Filter out the node-core HTTP and NodeFetch integrations and replace them with Node SDK's composite versions\n return nodeCoreIntegrations\n .filter(integration => integration.name !== 'Http' && integration.name !== 'NodeFetch')\n .concat(httpIntegration(), nativeNodeFetchIntegration());\n}\n\n/** Get the default integrations for the Node SDK. */\nexport function getDefaultIntegrations(options: Options): Integration[] {\n return [\n ...getDefaultIntegrationsWithoutPerformance(),\n // We only add performance integrations if tracing is enabled\n // Note that this means that without tracing enabled, e.g. `expressIntegration()` will not be added\n // This means that generally request isolation will work (because that is done by httpIntegration)\n // But `transactionName` will not be set automatically\n ...(hasSpansEnabled(options) ? getAutoPerformanceIntegrations() : []),\n ];\n}\n\n/**\n * Initialize Sentry for Node.\n */\nexport function init(options: NodeOptions | undefined = {}): NodeClient | undefined {\n return _init(options, getDefaultIntegrations);\n}\n\n/**\n * Internal initialization function.\n */\nfunction _init(\n options: NodeOptions | undefined = {},\n getDefaultIntegrationsImpl: (options: Options) => Integration[],\n): NodeClient | undefined {\n applySdkMetadata(options, 'node');\n\n // EXPERIMENTAL: diagnostics-channel injection, opted into via\n // `experimentalUseDiagnosticsChannelInjection()`. Gated on span recording to\n // match the OTel integrations it replaces. With tracing off there are no\n // channel subscribers, so injecting is pointless work.\n const diagnosticsChannelInjection =\n isDiagnosticsChannelInjectionEnabled() && hasSpansEnabled(options)\n ? resolveDiagnosticsChannelInjection()\n : undefined;\n\n // Install the channel-injection hooks as early as possible, before the app\n // imports its instrumented modules.\n if (diagnosticsChannelInjection) {\n diagnosticsChannelInjection.register();\n }\n\n // Only use Node SDK defaults if none provided.\n let defaultIntegrations = options.defaultIntegrations ?? getDefaultIntegrationsImpl(options);\n\n // When opted into diagnostics-channel injection, swap the channel-based\n // integrations in place of their OTel equivalents so the two don't both\n // instrument the same library. Done here (rather than in\n // `getDefaultIntegrations`) so it also covers framework SDKs (e.g.\n // `@sentry/nestjs`) that pass their own `defaultIntegrations` array.\n //\n // Only when there's a non-empty default set to swap:\n // `defaultIntegrations: false` (not an array) and `[]` /\n // `initWithoutDefaultIntegrations()` (explicitly no defaults) are left\n // untouched, as appending channel integrations there would resurrect\n // defaults the caller opted out of.\n if (diagnosticsChannelInjection && Array.isArray(defaultIntegrations) && defaultIntegrations.length > 0) {\n const replaced = new Set(diagnosticsChannelInjection.replacedOtelIntegrationNames);\n defaultIntegrations = [\n ...defaultIntegrations.filter(integration => !replaced.has(integration.name)),\n ...diagnosticsChannelInjection.integrations,\n ];\n }\n\n const client = initNodeCore({\n ...options,\n defaultIntegrations,\n });\n\n // Add Node SDK specific OpenTelemetry setup\n if (client && !options.skipOpenTelemetrySetup) {\n initOpenTelemetry(client, {\n spanProcessors: options.openTelemetrySpanProcessors,\n });\n validateOpenTelemetrySetup();\n }\n\n // Warn about missing or doubled channel injection. Runs after the client\n // is created so the debug logger is enabled and the warning is emitted.\n if (diagnosticsChannelInjection) {\n diagnosticsChannelInjection.detect();\n }\n\n return client;\n}\n\n/**\n * Initialize Sentry for Node, without any integrations added by default.\n */\nexport function initWithoutDefaultIntegrations(options: NodeOptions | undefined = {}): NodeClient | undefined {\n return _init(options, () => []);\n}\n"],"names":["getNodeCoreDefaultIntegrations","initNodeCore"],"mappings":";;;;;;;;AAqBO,SAAS,wCAAA,GAA0D;AACxE,EAAA,MAAM,uBAAuBA,wBAAA,EAA+B;AAG5D,EAAA,OAAO,oBAAA,CACJ,MAAA,CAAO,CAAA,WAAA,KAAe,WAAA,CAAY,SAAS,MAAA,IAAU,WAAA,CAAY,IAAA,KAAS,WAAW,CAAA,CACrF,MAAA,CAAO,eAAA,EAAgB,EAAG,4BAA4B,CAAA;AAC3D;AAGO,SAAS,uBAAuB,OAAA,EAAiC;AACtE,EAAA,OAAO;AAAA,IACL,GAAG,wCAAA,EAAyC;AAAA;AAAA;AAAA;AAAA;AAAA,IAK5C,GAAI,eAAA,CAAgB,OAAO,CAAA,GAAI,8BAAA,KAAmC;AAAC,GACrE;AACF;AAKO,SAAS,IAAA,CAAK,OAAA,GAAmC,EAAC,EAA2B;AAClF,EAAA,OAAO,KAAA,CAAM,SAAS,sBAAsB,CAAA;AAC9C;AAKA,SAAS,KAAA,CACP,OAAA,GAAmC,EAAC,EACpC,0BAAA,EACwB;AACxB,EAAA,gBAAA,CAAiB,SAAS,MAAM,CAAA;AAMhC,EAAA,MAAM,8BACJ,oCAAA,EAAqC,IAAK,gBAAgB,OAAO,CAAA,GAC7D,oCAAmC,GACnC,MAAA;AAIN,EAAA,IAAI,2BAAA,EAA6B;AAC/B,IAAA,2BAAA,CAA4B,QAAA,EAAS;AAAA,EACvC;AAGA,EAAA,IAAI,mBAAA,GAAsB,OAAA,CAAQ,mBAAA,IAAuB,0BAAA,CAA2B,OAAO,CAAA;AAa3F,EAAA,IAAI,+BAA+B,KAAA,CAAM,OAAA,CAAQ,mBAAmB,CAAA,IAAK,mBAAA,CAAoB,SAAS,CAAA,EAAG;AACvG,IAAA,MAAM,QAAA,GAAW,IAAI,GAAA,CAAI,2BAAA,CAA4B,4BAA4B,CAAA;AACjF,IAAA,mBAAA,GAAsB;AAAA,MACpB,GAAG,oBAAoB,MAAA,CAAO,CAAA,WAAA,KAAe,CAAC,QAAA,CAAS,GAAA,CAAI,WAAA,CAAY,IAAI,CAAC,CAAA;AAAA,MAC5E,GAAG,2BAAA,CAA4B;AAAA,KACjC;AAAA,EACF;AAEA,EAAA,MAAM,SAASC,MAAA,CAAa;AAAA,IAC1B,GAAG,OAAA;AAAA,IACH;AAAA,GACD,CAAA;AAGD,EAAA,IAAI,MAAA,IAAU,CAAC,OAAA,CAAQ,sBAAA,EAAwB;AAC7C,IAAA,iBAAA,CAAkB,MAAA,EAAQ;AAAA,MACxB,gBAAgB,OAAA,CAAQ;AAAA,KACzB,CAAA;AACD,IAAA,0BAAA,EAA2B;AAAA,EAC7B;AAIA,EAAA,IAAI,2BAAA,EAA6B;AAC/B,IAAA,2BAAA,CAA4B,MAAA,EAAO;AAAA,EACrC;AAEA,EAAA,OAAO,MAAA;AACT;AAKO,SAAS,8BAAA,CAA+B,OAAA,GAAmC,EAAC,EAA2B;AAC5G,EAAA,OAAO,KAAA,CAAM,OAAA,EAAS,MAAM,EAAE,CAAA;AAChC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/sdk/index.ts"],"sourcesContent":["import type { Integration, Options } from '@sentry/core';\nimport { applySdkMetadata, hasSpansEnabled } from '@sentry/core';\nimport type { NodeClient } from '@sentry/node-core';\nimport {\n getDefaultIntegrations as getNodeCoreDefaultIntegrations,\n init as initNodeCore,\n validateOpenTelemetrySetup,\n} from '@sentry/node-core';\nimport { httpIntegration } from '../integrations/http';\nimport { nativeNodeFetchIntegration } from '../integrations/node-fetch';\nimport { getAutoPerformanceIntegrations } from '../integrations/tracing';\nimport type { NodeOptions } from '../types';\nimport {\n isDiagnosticsChannelInjectionEnabled,\n resolveDiagnosticsChannelInjection,\n} from './diagnosticsChannelInjection';\nimport { initOpenTelemetry } from './initOtel';\n\n/**\n * Get default integrations, excluding performance.\n */\nexport function getDefaultIntegrationsWithoutPerformance(): Integration[] {\n const nodeCoreIntegrations = getNodeCoreDefaultIntegrations();\n\n // Filter out the node-core HTTP and NodeFetch integrations and replace them with Node SDK's composite versions\n return nodeCoreIntegrations\n .filter(integration => integration.name !== 'Http' && integration.name !== 'NodeFetch')\n .concat(httpIntegration(), nativeNodeFetchIntegration());\n}\n\n/** Get the default integrations for the Node SDK. */\nexport function getDefaultIntegrations(options: Options): Integration[] {\n return [\n ...getDefaultIntegrationsWithoutPerformance(),\n // We only add performance integrations if tracing is enabled\n // Note that this means that without tracing enabled, e.g. `expressIntegration()` will not be added\n // This means that generally request isolation will work (because that is done by httpIntegration)\n // But `transactionName` will not be set automatically\n ...(hasSpansEnabled(options) ? getAutoPerformanceIntegrations() : []),\n ];\n}\n\n/**\n * When the app opted into diagnostics-channel injection (via\n * `experimentalUseDiagnosticsChannelInjection()`) AND span recording is enabled, drop the OTel\n * integrations that have a channel-based replacement and append the FULL channel-integration set,\n * so the two never both instrument the same library. Otherwise returns `integrations` unchanged.\n *\n * `_init` applies the same swap to `defaultIntegrations`, but SDKs that seed their integrations\n * through the user `integrations` option instead (e.g. the `@sentry/aws-serverless` Lambda layer\n * entry) never hit that path, so they call this directly from their own `getDefaultIntegrations`.\n *\n * Note the asymmetry: appended channel integrations are not limited to ones whose OTel counterpart\n * was in `integrations`. For `@sentry/node` that makes no difference (the incoming list carries the\n * whole OTel performance set), but a caller with a narrower list (e.g. `@sentry/aws-serverless`)\n * gains channel coverage for libraries it never shipped OTel integrations for. Channel integrations\n * produce nothing but spans, so this is gated on span recording. Exported so SDKs that build their\n * own default-integration set can apply the same logic instead of duplicating it.\n */\nexport function applyDiagnosticsChannelInjectionIntegrations(\n integrations: Integration[],\n options: Options,\n): Integration[] {\n if (isDiagnosticsChannelInjectionEnabled() && hasSpansEnabled(options)) {\n const diagnosticsChannelInjection = resolveDiagnosticsChannelInjection();\n if (diagnosticsChannelInjection) {\n const replaced = new Set(diagnosticsChannelInjection.replacedOtelIntegrationNames);\n return [...integrations.filter(i => !replaced.has(i.name)), ...diagnosticsChannelInjection.integrations];\n }\n }\n return integrations;\n}\n\n/**\n * Initialize Sentry for Node.\n */\nexport function init(options: NodeOptions | undefined = {}): NodeClient | undefined {\n return _init(options, getDefaultIntegrations);\n}\n\n/**\n * Internal initialization function.\n */\nfunction _init(\n options: NodeOptions | undefined = {},\n getDefaultIntegrationsImpl: (options: Options) => Integration[],\n): NodeClient | undefined {\n applySdkMetadata(options, 'node');\n\n // EXPERIMENTAL: diagnostics-channel injection, opted into via\n // `experimentalUseDiagnosticsChannelInjection()`. Gated on span recording to\n // match the OTel integrations it replaces. With tracing off there are no\n // channel subscribers, so injecting is pointless work.\n const diagnosticsChannelInjection =\n isDiagnosticsChannelInjectionEnabled() && hasSpansEnabled(options)\n ? resolveDiagnosticsChannelInjection()\n : undefined;\n\n // Install the channel-injection hooks as early as possible, before the app\n // imports its instrumented modules.\n if (diagnosticsChannelInjection) {\n diagnosticsChannelInjection.register();\n }\n\n // Only use Node SDK defaults if none provided.\n let defaultIntegrations = options.defaultIntegrations ?? getDefaultIntegrationsImpl(options);\n\n // When opted into diagnostics-channel injection, swap the channel-based\n // integrations in place of their OTel equivalents so the two don't both\n // instrument the same library. Done here (rather than in\n // `getDefaultIntegrations`) so it also covers framework SDKs (e.g.\n // `@sentry/nestjs`) that pass their own `defaultIntegrations` array.\n //\n // Only when there's a non-empty default set to swap:\n // `defaultIntegrations: false` (not an array) and `[]` /\n // `initWithoutDefaultIntegrations()` (explicitly no defaults) are left\n // untouched, as appending channel integrations there would resurrect\n // defaults the caller opted out of.\n if (diagnosticsChannelInjection && Array.isArray(defaultIntegrations) && defaultIntegrations.length > 0) {\n const replaced = new Set(diagnosticsChannelInjection.replacedOtelIntegrationNames);\n defaultIntegrations = [\n ...defaultIntegrations.filter(integration => !replaced.has(integration.name)),\n ...diagnosticsChannelInjection.integrations,\n ];\n }\n\n const client = initNodeCore({\n ...options,\n defaultIntegrations,\n });\n\n // Add Node SDK specific OpenTelemetry setup\n if (client && !options.skipOpenTelemetrySetup) {\n initOpenTelemetry(client, {\n spanProcessors: options.openTelemetrySpanProcessors,\n });\n validateOpenTelemetrySetup();\n }\n\n // Warn about missing or doubled channel injection. Runs after the client\n // is created so the debug logger is enabled and the warning is emitted.\n if (diagnosticsChannelInjection) {\n diagnosticsChannelInjection.detect();\n }\n\n return client;\n}\n\n/**\n * Initialize Sentry for Node, without any integrations added by default.\n */\nexport function initWithoutDefaultIntegrations(options: NodeOptions | undefined = {}): NodeClient | undefined {\n return _init(options, () => []);\n}\n"],"names":["getNodeCoreDefaultIntegrations","initNodeCore"],"mappings":";;;;;;;;AAqBO,SAAS,wCAAA,GAA0D;AACxE,EAAA,MAAM,uBAAuBA,wBAAA,EAA+B;AAG5D,EAAA,OAAO,oBAAA,CACJ,MAAA,CAAO,CAAA,WAAA,KAAe,WAAA,CAAY,SAAS,MAAA,IAAU,WAAA,CAAY,IAAA,KAAS,WAAW,CAAA,CACrF,MAAA,CAAO,eAAA,EAAgB,EAAG,4BAA4B,CAAA;AAC3D;AAGO,SAAS,uBAAuB,OAAA,EAAiC;AACtE,EAAA,OAAO;AAAA,IACL,GAAG,wCAAA,EAAyC;AAAA;AAAA;AAAA;AAAA;AAAA,IAK5C,GAAI,eAAA,CAAgB,OAAO,CAAA,GAAI,8BAAA,KAAmC;AAAC,GACrE;AACF;AAmBO,SAAS,4CAAA,CACd,cACA,OAAA,EACe;AACf,EAAA,IAAI,oCAAA,EAAqC,IAAK,eAAA,CAAgB,OAAO,CAAA,EAAG;AACtE,IAAA,MAAM,8BAA8B,kCAAA,EAAmC;AACvE,IAAA,IAAI,2BAAA,EAA6B;AA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AGD,EAAA,IAAI,MAAA,IAAU,CAAC,OAAA,CAAQ,sBAAA,EAAwB;AAC7C,IAAA,iBAAA,CAAkB,MAAA,EAAQ;AAAA,MACxB,gBAAgB,OAAA,CAAQ;AAAA,KACzB,CAAA;AACD,IAAA,0BAAA,EAA2B;AAAA,EAC7B;AAIA,EAAA,IAAI,2BAAA,EAA6B;AAC/B,IAAA,2BAAA,CAA4B,MAAA,EAAO;AAAA,EACrC;AAEA,EAAA,OAAO,MAAA;AACT;AAKO,SAAS,8BAAA,CAA+B,OAAA,GAAmC,EAAC,EAA2B;AAC5G,EAAA,OAAO,KAAA,CAAM,OAAA,EAAS,MAAM,EAAE,CAAA;AAChC;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { propagation, context, trace } from '@opentelemetry/api';
|
|
2
2
|
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
|
|
3
3
|
import { debug, hasSpanStreamingEnabled } from '@sentry/core';
|
|
4
4
|
import { setupOpenTelemetryLogger, SentryContextManager, initializeEsmLoader } from '@sentry/node-core';
|
|
@@ -7,6 +7,30 @@ import { DEBUG_BUILD } from '../debug-build.js';
|
|
|
7
7
|
import { getOpenTelemetryInstrumentationToPreload } from '../integrations/tracing/index.js';
|
|
8
8
|
|
|
9
9
|
const MAX_MAX_SPAN_WAIT_DURATION = 1e6;
|
|
10
|
+
const OTEL_API_GLOBAL_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api.1");
|
|
11
|
+
function registerGlobalTracerProvider(provider) {
|
|
12
|
+
if (trace.setGlobalTracerProvider(provider)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const otelGlobal = globalThis;
|
|
16
|
+
const registry = otelGlobal[OTEL_API_GLOBAL_KEY];
|
|
17
|
+
if (registry && !registry.trace) {
|
|
18
|
+
DEBUG_BUILD && debug.warn(
|
|
19
|
+
"Replaced a pre-existing OpenTelemetry API registry that was created by a different @opentelemetry/api version and would have blocked tracing. If you want to manage OpenTelemetry yourself, set `skipOpenTelemetrySetup: true` in `Sentry.init()`."
|
|
20
|
+
);
|
|
21
|
+
otelGlobal[OTEL_API_GLOBAL_KEY] = void 0;
|
|
22
|
+
if (!trace.setGlobalTracerProvider(provider)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const recreatedRegistry = otelGlobal[OTEL_API_GLOBAL_KEY];
|
|
26
|
+
if (recreatedRegistry) {
|
|
27
|
+
const { propagation: _propagation, context: _context, ...carriedOverSlots } = registry;
|
|
28
|
+
otelGlobal[OTEL_API_GLOBAL_KEY] = { ...carriedOverSlots, ...recreatedRegistry };
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
10
34
|
function initOpenTelemetry(client, options = {}) {
|
|
11
35
|
if (client.getOptions().debug) {
|
|
12
36
|
setupOpenTelemetryLogger();
|
|
@@ -55,7 +79,7 @@ function setupOtel(client, options = {}) {
|
|
|
55
79
|
...options.spanProcessors || []
|
|
56
80
|
]
|
|
57
81
|
});
|
|
58
|
-
|
|
82
|
+
registerGlobalTracerProvider(provider);
|
|
59
83
|
propagation.setGlobalPropagator(new SentryPropagator());
|
|
60
84
|
const ctxManager = new SentryContextManager();
|
|
61
85
|
context.setGlobalContextManager(ctxManager);
|
|
@@ -63,7 +87,7 @@ function setupOtel(client, options = {}) {
|
|
|
63
87
|
}
|
|
64
88
|
function setupSentryTracerProvider(client) {
|
|
65
89
|
const provider = new SentryTracerProvider({ resource: getSentryResource("node") });
|
|
66
|
-
if (!
|
|
90
|
+
if (!registerGlobalTracerProvider(provider)) {
|
|
67
91
|
DEBUG_BUILD && debug.warn(
|
|
68
92
|
"Could not register SentryTracerProvider because another OpenTelemetry tracer provider is already registered."
|
|
69
93
|
);
|