autotel-mongoose 0.0.1

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts","../src/types.ts","../src/statement.ts","../src/instrumentation.ts"],"names":["wrappedHook","trace"],"mappings":";;;;;;AAEO,IAAM,kBAAA,GAAqB,eAAA;AAC3B,IAAM,sBAAA,GAAyB,mBAAA;AAC/B,IAAM,mBAAA,GAAsB,gBAAA;AAC5B,IAAM,uBAAA,GAA0B,oBAAA;AAChC,IAAM,iBAAA,GAAoB,cAAA;AAC1B,IAAM,mBAAA,GAAsB,gBAAA;AAC5B,IAAM,gBAAA,GAAmB,aAAA;AAEzB,IAAM,4BAAA,GAA+B,SAAA;;;AC+DrC,IAAM,mBAAA,GAAsB,kBAAA;ACnE5B,SAAS,iBAAA,CACd,YACA,OAAA,EACQ;AACR,EAAA,OAAO,IAAA,CAAK,UAAU,OAAO,CAAA;AAC/B;AAWO,SAAS,uBAAuB,MAAA,EAGhB;AAErB,EAAA,IAAI,MAAA,CAAO,0BAA0B,KAAA,EAAO;AAC1C,IAAA,OAAO,MAAiB;AACtB,MAAA;AAAA,IACF,CAAA;AAAA,EACF;AAEA,EAAA,MAAM,aACJ,OAAO,MAAA,CAAO,qBAAA,KAA0B,UAAA,GACpC,OAAO,qBAAA,GACP,iBAAA;AAGN,EAAA,IAAI,MAAA;AACJ,EAAA,IACE,MAAA,CAAO,iBAAA,KAAsB,KAAA,IAC7B,MAAA,CAAO,sBAAsB,MAAA,EAC7B;AACA,IAAA,MAAA,GAAS,oBAAA,CAAqB,OAAO,iBAAiB,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,CACL,WACA,OAAA,KACuB;AACvB,IAAA,MAAM,GAAA,GAAM,UAAA,CAAW,SAAA,EAAW,OAAO,CAAA;AACzC,IAAA,IAAI,QAAQ,MAAA,EAAW;AACrB,MAAA,OAAO,MAAA;AAAA,IACT;AACA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AClC,IAAA,IAAI,CAAA,CAAE,KAAA,CAAM,MAAM,CAAA,EAAG;AACnB,MAAA,gBAAA;AAAA,QACE,CAAA,CAAE,KAAA;AAAA,QACF,MAAA;AAAA,QACA,MAAA;AAAA,QACA,CAAC,KAAA,KAAe;AACd,UAAA,IAAI;AACF,YAAA,OAAO,MAAM,UAAA,EAAY,cAAA;AAAA,UAC3B,CAAA,CAAA,MAAQ;AACN,YAAA;AAAA,UACF;AAAA,QACF,CAAA;AAAA,QACA,CAAC,UAAe,KAAA,CAAM,SAAA;AAAA,QACtB,MAAA;AAAA,QACA,WAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF;AAAA,EACF;AAGA,EAAA,MAAM,gBAAA,GAAmB;AAAA,IACvB,UAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,KAAA,MAAW,UAAU,gBAAA,EAAkB;AACrC,IAAA,IAAI,CAAA,CAAE,KAAA,EAAO,SAAA,GAAY,MAAM,CAAA,EAAG;AAChC,MAAA,mBAAA,CAAoB,CAAA,CAAE,KAAA,CAAM,SAAA,EAAW,MAAM,CAAA;AAAA,IAC/C;AAAA,EACF;AAEA,EAAA,CAAA,CAAE,iBAAiB,CAAA,GAAI,IAAA;AACvB,EAAA,OAAO,QAAA;AACT","file":"index.js","sourcesContent":["// Stable OTel semantic conventions only — no deprecated attributes.\n\nexport const ATTR_DB_QUERY_TEXT = 'db.query.text' as const;\nexport const ATTR_DB_OPERATION_NAME = 'db.operation.name' as const;\nexport const ATTR_DB_SYSTEM_NAME = 'db.system.name' as const;\nexport const ATTR_DB_COLLECTION_NAME = 'db.collection.name' as const;\nexport const ATTR_DB_NAMESPACE = 'db.namespace' as const;\nexport const ATTR_SERVER_ADDRESS = 'server.address' as const;\nexport const ATTR_SERVER_PORT = 'server.port' as const;\n\nexport const DB_SYSTEM_NAME_VALUE_MONGODB = 'mongodb' as const;\n","import type { AttributeRedactorPreset, AttributeRedactorConfig } from 'autotel';\n\n/**\n * Payload passed to the dbStatementSerializer.\n * Shape matches @opentelemetry/instrumentation-mongodb for migration compatibility.\n */\nexport interface SerializerPayload {\n condition?: Record<string, unknown>;\n updates?: Record<string, unknown>;\n options?: Record<string, unknown>;\n fields?: Record<string, unknown>;\n aggregatePipeline?: unknown[];\n document?: unknown;\n documents?: unknown[];\n operations?: unknown[];\n}\n\n/**\n * Configuration for Mongoose instrumentation.\n */\nexport interface InstrumentMongooseConfig {\n /** Database name for spans (sets db.namespace). */\n dbName?: string;\n\n /** MongoDB server hostname (sets server.address). */\n peerName?: string;\n\n /** MongoDB server port (sets server.port, default: 27017). */\n peerPort?: number;\n\n /** Custom tracer name (default: \"autotel-mongoose\"). */\n tracerName?: string;\n\n /** Capture collection names in spans (default: true). */\n captureCollectionName?: boolean;\n\n /** Instrument Schema hooks — pre/post save, validate, etc. (default: false). */\n instrumentHooks?: boolean;\n\n /**\n * Serializer for db.query.text attribute.\n * Default: JSON.stringify of the payload.\n * Pass false to disable statement capture entirely.\n */\n dbStatementSerializer?:\n | ((operation: string, payload: SerializerPayload) => string | undefined)\n | false;\n\n /**\n * Redactor applied to serialized statements before setting db.query.text.\n * Default: 'default' preset (emails, phones, SSNs, credit cards).\n * Pass a preset name, custom config, or false to disable redaction.\n */\n statementRedactor?: AttributeRedactorPreset | AttributeRedactorConfig | false;\n}\n\n/**\n * Resolved config with all defaults applied.\n * @internal\n */\nexport interface ResolvedConfig {\n dbName: string;\n peerName: string;\n peerPort: number;\n tracerName: string;\n captureCollectionName: boolean;\n instrumentHooks: boolean;\n dbStatementSerializer:\n | ((operation: string, payload: SerializerPayload) => string | undefined)\n | false;\n statementRedactor: AttributeRedactorPreset | AttributeRedactorConfig | false;\n}\n\nexport const DEFAULT_TRACER_NAME = 'autotel-mongoose';\n","import { createStringRedactor, type StringRedactor } from 'autotel';\nimport type { SerializerPayload, InstrumentMongooseConfig } from './types';\n\n/**\n * Default serializer — JSON.stringify of the payload.\n */\nexport function defaultSerializer(\n _operation: string,\n payload: SerializerPayload,\n): string {\n return JSON.stringify(payload);\n}\n\nexport type StatementCaptureFn = (\n operation: string,\n payload: SerializerPayload,\n) => string | undefined;\n\n/**\n * Composes the serializer and redactor into a single capture function.\n * Returns undefined if statement capture is disabled.\n */\nexport function createStatementCapture(config: {\n dbStatementSerializer: InstrumentMongooseConfig['dbStatementSerializer'];\n statementRedactor: InstrumentMongooseConfig['statementRedactor'];\n}): StatementCaptureFn {\n // Statement capture disabled\n if (config.dbStatementSerializer === false) {\n return (): undefined => {\n return;\n };\n }\n\n const serializer =\n typeof config.dbStatementSerializer === 'function'\n ? config.dbStatementSerializer\n : defaultSerializer;\n\n // Build redactor (or no-op)\n let redact: StringRedactor | undefined;\n if (\n config.statementRedactor !== false &&\n config.statementRedactor !== undefined\n ) {\n redact = createStringRedactor(config.statementRedactor);\n }\n\n return (\n operation: string,\n payload: SerializerPayload,\n ): string | undefined => {\n const raw = serializer(operation, payload);\n if (raw === undefined) {\n return undefined;\n }\n return redact ? redact(raw) : raw;\n };\n}\n","// Note: `any` is only used for dynamic method wrapping on runtime objects.\n// Type-safe interfaces are used for all public APIs.\n// Mongoose is a devDependency so we type-check against the real API; consumers use the peer.\n\nimport type { Mongoose } from 'mongoose';\nimport { otelTrace as trace, SpanKind } from 'autotel';\nimport type { Span, Tracer } from 'autotel';\nimport {\n runWithSpan,\n finalizeSpan,\n getActiveSpan,\n} from 'autotel/trace-helpers';\n\nimport {\n ATTR_DB_SYSTEM_NAME,\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_COLLECTION_NAME,\n ATTR_DB_NAMESPACE,\n ATTR_DB_QUERY_TEXT,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n DB_SYSTEM_NAME_VALUE_MONGODB,\n} from './constants';\nimport type {\n InstrumentMongooseConfig,\n ResolvedConfig,\n SerializerPayload,\n} from './types';\nimport { DEFAULT_TRACER_NAME } from './types';\nimport {\n createStatementCapture,\n defaultSerializer,\n type StatementCaptureFn,\n} from './statement';\n\nconst INSTRUMENTED_FLAG = '__autotelMongooseInstrumented' as const;\nconst WRAPPED_HOOK_FLAG = '__autotelWrappedHook' as const;\n\n/**\n * Symbol used to store the parent span on Query/Aggregate objects.\n * This preserves context across chainable query methods.\n */\nexport const _STORED_PARENT_SPAN: unique symbol = Symbol('stored-parent-span');\n\n// ---------------------------------------------------------------------------\n// Span creation\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a span for a Mongoose operation.\n * Note: db.query.text is NOT set here — callers set it after payload extraction.\n */\nfunction createSpan(\n tracer: Tracer,\n operation: string,\n modelName: string | undefined,\n collectionName: string | undefined,\n config: ResolvedConfig,\n): Span {\n const spanName = collectionName\n ? `${operation} ${collectionName}`\n : modelName\n ? `${operation} ${modelName}`\n : `mongoose.${operation}`;\n\n const attributes: Record<string, any> = {\n [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_MONGODB,\n [ATTR_DB_OPERATION_NAME]: operation,\n };\n\n if (collectionName && config.captureCollectionName) {\n attributes[ATTR_DB_COLLECTION_NAME] = collectionName;\n }\n if (config.dbName) {\n attributes[ATTR_DB_NAMESPACE] = config.dbName;\n }\n if (config.peerName) {\n attributes[ATTR_SERVER_ADDRESS] = config.peerName;\n }\n if (config.peerPort) {\n attributes[ATTR_SERVER_PORT] = config.peerPort;\n }\n\n return tracer.startSpan(spanName, { kind: SpanKind.CLIENT, attributes });\n}\n\n// ---------------------------------------------------------------------------\n// Wrapper helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Wraps Model methods that return Query objects (find, findOne, findById,\n * findOneAndUpdate, findOneAndDelete, findOneAndReplace, deleteOne, deleteMany,\n * updateOne, updateMany, countDocuments, estimatedDocumentCount).\n *\n * Creates span FIRST, calls original, extracts payload from the returned Query,\n * sets db.query.text AFTER extraction, then wraps exec() to finalize span.\n */\nfunction wrapQueryReturningMethod(\n target: any,\n methodName: string,\n operation: string,\n getCollectionName: (obj: any) => string | undefined,\n getModelName: (obj: any) => string | undefined,\n tracer: Tracer,\n config: ResolvedConfig,\n captureStatement: StatementCaptureFn,\n): void {\n const original = target[methodName];\n if (typeof original !== 'function') {\n return;\n }\n\n target[methodName] = function instrumented(this: any, ...args: any[]): any {\n const collectionName = getCollectionName(this);\n const modelName = getModelName(this);\n const span = createSpan(\n tracer,\n operation,\n modelName,\n collectionName,\n config,\n );\n\n return runWithSpan(span, () => {\n try {\n const result = original.apply(this, args);\n\n // Extract payload from the returned Query object\n if (result && typeof result.exec === 'function') {\n try {\n const payload: SerializerPayload = {};\n if (typeof result.getFilter === 'function') {\n payload.condition = result.getFilter();\n }\n if (result._update !== undefined) {\n payload.updates = result._update;\n }\n if (typeof result.getOptions === 'function') {\n payload.options = result.getOptions();\n }\n if (result._fields !== undefined) {\n payload.fields = result._fields;\n }\n const statementText = captureStatement(operation, payload);\n if (statementText) {\n span.setAttribute(ATTR_DB_QUERY_TEXT, statementText);\n }\n } catch {\n // Ignore errors in payload extraction\n }\n\n // Wrap exec() to finalize span\n const originalExec = result.exec.bind(result);\n result.exec = function wrappedExec(): Promise<any> {\n try {\n const execPromise = originalExec();\n return Promise.resolve(execPromise)\n .then((value: any) => {\n finalizeSpan(span);\n return value;\n })\n .catch((error: unknown) => {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n });\n } catch (error) {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n }\n };\n\n return result; // Return Query, not Promise\n }\n\n // Fallback for unexpected non-query results\n finalizeSpan(span);\n return result;\n } catch (error) {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n }\n });\n };\n}\n\n/**\n * Wraps Model static methods (create, insertMany, aggregate, bulkWrite).\n *\n * Builds payload from args BEFORE calling original (args are available\n * immediately), creates span, sets db.query.text, calls original, then wraps\n * exec() or promise for span finalization.\n */\nfunction wrapStaticMethod(\n target: any,\n methodName: string,\n operation: string,\n getCollectionName: (obj: any) => string | undefined,\n getModelName: (obj: any) => string | undefined,\n tracer: Tracer,\n config: ResolvedConfig,\n captureStatement: StatementCaptureFn,\n): void {\n const original = target[methodName];\n if (typeof original !== 'function') {\n return;\n }\n\n target[methodName] = function instrumented(this: any, ...args: any[]): any {\n const collectionName = getCollectionName(this);\n const modelName = getModelName(this);\n\n // Build payload from args before calling original\n const payload: SerializerPayload = {};\n try {\n switch (operation) {\n case 'create': {\n payload.document = args[0];\n break;\n }\n case 'insertMany': {\n payload.documents = args[0];\n break;\n }\n case 'aggregate': {\n payload.aggregatePipeline = args[0];\n break;\n }\n case 'bulkWrite': {\n payload.operations = args[0];\n break;\n }\n default: {\n break;\n }\n }\n } catch {\n // Ignore errors in payload extraction\n }\n\n const span = createSpan(\n tracer,\n operation,\n modelName,\n collectionName,\n config,\n );\n\n try {\n const statementText = captureStatement(operation, payload);\n if (statementText) {\n span.setAttribute(ATTR_DB_QUERY_TEXT, statementText);\n }\n } catch {\n // Ignore serialization errors\n }\n\n return runWithSpan(span, () => {\n try {\n const result = original.apply(this, args);\n\n // If result has exec() (e.g., aggregate), wrap it\n if (result && typeof result.exec === 'function') {\n const originalExec = result.exec.bind(result);\n result.exec = function wrappedExec(): Promise<any> {\n try {\n const execPromise = originalExec();\n return Promise.resolve(execPromise)\n .then((value: any) => {\n finalizeSpan(span);\n return value;\n })\n .catch((error: unknown) => {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n });\n } catch (error) {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n }\n };\n return result;\n }\n\n // For direct promise results (e.g., create, insertMany)\n if (result && typeof result.then === 'function') {\n return Promise.resolve(result as Promise<any>)\n .then((value) => {\n finalizeSpan(span);\n return value;\n })\n .catch((error: unknown) => {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n });\n }\n\n finalizeSpan(span);\n return result;\n } catch (error) {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n }\n });\n };\n}\n\n/**\n * Wraps Model instance methods (save, deleteOne on prototype).\n *\n * Extracts document via `this.toObject()` BEFORE calling original,\n * creates span, sets db.query.text, calls original, wraps promise\n * for span finalization.\n */\nfunction wrapInstanceMethod(\n target: any,\n methodName: string,\n operation: string,\n getCollectionName: (obj: any) => string | undefined,\n getModelName: (obj: any) => string | undefined,\n tracer: Tracer,\n config: ResolvedConfig,\n captureStatement: StatementCaptureFn,\n): void {\n const original = target[methodName];\n if (typeof original !== 'function') {\n return;\n }\n\n target[methodName] = function instrumented(this: any, ...args: any[]): any {\n const collectionName = getCollectionName(this);\n const modelName = getModelName(this);\n\n // Extract document before calling original\n const payload: SerializerPayload = {};\n try {\n if (typeof this.toObject === 'function') {\n payload.document = this.toObject();\n }\n } catch {\n // Ignore errors in document extraction\n }\n\n const span = createSpan(\n tracer,\n operation,\n modelName,\n collectionName,\n config,\n );\n\n try {\n const statementText = captureStatement(operation, payload);\n if (statementText) {\n span.setAttribute(ATTR_DB_QUERY_TEXT, statementText);\n }\n } catch {\n // Ignore serialization errors\n }\n\n return runWithSpan(span, () => {\n try {\n const result = original.apply(this, args);\n\n // Instance methods return promises\n if (result && typeof result.then === 'function') {\n return Promise.resolve(result as Promise<any>)\n .then((value) => {\n finalizeSpan(span);\n return value;\n })\n .catch((error: unknown) => {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n });\n }\n\n finalizeSpan(span);\n return result;\n } catch (error) {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n }\n });\n };\n}\n\n// ---------------------------------------------------------------------------\n// Chainable method wrapping (copied from original)\n// ---------------------------------------------------------------------------\n\n/**\n * Wraps chainable Query methods (populate, select, lean, etc.) to capture span context.\n */\nfunction wrapChainableMethod(target: any, methodName: string): void {\n const original = target[methodName];\n if (typeof original !== 'function') {\n return;\n }\n\n target[methodName] = function captureContext(this: any, ...args: any[]): any {\n const currentSpan = getActiveSpan();\n const result = original.apply(this, args);\n\n // Store parent span on returned Query for exec() calls\n if (result && typeof result.exec === 'function') {\n (result as any)[_STORED_PARENT_SPAN] = currentSpan;\n }\n\n return result;\n };\n}\n\n// ---------------------------------------------------------------------------\n// Schema hook instrumentation (copied from original, updated semconv)\n// ---------------------------------------------------------------------------\n\n/**\n * Patches Mongoose Schema hooks (pre/post) to automatically trace them.\n * Only wraps user-defined hooks, skipping Mongoose's internal hooks.\n */\nfunction patchSchemaHooks(\n Schema: any,\n tracer: Tracer,\n config: ResolvedConfig,\n): void {\n if (!Schema?.prototype) {\n return;\n }\n\n const HOOK_FLAG = '__autotelHookInstrumented' as const;\n if ((Schema.prototype as any)[HOOK_FLAG]) {\n return;\n }\n\n const originalPre = Schema.prototype.pre;\n if (typeof originalPre === 'function') {\n Schema.prototype.pre = function (hookName: string, ...args: any[]): any {\n const handler =\n typeof args[0] === 'function'\n ? args[0]\n : typeof args[1] === 'function'\n ? args[1]\n : null;\n\n // Only wrap user-defined hooks, skip Mongoose internals\n if (handler && !isMongooseInternalHook(handler)) {\n const wrapped = wrapHookHandler(\n handler,\n hookName,\n 'pre',\n tracer,\n config,\n );\n if (typeof args[0] === 'function') {\n args[0] = wrapped;\n } else if (typeof args[1] === 'function') {\n args[1] = wrapped;\n }\n }\n\n return Reflect.apply(originalPre, this, [hookName, ...args]);\n };\n }\n\n const originalPost = Schema.prototype.post;\n if (typeof originalPost === 'function') {\n Schema.prototype.post = function (hookName: string, ...args: any[]): any {\n const handler =\n typeof args[0] === 'function'\n ? args[0]\n : typeof args[1] === 'function'\n ? args[1]\n : null;\n\n // Only wrap user-defined hooks, skip Mongoose internals\n if (handler && !isMongooseInternalHook(handler)) {\n const wrapped = wrapHookHandler(\n handler,\n hookName,\n 'post',\n tracer,\n config,\n );\n if (typeof args[0] === 'function') {\n args[0] = wrapped;\n } else if (typeof args[1] === 'function') {\n args[1] = wrapped;\n }\n }\n\n return Reflect.apply(originalPost, this, [hookName, ...args]);\n };\n }\n\n (Schema.prototype as any)[HOOK_FLAG] = true;\n}\n\n/**\n * Detects if a hook handler is from Mongoose's internal code.\n * Skips private methods, known internal patterns, and functions with\n * Mongoose-internal source code signatures.\n *\n * Note: We intentionally allow anonymous functions because user-defined\n * hooks are often anonymous (e.g., `schema.pre('save', async function() {...})`).\n */\nfunction isMongooseInternalHook(handler: any): boolean {\n if (typeof handler !== 'function') {\n return false;\n }\n\n const funcName = handler.name || '';\n\n // Skip private/internal methods (starting with _ or $)\n if (funcName.startsWith('_') || funcName.startsWith('$')) {\n return true;\n }\n\n // Skip known Mongoose internal hook patterns by name\n const mongooseInternalNamePatterns = [\n 'shardingPlugin',\n 'mongooseInternalHook',\n 'noop',\n 'wrapped',\n 'bound ',\n ];\n\n if (\n mongooseInternalNamePatterns.some((pattern) => funcName.includes(pattern))\n ) {\n return true;\n }\n\n // Check function source for Mongoose-internal patterns\n // These patterns appear in Mongoose's auto-generated validation/transform hooks\n try {\n const source = handler.toString();\n const mongooseInternalSourcePatterns = [\n 'this.$__', // Mongoose internal document methods\n 'this.$isValid', // Mongoose validation\n 'this.$locals', // Mongoose local properties\n '_this.$__', // Mongoose internal with closure\n 'schema.s.hooks', // Mongoose hooks system\n 'kareem', // Mongoose's hooks library\n ];\n\n if (\n mongooseInternalSourcePatterns.some((pattern) => source.includes(pattern))\n ) {\n return true;\n }\n } catch {\n // If we can't get source, allow the hook through\n }\n\n return false;\n}\n\n/**\n * Wraps a hook handler to trace its execution.\n * Handles both callback-style (with next) and promise-style hooks.\n */\nfunction wrapHookHandler(\n handler: any,\n hookName: string,\n hookType: 'pre' | 'post',\n tracer: Tracer,\n config: ResolvedConfig,\n): any {\n if (typeof handler !== 'function') {\n return handler;\n }\n\n // Skip if already wrapped to prevent duplicate spans\n if ((handler as any)[WRAPPED_HOOK_FLAG]) {\n return handler;\n }\n\n const wrappedHook = function wrappedHook(this: any, ...args: any[]): any {\n let modelName: string | undefined;\n let collectionName: string | undefined;\n\n try {\n if (this.constructor?.modelName) {\n modelName = this.constructor.modelName;\n collectionName =\n this.constructor.collection?.collectionName || modelName;\n } else if (this.model?.modelName) {\n modelName = this.model.modelName;\n collectionName = this.model.collection?.collectionName || modelName;\n }\n } catch {\n // Ignore errors in extracting context\n }\n\n const spanName = collectionName\n ? `mongoose.${collectionName}.${hookType}.${hookName}`\n : `mongoose.hook.${hookType}.${hookName}`;\n\n const span = tracer.startSpan(spanName, { kind: SpanKind.INTERNAL });\n span.setAttribute('hook.type', hookType);\n span.setAttribute('hook.operation', hookName);\n if (modelName) {\n span.setAttribute('hook.model', modelName);\n }\n if (collectionName && config.captureCollectionName) {\n span.setAttribute(ATTR_DB_COLLECTION_NAME, collectionName);\n }\n span.setAttribute(ATTR_DB_SYSTEM_NAME, DB_SYSTEM_NAME_VALUE_MONGODB);\n if (config.dbName) {\n span.setAttribute(ATTR_DB_NAMESPACE, config.dbName);\n }\n\n return runWithSpan(span, () => {\n try {\n const result = handler.apply(this, args);\n\n if (result && typeof result.then === 'function') {\n return Promise.resolve(result as Promise<any>)\n .then((value) => {\n finalizeSpan(span);\n return value;\n })\n .catch((error: unknown) => {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n });\n }\n\n finalizeSpan(span);\n return result;\n } catch (error) {\n finalizeSpan(\n span,\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n }\n });\n };\n\n // Mark as wrapped to prevent double-wrapping\n (wrappedHook as any)[WRAPPED_HOOK_FLAG] = true;\n return wrappedHook;\n}\n\n// ---------------------------------------------------------------------------\n// Main instrumentation function\n// ---------------------------------------------------------------------------\n\n/**\n * Instruments Mongoose with OpenTelemetry tracing.\n *\n * Supports Mongoose 8+ with promise-based API only.\n * Patches Model methods, Query methods, and user-defined Schema hooks to create spans.\n *\n * **IMPORTANT:** Call `instrumentMongoose()` BEFORE defining schemas/models\n * to ensure hooks are automatically instrumented.\n *\n * @example\n * ```typescript\n * import mongoose from 'mongoose';\n * import { init } from 'autotel';\n * import { instrumentMongoose } from 'autotel-mongoose';\n *\n * init({ service: 'my-app' });\n *\n * // Call BEFORE defining schemas\n * instrumentMongoose(mongoose, { dbName: 'myapp' });\n *\n * const userSchema = new mongoose.Schema({ name: String });\n * const User = mongoose.model('User', userSchema);\n *\n * // All operations are automatically traced\n * await User.findOne({}).populate('posts').exec();\n * ```\n */\nexport function instrumentMongoose(\n mongoose: Mongoose,\n config?: InstrumentMongooseConfig,\n): Mongoose {\n if (!mongoose?.Model) {\n return mongoose;\n }\n\n const m = mongoose as any;\n if (m[INSTRUMENTED_FLAG]) {\n return mongoose;\n }\n\n // Resolve statement-related config separately (they accept undefined)\n const resolvedSerializer = config?.dbStatementSerializer;\n const resolvedRedactor = config?.statementRedactor ?? 'default';\n\n const finalConfig: ResolvedConfig = {\n dbName: config?.dbName || '',\n peerName: config?.peerName || '',\n peerPort: config?.peerPort || 27_017,\n tracerName: config?.tracerName || DEFAULT_TRACER_NAME,\n captureCollectionName: config?.captureCollectionName ?? true,\n instrumentHooks: config?.instrumentHooks ?? false,\n dbStatementSerializer:\n resolvedSerializer === false\n ? false\n : (resolvedSerializer ?? defaultSerializer),\n statementRedactor: resolvedRedactor,\n };\n\n const tracer = trace.getTracer(finalConfig.tracerName);\n\n // Create statement capture function\n const captureStatement = createStatementCapture({\n dbStatementSerializer: resolvedSerializer,\n statementRedactor: resolvedRedactor,\n });\n\n // Patch Schema hooks only if enabled\n if (m.Schema && finalConfig.instrumentHooks) {\n patchSchemaHooks(m.Schema, tracer, finalConfig);\n }\n\n // Helper functions\n const getModelCollectionName = (model: any) => {\n try {\n return model.collection?.collectionName || model.modelName;\n } catch {\n return;\n }\n };\n\n // Patch Query-returning methods on Model\n const queryMethods: Array<{ method: string; operation: string }> = [\n { method: 'find', operation: 'find' },\n { method: 'findOne', operation: 'findOne' },\n { method: 'findById', operation: 'findById' },\n { method: 'findOneAndUpdate', operation: 'findOneAndUpdate' },\n { method: 'findOneAndDelete', operation: 'findOneAndDelete' },\n { method: 'findOneAndReplace', operation: 'findOneAndReplace' },\n { method: 'deleteOne', operation: 'deleteOne' },\n { method: 'deleteMany', operation: 'deleteMany' },\n { method: 'updateOne', operation: 'updateOne' },\n { method: 'updateMany', operation: 'updateMany' },\n { method: 'countDocuments', operation: 'countDocuments' },\n { method: 'estimatedDocumentCount', operation: 'estimatedDocumentCount' },\n ];\n\n for (const { method, operation } of queryMethods) {\n wrapQueryReturningMethod(\n m.Model,\n method,\n operation,\n getModelCollectionName,\n (model: any) => model.modelName,\n tracer,\n finalConfig,\n captureStatement,\n );\n\n // Also patch chainable Query methods to capture context\n if (m.Query?.prototype?.[method]) {\n wrapChainableMethod(m.Query.prototype, method);\n }\n }\n\n // Patch Model instance methods\n const instanceMethods = ['save', 'deleteOne'];\n for (const method of instanceMethods) {\n if (m.Model.prototype[method]) {\n wrapInstanceMethod(\n m.Model.prototype,\n method,\n method,\n (doc: any) => {\n try {\n return (\n doc.constructor?.collection?.collectionName ||\n doc.constructor?.modelName\n );\n } catch {\n return;\n }\n },\n (doc: any) => {\n try {\n return doc.constructor?.modelName;\n } catch {\n return;\n }\n },\n tracer,\n finalConfig,\n captureStatement,\n );\n }\n }\n\n // Patch Model static methods\n const staticMethods = ['create', 'insertMany', 'aggregate', 'bulkWrite'];\n for (const method of staticMethods) {\n if (m.Model[method]) {\n wrapStaticMethod(\n m.Model,\n method,\n method,\n (model: any) => {\n try {\n return model.collection?.collectionName;\n } catch {\n return;\n }\n },\n (model: any) => model.modelName,\n tracer,\n finalConfig,\n captureStatement,\n );\n }\n }\n\n // Patch Query chainable methods\n const chainableMethods = [\n 'populate',\n 'select',\n 'lean',\n 'where',\n 'sort',\n 'limit',\n 'skip',\n ];\n for (const method of chainableMethods) {\n if (m.Query?.prototype?.[method]) {\n wrapChainableMethod(m.Query.prototype, method);\n }\n }\n\n m[INSTRUMENTED_FLAG] = true;\n return mongoose;\n}\n\n/**\n * Legacy export for backwards compatibility.\n * @deprecated Use `instrumentMongoose` instead.\n */\nexport class MongooseInstrumentation {\n constructor(private config?: InstrumentMongooseConfig) {}\n\n enable(mongoose: Mongoose): void {\n instrumentMongoose(mongoose, this.config);\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "autotel-mongoose",
3
+ "version": "0.0.1",
4
+ "description": "OpenTelemetry instrumentation for Mongoose with db.query.text capture and automatic redaction",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
24
+ "lint": "npx eslint src/**/*.ts",
25
+ "lint:fix": "npx eslint src/**/*.ts --fix",
26
+ "type-check": "tsc --noEmit",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
29
+ "test:integration": "vitest run --config vitest.integration.config.ts",
30
+ "clean": "rimraf dist",
31
+ "format": "prettier --write .",
32
+ "format:check": "prettier --check src/**/*.ts",
33
+ "quality": "pnpm type-check && pnpm test && pnpm lint && pnpm format:check && pnpm build"
34
+ },
35
+ "keywords": [
36
+ "opentelemetry",
37
+ "otel",
38
+ "mongoose",
39
+ "mongodb",
40
+ "observability",
41
+ "instrumentation",
42
+ "tracing",
43
+ "redaction"
44
+ ],
45
+ "author": "Jag Reehal <jag@jagreehal.com> (https://jagreehal.com)",
46
+ "license": "MIT",
47
+ "peerDependencies": {
48
+ "mongoose": ">=8.0.0",
49
+ "autotel": "*"
50
+ },
51
+ "devDependencies": {
52
+ "@opentelemetry/context-async-hooks": "^2.6.0",
53
+ "@opentelemetry/core": "^2.6.0",
54
+ "@opentelemetry/sdk-trace-node": "^2.6.0",
55
+ "@types/node": "^25.5.0",
56
+ "autotel": "workspace:*",
57
+ "mongodb-memory-server": "^10.4.0",
58
+ "mongoose": "^8.0.0",
59
+ "rimraf": "^6.1.3",
60
+ "tsup": "^8.5.1",
61
+ "typescript": "^5.9.3",
62
+ "vitest": "^4.1.0"
63
+ },
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "https://github.com/jagreehal/autotel",
67
+ "directory": "packages/autotel-mongoose"
68
+ },
69
+ "bugs": {
70
+ "url": "https://github.com/jagreehal/autotel/issues"
71
+ },
72
+ "homepage": "https://github.com/jagreehal/autotel/tree/main/packages/autotel-mongoose#readme"
73
+ }
@@ -0,0 +1,91 @@
1
+ import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
2
+ import mongoose from 'mongoose';
3
+ import { MongoMemoryServer } from 'mongodb-memory-server';
4
+ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
5
+ import {
6
+ InMemorySpanExporter,
7
+ SimpleSpanProcessor,
8
+ } from '@opentelemetry/sdk-trace-node';
9
+ import { instrumentMongoose } from './instrumentation';
10
+ import { ATTR_DB_QUERY_TEXT, ATTR_DB_OPERATION_NAME } from './constants';
11
+ import { canListenOnLoopback } from './test-support';
12
+ import type { SerializerPayload } from './types';
13
+
14
+ let mongod: MongoMemoryServer | undefined;
15
+ let exporter: InMemorySpanExporter;
16
+ let provider: NodeTracerProvider;
17
+
18
+ const userSchema = new mongoose.Schema({
19
+ name: { type: String, required: true },
20
+ email: { type: String, required: true },
21
+ });
22
+
23
+ let User: mongoose.Model<any>;
24
+
25
+ const supportsLocalServer = await canListenOnLoopback();
26
+
27
+ beforeAll(async () => {
28
+ exporter = new InMemorySpanExporter();
29
+ provider = new NodeTracerProvider({
30
+ spanProcessors: [new SimpleSpanProcessor(exporter)],
31
+ });
32
+ provider.register();
33
+
34
+ if (!supportsLocalServer) {
35
+ return;
36
+ }
37
+
38
+ mongod = await MongoMemoryServer.create();
39
+
40
+ // Custom serializer that only outputs the operation + condition keys
41
+ instrumentMongoose(mongoose, {
42
+ dbStatementSerializer: (op: string, payload: SerializerPayload) => {
43
+ const keys = payload.condition ? Object.keys(payload.condition) : [];
44
+ return `${op}(${keys.join(',')})`;
45
+ },
46
+ statementRedactor: false, // Disable redaction for this test
47
+ });
48
+
49
+ await mongoose.connect(mongod.getUri());
50
+ User = mongoose.model('User', userSchema);
51
+ });
52
+
53
+ afterAll(async () => {
54
+ await mongoose.disconnect();
55
+ await mongod?.stop();
56
+ await provider.shutdown();
57
+ });
58
+
59
+ beforeEach(() => exporter.reset());
60
+
61
+ describe('custom dbStatementSerializer', () => {
62
+ if (!supportsLocalServer) {
63
+ it.skip('skips custom mongoose integration tests when the environment cannot open local TCP ports', () => {});
64
+ return;
65
+ }
66
+
67
+ it('uses custom serializer output as db.query.text', async () => {
68
+ await User.find({ name: 'Alice', email: 'alice@example.com' }).exec();
69
+
70
+ const spans = exporter.getFinishedSpans();
71
+ const findSpan = spans.find(
72
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'find',
73
+ );
74
+ expect(findSpan).toBeDefined();
75
+ const queryText = findSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
76
+ expect(queryText).toBe('find(name,email)');
77
+ });
78
+
79
+ it('does not redact when statementRedactor is false', async () => {
80
+ await User.find({ email: 'alice@example.com' }).exec();
81
+
82
+ const spans = exporter.getFinishedSpans();
83
+ const findSpan = spans.find(
84
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'find',
85
+ );
86
+ const queryText = findSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
87
+ // Custom serializer doesn't include values, so email won't appear,
88
+ // but importantly the redactor is not running
89
+ expect(queryText).toBe('find(email)');
90
+ });
91
+ });
@@ -0,0 +1,79 @@
1
+ import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
2
+ import mongoose from 'mongoose';
3
+ import { MongoMemoryServer } from 'mongodb-memory-server';
4
+ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
5
+ import {
6
+ InMemorySpanExporter,
7
+ SimpleSpanProcessor,
8
+ } from '@opentelemetry/sdk-trace-node';
9
+ import { instrumentMongoose } from './instrumentation';
10
+ import { ATTR_DB_QUERY_TEXT, ATTR_DB_OPERATION_NAME } from './constants';
11
+ import { canListenOnLoopback } from './test-support';
12
+
13
+ let mongod: MongoMemoryServer | undefined;
14
+ let exporter: InMemorySpanExporter;
15
+ let provider: NodeTracerProvider;
16
+
17
+ const userSchema = new mongoose.Schema({
18
+ name: { type: String, required: true },
19
+ email: { type: String, required: true },
20
+ });
21
+
22
+ let User: mongoose.Model<any>;
23
+
24
+ const supportsLocalServer = await canListenOnLoopback();
25
+
26
+ beforeAll(async () => {
27
+ exporter = new InMemorySpanExporter();
28
+ // Use the same NodeTracerProvider pattern as the main integration test
29
+ provider = new NodeTracerProvider({
30
+ spanProcessors: [new SimpleSpanProcessor(exporter)],
31
+ });
32
+ provider.register();
33
+
34
+ if (!supportsLocalServer) {
35
+ return;
36
+ }
37
+
38
+ mongod = await MongoMemoryServer.create();
39
+ instrumentMongoose(mongoose, { dbStatementSerializer: false });
40
+ await mongoose.connect(mongod.getUri());
41
+ User = mongoose.model('User', userSchema);
42
+ });
43
+
44
+ afterAll(async () => {
45
+ await mongoose.disconnect();
46
+ await mongod?.stop();
47
+ await provider.shutdown();
48
+ });
49
+
50
+ beforeEach(() => exporter.reset());
51
+
52
+ describe('dbStatementSerializer: false', () => {
53
+ if (!supportsLocalServer) {
54
+ it.skip('skips disabled-config mongoose integration tests when the environment cannot open local TCP ports', () => {});
55
+ return;
56
+ }
57
+
58
+ it('does not set db.query.text on spans', async () => {
59
+ await User.find({ name: 'Alice' }).exec();
60
+
61
+ const spans = exporter.getFinishedSpans();
62
+ const findSpan = spans.find(
63
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'find',
64
+ );
65
+ expect(findSpan).toBeDefined();
66
+ expect(findSpan!.attributes[ATTR_DB_QUERY_TEXT]).toBeUndefined();
67
+ });
68
+
69
+ it('still creates spans with correct operation name', async () => {
70
+ await User.findOne({ name: 'Bob' }).exec();
71
+
72
+ const spans = exporter.getFinishedSpans();
73
+ const span = spans.find(
74
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'findOne',
75
+ );
76
+ expect(span).toBeDefined();
77
+ expect(span!.name).toBe('findOne users');
78
+ });
79
+ });
@@ -0,0 +1,11 @@
1
+ // Stable OTel semantic conventions only — no deprecated attributes.
2
+
3
+ export const ATTR_DB_QUERY_TEXT = 'db.query.text' as const;
4
+ export const ATTR_DB_OPERATION_NAME = 'db.operation.name' as const;
5
+ export const ATTR_DB_SYSTEM_NAME = 'db.system.name' as const;
6
+ export const ATTR_DB_COLLECTION_NAME = 'db.collection.name' as const;
7
+ export const ATTR_DB_NAMESPACE = 'db.namespace' as const;
8
+ export const ATTR_SERVER_ADDRESS = 'server.address' as const;
9
+ export const ATTR_SERVER_PORT = 'server.port' as const;
10
+
11
+ export const DB_SYSTEM_NAME_VALUE_MONGODB = 'mongodb' as const;
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export type { InstrumentMongooseConfig, SerializerPayload } from './types';
2
+
3
+ export { instrumentMongoose } from './instrumentation';
@@ -0,0 +1,202 @@
1
+ import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
2
+ import mongoose from 'mongoose';
3
+ import { MongoMemoryServer } from 'mongodb-memory-server';
4
+ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
5
+ import {
6
+ InMemorySpanExporter,
7
+ SimpleSpanProcessor,
8
+ } from '@opentelemetry/sdk-trace-node';
9
+ import { instrumentMongoose } from './instrumentation';
10
+ import { canListenOnLoopback } from './test-support';
11
+ import {
12
+ ATTR_DB_QUERY_TEXT,
13
+ ATTR_DB_OPERATION_NAME,
14
+ ATTR_DB_SYSTEM_NAME,
15
+ ATTR_DB_COLLECTION_NAME,
16
+ DB_SYSTEM_NAME_VALUE_MONGODB,
17
+ } from './constants';
18
+
19
+ let mongod: MongoMemoryServer | undefined;
20
+ let exporter: InMemorySpanExporter;
21
+ let provider: NodeTracerProvider;
22
+
23
+ interface IUser {
24
+ name: string;
25
+ email: string;
26
+ age: number;
27
+ }
28
+
29
+ const userSchema = new mongoose.Schema<IUser>({
30
+ name: { type: String, required: true },
31
+ email: { type: String, required: true },
32
+ age: { type: Number, required: true },
33
+ });
34
+
35
+ let User: mongoose.Model<IUser>;
36
+
37
+ const supportsLocalServer = await canListenOnLoopback();
38
+
39
+ beforeAll(async () => {
40
+ // Set up OTel
41
+ exporter = new InMemorySpanExporter();
42
+ provider = new NodeTracerProvider({
43
+ spanProcessors: [new SimpleSpanProcessor(exporter)],
44
+ });
45
+ provider.register();
46
+
47
+ if (!supportsLocalServer) {
48
+ return;
49
+ }
50
+
51
+ // Start in-memory MongoDB
52
+ mongod = await MongoMemoryServer.create();
53
+ const uri = mongod.getUri();
54
+
55
+ // Instrument BEFORE connecting
56
+ instrumentMongoose(mongoose);
57
+
58
+ await mongoose.connect(uri);
59
+ User = mongoose.model<IUser>('User', userSchema);
60
+ });
61
+
62
+ afterAll(async () => {
63
+ await mongoose.disconnect();
64
+ await mongod?.stop();
65
+ await provider.shutdown();
66
+ });
67
+
68
+ beforeEach(() => {
69
+ exporter.reset();
70
+ });
71
+
72
+ describe('instrumentMongoose integration', () => {
73
+ if (!supportsLocalServer) {
74
+ it.skip('skips mongoose integration tests when the environment cannot open local TCP ports', () => {});
75
+ return;
76
+ }
77
+
78
+ it('captures db.query.text for find operations', async () => {
79
+ await User.find({ name: 'Alice' }).exec();
80
+
81
+ const spans = exporter.getFinishedSpans();
82
+ const findSpan = spans.find(
83
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'find',
84
+ );
85
+ expect(findSpan).toBeDefined();
86
+ expect(findSpan!.attributes[ATTR_DB_SYSTEM_NAME]).toBe(
87
+ DB_SYSTEM_NAME_VALUE_MONGODB,
88
+ );
89
+ expect(findSpan!.attributes[ATTR_DB_COLLECTION_NAME]).toBe('users');
90
+
91
+ const queryText = findSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
92
+ expect(queryText).toBeDefined();
93
+ expect(queryText).toContain('Alice');
94
+ });
95
+
96
+ it('redacts PII in db.query.text by default', async () => {
97
+ await User.find({ email: 'alice@example.com' }).exec();
98
+
99
+ const spans = exporter.getFinishedSpans();
100
+ const findSpan = spans.find(
101
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'find',
102
+ );
103
+ const queryText = findSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
104
+ expect(queryText).not.toContain('alice@example.com');
105
+ expect(queryText).toContain('[REDACTED]');
106
+ });
107
+
108
+ it('captures db.query.text for save operations', async () => {
109
+ const user = new User({ name: 'Bob', email: 'bob@test.com', age: 30 });
110
+ await user.save();
111
+
112
+ const spans = exporter.getFinishedSpans();
113
+ const saveSpan = spans.find(
114
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'save',
115
+ );
116
+ expect(saveSpan).toBeDefined();
117
+ const queryText = saveSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
118
+ expect(queryText).toBeDefined();
119
+ expect(queryText).toContain('Bob');
120
+ // Email should be redacted
121
+ expect(queryText).not.toContain('bob@test.com');
122
+ });
123
+
124
+ it('captures db.query.text for aggregate operations', async () => {
125
+ await User.aggregate([
126
+ { $match: { age: { $gte: 18 } } },
127
+ { $group: { _id: '$name', count: { $sum: 1 } } },
128
+ ]).exec();
129
+
130
+ const spans = exporter.getFinishedSpans();
131
+ const aggSpan = spans.find(
132
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'aggregate',
133
+ );
134
+ expect(aggSpan).toBeDefined();
135
+ const queryText = aggSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
136
+ expect(queryText).toContain('$match');
137
+ expect(queryText).toContain('$group');
138
+ });
139
+
140
+ it('captures db.query.text for insertMany', async () => {
141
+ await User.insertMany([
142
+ { name: 'Charlie', email: 'c@test.com', age: 25 },
143
+ { name: 'Diana', email: 'd@test.com', age: 28 },
144
+ ]);
145
+
146
+ const spans = exporter.getFinishedSpans();
147
+ const insertSpan = spans.find(
148
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'insertMany',
149
+ );
150
+ expect(insertSpan).toBeDefined();
151
+ const queryText = insertSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
152
+ expect(queryText).toContain('Charlie');
153
+ expect(queryText).toContain('Diana');
154
+ });
155
+
156
+ it('captures db.query.text for bulkWrite', async () => {
157
+ await User.bulkWrite([
158
+ {
159
+ insertOne: {
160
+ document: { name: 'Eve', email: 'eve@test.com', age: 22 },
161
+ },
162
+ },
163
+ { updateOne: { filter: { name: 'Eve' }, update: { $set: { age: 23 } } } },
164
+ ]);
165
+
166
+ const spans = exporter.getFinishedSpans();
167
+ const bulkSpan = spans.find(
168
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'bulkWrite',
169
+ );
170
+ expect(bulkSpan).toBeDefined();
171
+ const queryText = bulkSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
172
+ expect(queryText).toContain('insertOne');
173
+ expect(queryText).toContain('updateOne');
174
+ expect(queryText).toContain('Eve');
175
+ });
176
+
177
+ it('captures db.query.text for updateOne with updates payload', async () => {
178
+ await User.updateOne({ name: 'Bob' }, { $set: { age: 31 } }).exec();
179
+
180
+ const spans = exporter.getFinishedSpans();
181
+ const updateSpan = spans.find(
182
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'updateOne',
183
+ );
184
+ expect(updateSpan).toBeDefined();
185
+ const queryText = updateSpan!.attributes[ATTR_DB_QUERY_TEXT] as string;
186
+ expect(queryText).toBeDefined();
187
+ // Should contain both condition and update fields
188
+ expect(queryText).toContain('Bob');
189
+ expect(queryText).toContain('$set');
190
+ });
191
+
192
+ it('uses stable semantic convention span names', async () => {
193
+ await User.findOne({ name: 'Alice' }).exec();
194
+
195
+ const spans = exporter.getFinishedSpans();
196
+ const span = spans.find(
197
+ (s) => s.attributes[ATTR_DB_OPERATION_NAME] === 'findOne',
198
+ );
199
+ // Stable convention: "operation collection"
200
+ expect(span!.name).toBe('findOne users');
201
+ });
202
+ });