autotel-plugins 0.19.2 → 0.19.3
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/README.md +2 -282
- package/dist/bigquery.d.cts +1 -1
- package/dist/bigquery.d.ts +1 -1
- package/dist/{constants-DoaoDYT8.d.cts → constants-DKKe2D25.d.cts} +1 -1
- package/dist/{constants-DoaoDYT8.d.ts → constants-DKKe2D25.d.ts} +1 -1
- package/dist/index.cjs +36 -879
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +51 -890
- package/dist/index.js.map +1 -1
- package/dist/kafka.d.cts +1 -1
- package/dist/kafka.d.ts +1 -1
- package/dist/rabbitmq.d.cts +1 -1
- package/dist/rabbitmq.d.ts +1 -1
- package/package.json +4 -28
- package/src/index.ts +2 -36
- package/dist/drizzle.cjs +0 -469
- package/dist/drizzle.cjs.map +0 -1
- package/dist/drizzle.d.cts +0 -194
- package/dist/drizzle.d.ts +0 -194
- package/dist/drizzle.js +0 -466
- package/dist/drizzle.js.map +0 -1
- package/dist/mongoose.cjs +0 -408
- package/dist/mongoose.cjs.map +0 -1
- package/dist/mongoose.d.cts +0 -79
- package/dist/mongoose.d.ts +0 -79
- package/dist/mongoose.js +0 -404
- package/dist/mongoose.js.map +0 -1
- package/src/drizzle/index.ts +0 -898
- package/src/mongoose/index.ts +0 -641
package/dist/mongoose.cjs
DELETED
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var autotel = require('autotel');
|
|
4
|
-
var traceHelpers = require('autotel/trace-helpers');
|
|
5
|
-
|
|
6
|
-
// src/mongoose/index.ts
|
|
7
|
-
|
|
8
|
-
// src/common/constants.ts
|
|
9
|
-
var SEMATTRS_DB_SYSTEM = "db.system";
|
|
10
|
-
var SEMATTRS_DB_OPERATION = "db.operation";
|
|
11
|
-
var SEMATTRS_DB_NAME = "db.name";
|
|
12
|
-
var SEMATTRS_DB_MONGODB_COLLECTION = "db.mongodb.collection";
|
|
13
|
-
var SEMATTRS_NET_PEER_NAME = "net.peer.name";
|
|
14
|
-
var SEMATTRS_NET_PEER_PORT = "net.peer.port";
|
|
15
|
-
var DEFAULT_TRACER_NAME = "autotel-plugins/mongoose";
|
|
16
|
-
var DEFAULT_DB_SYSTEM = "mongoose";
|
|
17
|
-
var INSTRUMENTED_FLAG = "__autotelMongooseInstrumented";
|
|
18
|
-
var WRAPPED_HOOK_FLAG = "__autotelWrappedHook";
|
|
19
|
-
var _STORED_PARENT_SPAN = /* @__PURE__ */ Symbol("stored-parent-span");
|
|
20
|
-
function createSpan(tracer, operation, modelName, collectionName, config) {
|
|
21
|
-
const spanName = collectionName ? `mongoose.${collectionName}.${operation}` : modelName ? `mongoose.${modelName}.${operation}` : `mongoose.${operation}`;
|
|
22
|
-
const attributes = {
|
|
23
|
-
[SEMATTRS_DB_SYSTEM]: DEFAULT_DB_SYSTEM,
|
|
24
|
-
[SEMATTRS_DB_OPERATION]: operation
|
|
25
|
-
};
|
|
26
|
-
if (collectionName && config.captureCollectionName) {
|
|
27
|
-
attributes[SEMATTRS_DB_MONGODB_COLLECTION] = collectionName;
|
|
28
|
-
}
|
|
29
|
-
if (config.dbName) {
|
|
30
|
-
attributes[SEMATTRS_DB_NAME] = config.dbName;
|
|
31
|
-
}
|
|
32
|
-
if (config.peerName) {
|
|
33
|
-
attributes[SEMATTRS_NET_PEER_NAME] = config.peerName;
|
|
34
|
-
}
|
|
35
|
-
if (config.peerPort) {
|
|
36
|
-
attributes[SEMATTRS_NET_PEER_PORT] = config.peerPort;
|
|
37
|
-
}
|
|
38
|
-
return tracer.startSpan(spanName, { kind: autotel.SpanKind.CLIENT, attributes });
|
|
39
|
-
}
|
|
40
|
-
function wrapQueryMethod(target, methodName, operation, getCollectionName, getModelName, tracer, config) {
|
|
41
|
-
const original = target[methodName];
|
|
42
|
-
if (typeof original !== "function") {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
target[methodName] = function instrumented(...args) {
|
|
46
|
-
const collectionName = getCollectionName(this);
|
|
47
|
-
const modelName = getModelName(this);
|
|
48
|
-
const span = createSpan(
|
|
49
|
-
tracer,
|
|
50
|
-
operation,
|
|
51
|
-
modelName,
|
|
52
|
-
collectionName,
|
|
53
|
-
config
|
|
54
|
-
);
|
|
55
|
-
return traceHelpers.runWithSpan(span, () => {
|
|
56
|
-
try {
|
|
57
|
-
const result = original.apply(this, args);
|
|
58
|
-
if (result && typeof result.exec === "function") {
|
|
59
|
-
const originalExec = result.exec.bind(result);
|
|
60
|
-
result.exec = function wrappedExec() {
|
|
61
|
-
try {
|
|
62
|
-
const execPromise = originalExec();
|
|
63
|
-
return Promise.resolve(execPromise).then((value) => {
|
|
64
|
-
traceHelpers.finalizeSpan(span);
|
|
65
|
-
return value;
|
|
66
|
-
}).catch((error) => {
|
|
67
|
-
traceHelpers.finalizeSpan(
|
|
68
|
-
span,
|
|
69
|
-
error instanceof Error ? error : new Error(String(error))
|
|
70
|
-
);
|
|
71
|
-
throw error;
|
|
72
|
-
});
|
|
73
|
-
} catch (error) {
|
|
74
|
-
traceHelpers.finalizeSpan(
|
|
75
|
-
span,
|
|
76
|
-
error instanceof Error ? error : new Error(String(error))
|
|
77
|
-
);
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
if (result && typeof result.then === "function") {
|
|
84
|
-
return Promise.resolve(result).then((value) => {
|
|
85
|
-
traceHelpers.finalizeSpan(span);
|
|
86
|
-
return value;
|
|
87
|
-
}).catch((error) => {
|
|
88
|
-
traceHelpers.finalizeSpan(
|
|
89
|
-
span,
|
|
90
|
-
error instanceof Error ? error : new Error(String(error))
|
|
91
|
-
);
|
|
92
|
-
throw error;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
traceHelpers.finalizeSpan(span);
|
|
96
|
-
return result;
|
|
97
|
-
} catch (error) {
|
|
98
|
-
traceHelpers.finalizeSpan(
|
|
99
|
-
span,
|
|
100
|
-
error instanceof Error ? error : new Error(String(error))
|
|
101
|
-
);
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function wrapChainableMethod(target, methodName) {
|
|
108
|
-
const original = target[methodName];
|
|
109
|
-
if (typeof original !== "function") {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
target[methodName] = function captureContext(...args) {
|
|
113
|
-
const currentSpan = traceHelpers.getActiveSpan();
|
|
114
|
-
const result = original.apply(this, args);
|
|
115
|
-
if (result && typeof result.exec === "function") {
|
|
116
|
-
result[_STORED_PARENT_SPAN] = currentSpan;
|
|
117
|
-
}
|
|
118
|
-
return result;
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function patchSchemaHooks(Schema, tracer, config) {
|
|
122
|
-
if (!Schema?.prototype) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const HOOK_FLAG = "__autotelHookInstrumented";
|
|
126
|
-
if (Schema.prototype[HOOK_FLAG]) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const originalPre = Schema.prototype.pre;
|
|
130
|
-
if (typeof originalPre === "function") {
|
|
131
|
-
Schema.prototype.pre = function(hookName, ...args) {
|
|
132
|
-
const handler = typeof args[0] === "function" ? args[0] : typeof args[1] === "function" ? args[1] : null;
|
|
133
|
-
if (handler && !isMongooseInternalHook(handler)) {
|
|
134
|
-
const wrapped = wrapHookHandler(
|
|
135
|
-
handler,
|
|
136
|
-
hookName,
|
|
137
|
-
"pre",
|
|
138
|
-
tracer,
|
|
139
|
-
config
|
|
140
|
-
);
|
|
141
|
-
if (typeof args[0] === "function") {
|
|
142
|
-
args[0] = wrapped;
|
|
143
|
-
} else if (typeof args[1] === "function") {
|
|
144
|
-
args[1] = wrapped;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return Reflect.apply(originalPre, this, [hookName, ...args]);
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
const originalPost = Schema.prototype.post;
|
|
151
|
-
if (typeof originalPost === "function") {
|
|
152
|
-
Schema.prototype.post = function(hookName, ...args) {
|
|
153
|
-
const handler = typeof args[0] === "function" ? args[0] : typeof args[1] === "function" ? args[1] : null;
|
|
154
|
-
if (handler && !isMongooseInternalHook(handler)) {
|
|
155
|
-
const wrapped = wrapHookHandler(
|
|
156
|
-
handler,
|
|
157
|
-
hookName,
|
|
158
|
-
"post",
|
|
159
|
-
tracer,
|
|
160
|
-
config
|
|
161
|
-
);
|
|
162
|
-
if (typeof args[0] === "function") {
|
|
163
|
-
args[0] = wrapped;
|
|
164
|
-
} else if (typeof args[1] === "function") {
|
|
165
|
-
args[1] = wrapped;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return Reflect.apply(originalPost, this, [hookName, ...args]);
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
Schema.prototype[HOOK_FLAG] = true;
|
|
172
|
-
}
|
|
173
|
-
function isMongooseInternalHook(handler) {
|
|
174
|
-
if (typeof handler !== "function") {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
const funcName = handler.name || "";
|
|
178
|
-
if (funcName.startsWith("_") || funcName.startsWith("$")) {
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
const mongooseInternalNamePatterns = [
|
|
182
|
-
"shardingPlugin",
|
|
183
|
-
"mongooseInternalHook",
|
|
184
|
-
"noop",
|
|
185
|
-
"wrapped",
|
|
186
|
-
"bound "
|
|
187
|
-
];
|
|
188
|
-
if (mongooseInternalNamePatterns.some((pattern) => funcName.includes(pattern))) {
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const source = handler.toString();
|
|
193
|
-
const mongooseInternalSourcePatterns = [
|
|
194
|
-
"this.$__",
|
|
195
|
-
// Mongoose internal document methods
|
|
196
|
-
"this.$isValid",
|
|
197
|
-
// Mongoose validation
|
|
198
|
-
"this.$locals",
|
|
199
|
-
// Mongoose local properties
|
|
200
|
-
"_this.$__",
|
|
201
|
-
// Mongoose internal with closure
|
|
202
|
-
"schema.s.hooks",
|
|
203
|
-
// Mongoose hooks system
|
|
204
|
-
"kareem"
|
|
205
|
-
// Mongoose's hooks library
|
|
206
|
-
];
|
|
207
|
-
if (mongooseInternalSourcePatterns.some((pattern) => source.includes(pattern))) {
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
} catch {
|
|
211
|
-
}
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
function wrapHookHandler(handler, hookName, hookType, tracer, config) {
|
|
215
|
-
if (typeof handler !== "function") {
|
|
216
|
-
return handler;
|
|
217
|
-
}
|
|
218
|
-
if (handler[WRAPPED_HOOK_FLAG]) {
|
|
219
|
-
return handler;
|
|
220
|
-
}
|
|
221
|
-
const wrappedHook = function wrappedHook2(...args) {
|
|
222
|
-
let modelName;
|
|
223
|
-
let collectionName;
|
|
224
|
-
try {
|
|
225
|
-
if (this.constructor?.modelName) {
|
|
226
|
-
modelName = this.constructor.modelName;
|
|
227
|
-
collectionName = this.constructor.collection?.collectionName || modelName;
|
|
228
|
-
} else if (this.model?.modelName) {
|
|
229
|
-
modelName = this.model.modelName;
|
|
230
|
-
collectionName = this.model.collection?.collectionName || modelName;
|
|
231
|
-
}
|
|
232
|
-
} catch {
|
|
233
|
-
}
|
|
234
|
-
const spanName = collectionName ? `mongoose.${collectionName}.${hookType}.${hookName}` : `mongoose.hook.${hookType}.${hookName}`;
|
|
235
|
-
const span = tracer.startSpan(spanName, { kind: autotel.SpanKind.INTERNAL });
|
|
236
|
-
span.setAttribute("hook.type", hookType);
|
|
237
|
-
span.setAttribute("hook.operation", hookName);
|
|
238
|
-
if (modelName) {
|
|
239
|
-
span.setAttribute("hook.model", modelName);
|
|
240
|
-
}
|
|
241
|
-
if (collectionName && config.captureCollectionName) {
|
|
242
|
-
span.setAttribute(SEMATTRS_DB_MONGODB_COLLECTION, collectionName);
|
|
243
|
-
}
|
|
244
|
-
span.setAttribute(SEMATTRS_DB_SYSTEM, DEFAULT_DB_SYSTEM);
|
|
245
|
-
if (config.dbName) {
|
|
246
|
-
span.setAttribute(SEMATTRS_DB_NAME, config.dbName);
|
|
247
|
-
}
|
|
248
|
-
return traceHelpers.runWithSpan(span, () => {
|
|
249
|
-
try {
|
|
250
|
-
const result = handler.apply(this, args);
|
|
251
|
-
if (result && typeof result.then === "function") {
|
|
252
|
-
return Promise.resolve(result).then((value) => {
|
|
253
|
-
traceHelpers.finalizeSpan(span);
|
|
254
|
-
return value;
|
|
255
|
-
}).catch((error) => {
|
|
256
|
-
traceHelpers.finalizeSpan(
|
|
257
|
-
span,
|
|
258
|
-
error instanceof Error ? error : new Error(String(error))
|
|
259
|
-
);
|
|
260
|
-
throw error;
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
traceHelpers.finalizeSpan(span);
|
|
264
|
-
return result;
|
|
265
|
-
} catch (error) {
|
|
266
|
-
traceHelpers.finalizeSpan(
|
|
267
|
-
span,
|
|
268
|
-
error instanceof Error ? error : new Error(String(error))
|
|
269
|
-
);
|
|
270
|
-
throw error;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
wrappedHook[WRAPPED_HOOK_FLAG] = true;
|
|
275
|
-
return wrappedHook;
|
|
276
|
-
}
|
|
277
|
-
function instrumentMongoose(mongoose, config) {
|
|
278
|
-
if (!mongoose?.Model) {
|
|
279
|
-
return mongoose;
|
|
280
|
-
}
|
|
281
|
-
const m = mongoose;
|
|
282
|
-
if (m[INSTRUMENTED_FLAG]) {
|
|
283
|
-
return mongoose;
|
|
284
|
-
}
|
|
285
|
-
const finalConfig = {
|
|
286
|
-
dbName: config?.dbName || "",
|
|
287
|
-
peerName: config?.peerName || "",
|
|
288
|
-
peerPort: config?.peerPort || 27017,
|
|
289
|
-
tracerName: config?.tracerName || DEFAULT_TRACER_NAME,
|
|
290
|
-
captureCollectionName: config?.captureCollectionName ?? true,
|
|
291
|
-
instrumentHooks: config?.instrumentHooks ?? false
|
|
292
|
-
};
|
|
293
|
-
const tracer = autotel.otelTrace.getTracer(finalConfig.tracerName);
|
|
294
|
-
if (m.Schema && finalConfig.instrumentHooks) {
|
|
295
|
-
patchSchemaHooks(m.Schema, tracer, finalConfig);
|
|
296
|
-
}
|
|
297
|
-
const getModelCollectionName = (model) => {
|
|
298
|
-
try {
|
|
299
|
-
return model.collection?.collectionName || model.modelName;
|
|
300
|
-
} catch {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
const queryMethods = [
|
|
305
|
-
{ method: "find", operation: "find" },
|
|
306
|
-
{ method: "findOne", operation: "findOne" },
|
|
307
|
-
{ method: "findById", operation: "findById" },
|
|
308
|
-
{ method: "findOneAndUpdate", operation: "findOneAndUpdate" },
|
|
309
|
-
{ method: "findOneAndDelete", operation: "findOneAndDelete" },
|
|
310
|
-
{ method: "findOneAndReplace", operation: "findOneAndReplace" },
|
|
311
|
-
{ method: "deleteOne", operation: "deleteOne" },
|
|
312
|
-
{ method: "deleteMany", operation: "deleteMany" },
|
|
313
|
-
{ method: "updateOne", operation: "updateOne" },
|
|
314
|
-
{ method: "updateMany", operation: "updateMany" },
|
|
315
|
-
{ method: "countDocuments", operation: "countDocuments" },
|
|
316
|
-
{ method: "estimatedDocumentCount", operation: "estimatedDocumentCount" }
|
|
317
|
-
];
|
|
318
|
-
for (const { method, operation } of queryMethods) {
|
|
319
|
-
wrapQueryMethod(
|
|
320
|
-
m.Model,
|
|
321
|
-
method,
|
|
322
|
-
operation,
|
|
323
|
-
getModelCollectionName,
|
|
324
|
-
(model) => model.modelName,
|
|
325
|
-
tracer,
|
|
326
|
-
finalConfig
|
|
327
|
-
);
|
|
328
|
-
if (m.Query?.prototype?.[method]) {
|
|
329
|
-
wrapChainableMethod(m.Query.prototype, method);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
const instanceMethods = ["save", "deleteOne"];
|
|
333
|
-
for (const method of instanceMethods) {
|
|
334
|
-
if (m.Model.prototype[method]) {
|
|
335
|
-
wrapQueryMethod(
|
|
336
|
-
m.Model.prototype,
|
|
337
|
-
method,
|
|
338
|
-
method,
|
|
339
|
-
(doc) => {
|
|
340
|
-
try {
|
|
341
|
-
return doc.constructor?.collection?.collectionName || doc.constructor?.modelName;
|
|
342
|
-
} catch {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
},
|
|
346
|
-
(doc) => {
|
|
347
|
-
try {
|
|
348
|
-
return doc.constructor?.modelName;
|
|
349
|
-
} catch {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
tracer,
|
|
354
|
-
finalConfig
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
const staticMethods = ["create", "insertMany", "aggregate", "bulkWrite"];
|
|
359
|
-
for (const method of staticMethods) {
|
|
360
|
-
if (m.Model[method]) {
|
|
361
|
-
wrapQueryMethod(
|
|
362
|
-
m.Model,
|
|
363
|
-
method,
|
|
364
|
-
method,
|
|
365
|
-
(model) => {
|
|
366
|
-
try {
|
|
367
|
-
return model.collection?.collectionName;
|
|
368
|
-
} catch {
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
},
|
|
372
|
-
(model) => model.modelName,
|
|
373
|
-
tracer,
|
|
374
|
-
finalConfig
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
const chainableMethods = [
|
|
379
|
-
"populate",
|
|
380
|
-
"select",
|
|
381
|
-
"lean",
|
|
382
|
-
"where",
|
|
383
|
-
"sort",
|
|
384
|
-
"limit",
|
|
385
|
-
"skip"
|
|
386
|
-
];
|
|
387
|
-
for (const method of chainableMethods) {
|
|
388
|
-
if (m.Query?.prototype?.[method]) {
|
|
389
|
-
wrapChainableMethod(m.Query.prototype, method);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
m[INSTRUMENTED_FLAG] = true;
|
|
393
|
-
return mongoose;
|
|
394
|
-
}
|
|
395
|
-
var MongooseInstrumentation = class {
|
|
396
|
-
constructor(config) {
|
|
397
|
-
this.config = config;
|
|
398
|
-
}
|
|
399
|
-
enable(mongoose) {
|
|
400
|
-
instrumentMongoose(mongoose, this.config);
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
exports.MongooseInstrumentation = MongooseInstrumentation;
|
|
405
|
-
exports._STORED_PARENT_SPAN = _STORED_PARENT_SPAN;
|
|
406
|
-
exports.instrumentMongoose = instrumentMongoose;
|
|
407
|
-
//# sourceMappingURL=mongoose.cjs.map
|
|
408
|
-
//# sourceMappingURL=mongoose.cjs.map
|
package/dist/mongoose.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/common/constants.ts","../src/mongoose/index.ts"],"names":["SpanKind","runWithSpan","finalizeSpan","getActiveSpan","wrappedHook","trace"],"mappings":";;;;;;;;AAMO,IAAM,kBAAA,GAAqB,WAAA;AAE3B,IAAM,qBAAA,GAAwB,cAAA;AAE9B,IAAM,gBAAA,GAAmB,SAAA;AAQzB,IAAM,8BAAA,GAAiC,uBAAA;AAGvC,IAAM,sBAAA,GAAyB,eAAA;AAC/B,IAAM,sBAAA,GAAyB,eAAA;ACDtC,IAAM,mBAAA,GAAsB,0BAAA;AAC5B,IAAM,iBAAA,GAAoB,UAAA;AAC1B,IAAM,iBAAA,GAAoB,+BAAA;AAC1B,IAAM,iBAAA,GAAoB,sBAAA;AAMnB,IAAM,mBAAA,0BAA4C,oBAAoB;AA4C7E,SAAS,UAAA,CACP,MAAA,EACA,SAAA,EACA,SAAA,EACA,gBACA,MAAA,EACM;AACN,EAAA,MAAM,QAAA,GAAW,cAAA,GACb,CAAA,SAAA,EAAY,cAAc,IAAI,SAAS,CAAA,CAAA,GACvC,S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AAA,EAAyC;AAAA,EAE7D,OAAO,QAAA,EAA0B;AAC/B,IAAA,kBAAA,CAAmB,QAAA,EAAU,KAAK,MAAM,CAAA;AAAA,EAC1C;AACF","file":"mongoose.cjs","sourcesContent":["/**\n * OpenTelemetry semantic conventions for database operations.\n * These constants are shared across all plugins.\n */\n\n// Common database attributes\nexport const SEMATTRS_DB_SYSTEM = 'db.system' as const;\nexport const SEMATTRS_DB_SYSTEM_NAME = 'db.system.name' as const;\nexport const SEMATTRS_DB_OPERATION = 'db.operation' as const;\nexport const SEMATTRS_DB_STATEMENT = 'db.statement' as const;\nexport const SEMATTRS_DB_NAME = 'db.name' as const;\nexport const SEMATTRS_DB_NAMESPACE = 'db.namespace' as const;\nexport const SEMATTRS_DB_COLLECTION_NAME = 'db.collection.name' as const;\nexport const SEMATTRS_DB_OPERATION_NAME = 'db.operation.name' as const;\nexport const SEMATTRS_DB_QUERY_TEXT = 'db.query.text' as const;\nexport const SEMATTRS_DB_QUERY_SUMMARY = 'db.query.summary' as const;\n\n// MongoDB-specific attributes\nexport const SEMATTRS_DB_MONGODB_COLLECTION = 'db.mongodb.collection' as const;\n\n// Network attributes\nexport const SEMATTRS_NET_PEER_NAME = 'net.peer.name' as const;\nexport const SEMATTRS_NET_PEER_PORT = 'net.peer.port' as const;\n\n// Messaging attributes (Kafka, etc.)\nexport const SEMATTRS_MESSAGING_SYSTEM = 'messaging.system' as const;\nexport const SEMATTRS_MESSAGING_DESTINATION_NAME =\n 'messaging.destination.name' as const;\nexport const SEMATTRS_MESSAGING_OPERATION = 'messaging.operation' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP =\n 'messaging.kafka.consumer.group' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_PARTITION =\n 'messaging.kafka.partition' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_OFFSET =\n 'messaging.kafka.offset' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY =\n 'messaging.kafka.message.key' as const;\n\n// Batch lineage attributes\nexport const SEMATTRS_LINKED_TRACE_ID_COUNT = 'linked_trace_id_count' as const;\nexport const SEMATTRS_LINKED_TRACE_ID_HASH = 'linked_trace_id_hash' as const;\n\n// Correlation ID header name\nexport const CORRELATION_ID_HEADER = 'x-correlation-id' as const;\n\n// BigQuery-specific attributes (namespaced under gcp.bigquery per OTel spec)\nexport const SEMATTRS_GCP_BIGQUERY_JOB_ID = 'gcp.bigquery.job.id' as const;\nexport const SEMATTRS_GCP_BIGQUERY_JOB_LOCATION =\n 'gcp.bigquery.job.location' as const;\nexport const SEMATTRS_GCP_BIGQUERY_PROJECT_ID =\n 'gcp.bigquery.project.id' as const;\nexport const SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE =\n 'gcp.bigquery.destination.table' as const;\nexport const SEMATTRS_GCP_BIGQUERY_SOURCE_TABLES =\n 'gcp.bigquery.source.tables' as const;\nexport const SEMATTRS_GCP_BIGQUERY_STATEMENT_TYPE =\n 'gcp.bigquery.statement_type' as const;\nexport const SEMATTRS_GCP_BIGQUERY_QUERY_HASH =\n 'gcp.bigquery.query.hash' as const;\nexport const SEMATTRS_GCP_BIGQUERY_ROWS_AFFECTED =\n 'gcp.bigquery.rows.affected' as const;\nexport const SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED =\n 'gcp.bigquery.rows.returned' as const;\nexport const SEMATTRS_GCP_BIGQUERY_SCHEMA_FIELDS =\n 'gcp.bigquery.schema.fields' as const;\n\n// RabbitMQ-specific attributes (aligned with OTel messaging semantic conventions)\nexport const SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY =\n 'messaging.rabbitmq.destination.routing_key' as const;\nexport const SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE =\n 'messaging.rabbitmq.destination.exchange' as const;\nexport const SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT =\n 'messaging.rabbitmq.ack_result' as const;\nexport const SEMATTRS_MESSAGING_RABBITMQ_REQUEUE =\n 'messaging.rabbitmq.requeue' as const;\n\n// Messaging attributes (shared across messaging systems)\nexport const SEMATTRS_MESSAGING_MESSAGE_ID = 'messaging.message.id' as const;\nexport const SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID =\n 'messaging.message.conversation_id' as const;\nexport const SEMATTRS_MESSAGING_CONSUMER_ID = 'messaging.consumer.id' as const;\nexport const SEMATTRS_MESSAGING_OPERATION_NAME =\n 'messaging.operation.name' as const;\n\n// Kafka batch consumer attributes\nexport const SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT =\n 'messaging.batch.message_count' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET =\n 'messaging.kafka.batch.first_offset' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET =\n 'messaging.kafka.batch.last_offset' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED =\n 'messaging.kafka.batch.messages_processed' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED =\n 'messaging.kafka.batch.messages_failed' as const;\nexport const SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS =\n 'messaging.kafka.batch.processing_time_ms' as const;\n","/* eslint-disable @typescript-eslint/no-explicit-any */\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 { SpanKind, otelTrace as trace, type Span, type Tracer } from 'autotel';\nimport {\n SEMATTRS_DB_SYSTEM,\n SEMATTRS_DB_OPERATION,\n SEMATTRS_DB_MONGODB_COLLECTION,\n SEMATTRS_DB_NAME,\n SEMATTRS_NET_PEER_NAME,\n SEMATTRS_NET_PEER_PORT,\n} from '../common/constants';\nimport {\n runWithSpan,\n finalizeSpan,\n getActiveSpan,\n} from 'autotel/trace-helpers';\n\nconst DEFAULT_TRACER_NAME = 'autotel-plugins/mongoose';\nconst DEFAULT_DB_SYSTEM = 'mongoose';\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 * Configuration options for Mongoose instrumentation.\n * Focused on Mongoose 8+ with promise-based API only.\n */\nexport interface MongooseInstrumentationConfig {\n /**\n * Database name to include in spans.\n */\n dbName?: string;\n\n /**\n * Remote hostname or IP address of the MongoDB server.\n */\n peerName?: string;\n\n /**\n * Remote port number of the MongoDB server (default: 27017).\n */\n peerPort?: number;\n\n /**\n * Custom tracer name (default: \"autotel-plugins/mongoose\").\n */\n tracerName?: string;\n\n /**\n * Whether to capture collection names in spans (default: true).\n */\n captureCollectionName?: boolean;\n\n /**\n * Whether to instrument Schema hooks (pre/post save, validate, etc).\n * Disabled by default because hooks interact with Mongoose plugins.\n * Enable only if you have user-defined hooks you want to trace.\n * (default: false)\n */\n instrumentHooks?: boolean;\n}\n\n/**\n * Creates a span for a Mongoose operation.\n */\nfunction createSpan(\n tracer: Tracer,\n operation: string,\n modelName: string | undefined,\n collectionName: string | undefined,\n config: Required<MongooseInstrumentationConfig>,\n): Span {\n const spanName = collectionName\n ? `mongoose.${collectionName}.${operation}`\n : modelName\n ? `mongoose.${modelName}.${operation}`\n : `mongoose.${operation}`;\n\n const attributes: Record<string, any> = {\n [SEMATTRS_DB_SYSTEM]: DEFAULT_DB_SYSTEM,\n [SEMATTRS_DB_OPERATION]: operation,\n };\n\n if (collectionName && config.captureCollectionName) {\n attributes[SEMATTRS_DB_MONGODB_COLLECTION] = collectionName;\n }\n\n if (config.dbName) {\n attributes[SEMATTRS_DB_NAME] = config.dbName;\n }\n\n if (config.peerName) {\n attributes[SEMATTRS_NET_PEER_NAME] = config.peerName;\n }\n\n if (config.peerPort) {\n attributes[SEMATTRS_NET_PEER_PORT] = config.peerPort;\n }\n\n return tracer.startSpan(spanName, { kind: SpanKind.CLIENT, attributes });\n}\n\n/**\n * Wraps a method to trace Query/Aggregate execution with proper span lifecycle.\n * Returns the Query/Aggregate object with wrapped exec() to finalize span.\n */\nfunction wrapQueryMethod(\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: Required<MongooseInstrumentationConfig>,\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 // If result is a Query/Aggregate, wrap exec() and preserve it\n if (result && typeof result.exec === 'function') {\n const originalExec = result.exec.bind(result);\n\n result.exec = function wrappedExec(): Promise<any> {\n try {\n const execPromise = originalExec();\n\n return Promise.resolve(execPromise)\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 } 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/Aggregate, not Promise\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 chainable Query methods (find, findOne, 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 * 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: Required<MongooseInstrumentationConfig>,\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: Required<MongooseInstrumentationConfig>,\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(SEMATTRS_DB_MONGODB_COLLECTION, collectionName);\n }\n span.setAttribute(SEMATTRS_DB_SYSTEM, DEFAULT_DB_SYSTEM);\n if (config.dbName) {\n span.setAttribute(SEMATTRS_DB_NAME, 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 * 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-plugins/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?: MongooseInstrumentationConfig,\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 const finalConfig: Required<MongooseInstrumentationConfig> = {\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 };\n\n const tracer = trace.getTracer(finalConfig.tracerName);\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 methods\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 wrapQueryMethod(\n m.Model,\n method,\n operation,\n getModelCollectionName,\n (model: any) => model.modelName,\n tracer,\n finalConfig,\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 wrapQueryMethod(\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 );\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 wrapQueryMethod(\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 );\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?: MongooseInstrumentationConfig) {}\n\n enable(mongoose: Mongoose): void {\n instrumentMongoose(mongoose, this.config);\n }\n}\n"]}
|
package/dist/mongoose.d.cts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Mongoose } from 'mongoose';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Symbol used to store the parent span on Query/Aggregate objects.
|
|
5
|
-
* This preserves context across chainable query methods.
|
|
6
|
-
*/
|
|
7
|
-
declare const _STORED_PARENT_SPAN: unique symbol;
|
|
8
|
-
/**
|
|
9
|
-
* Configuration options for Mongoose instrumentation.
|
|
10
|
-
* Focused on Mongoose 8+ with promise-based API only.
|
|
11
|
-
*/
|
|
12
|
-
interface MongooseInstrumentationConfig {
|
|
13
|
-
/**
|
|
14
|
-
* Database name to include in spans.
|
|
15
|
-
*/
|
|
16
|
-
dbName?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Remote hostname or IP address of the MongoDB server.
|
|
19
|
-
*/
|
|
20
|
-
peerName?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Remote port number of the MongoDB server (default: 27017).
|
|
23
|
-
*/
|
|
24
|
-
peerPort?: number;
|
|
25
|
-
/**
|
|
26
|
-
* Custom tracer name (default: "autotel-plugins/mongoose").
|
|
27
|
-
*/
|
|
28
|
-
tracerName?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Whether to capture collection names in spans (default: true).
|
|
31
|
-
*/
|
|
32
|
-
captureCollectionName?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Whether to instrument Schema hooks (pre/post save, validate, etc).
|
|
35
|
-
* Disabled by default because hooks interact with Mongoose plugins.
|
|
36
|
-
* Enable only if you have user-defined hooks you want to trace.
|
|
37
|
-
* (default: false)
|
|
38
|
-
*/
|
|
39
|
-
instrumentHooks?: boolean;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Instruments Mongoose with OpenTelemetry tracing.
|
|
43
|
-
*
|
|
44
|
-
* Supports Mongoose 8+ with promise-based API only.
|
|
45
|
-
* Patches Model methods, Query methods, and user-defined Schema hooks to create spans.
|
|
46
|
-
*
|
|
47
|
-
* **IMPORTANT:** Call `instrumentMongoose()` BEFORE defining schemas/models
|
|
48
|
-
* to ensure hooks are automatically instrumented.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* import mongoose from 'mongoose';
|
|
53
|
-
* import { init } from 'autotel';
|
|
54
|
-
* import { instrumentMongoose } from 'autotel-plugins/mongoose';
|
|
55
|
-
*
|
|
56
|
-
* init({ service: 'my-app' });
|
|
57
|
-
*
|
|
58
|
-
* // Call BEFORE defining schemas
|
|
59
|
-
* instrumentMongoose(mongoose, { dbName: 'myapp' });
|
|
60
|
-
*
|
|
61
|
-
* const userSchema = new mongoose.Schema({ name: String });
|
|
62
|
-
* const User = mongoose.model('User', userSchema);
|
|
63
|
-
*
|
|
64
|
-
* // All operations are automatically traced
|
|
65
|
-
* await User.findOne({}).populate('posts').exec();
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function instrumentMongoose(mongoose: Mongoose, config?: MongooseInstrumentationConfig): Mongoose;
|
|
69
|
-
/**
|
|
70
|
-
* Legacy export for backwards compatibility.
|
|
71
|
-
* @deprecated Use `instrumentMongoose` instead.
|
|
72
|
-
*/
|
|
73
|
-
declare class MongooseInstrumentation {
|
|
74
|
-
private config?;
|
|
75
|
-
constructor(config?: MongooseInstrumentationConfig | undefined);
|
|
76
|
-
enable(mongoose: Mongoose): void;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { MongooseInstrumentation, type MongooseInstrumentationConfig, _STORED_PARENT_SPAN, instrumentMongoose };
|
package/dist/mongoose.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Mongoose } from 'mongoose';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Symbol used to store the parent span on Query/Aggregate objects.
|
|
5
|
-
* This preserves context across chainable query methods.
|
|
6
|
-
*/
|
|
7
|
-
declare const _STORED_PARENT_SPAN: unique symbol;
|
|
8
|
-
/**
|
|
9
|
-
* Configuration options for Mongoose instrumentation.
|
|
10
|
-
* Focused on Mongoose 8+ with promise-based API only.
|
|
11
|
-
*/
|
|
12
|
-
interface MongooseInstrumentationConfig {
|
|
13
|
-
/**
|
|
14
|
-
* Database name to include in spans.
|
|
15
|
-
*/
|
|
16
|
-
dbName?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Remote hostname or IP address of the MongoDB server.
|
|
19
|
-
*/
|
|
20
|
-
peerName?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Remote port number of the MongoDB server (default: 27017).
|
|
23
|
-
*/
|
|
24
|
-
peerPort?: number;
|
|
25
|
-
/**
|
|
26
|
-
* Custom tracer name (default: "autotel-plugins/mongoose").
|
|
27
|
-
*/
|
|
28
|
-
tracerName?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Whether to capture collection names in spans (default: true).
|
|
31
|
-
*/
|
|
32
|
-
captureCollectionName?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Whether to instrument Schema hooks (pre/post save, validate, etc).
|
|
35
|
-
* Disabled by default because hooks interact with Mongoose plugins.
|
|
36
|
-
* Enable only if you have user-defined hooks you want to trace.
|
|
37
|
-
* (default: false)
|
|
38
|
-
*/
|
|
39
|
-
instrumentHooks?: boolean;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Instruments Mongoose with OpenTelemetry tracing.
|
|
43
|
-
*
|
|
44
|
-
* Supports Mongoose 8+ with promise-based API only.
|
|
45
|
-
* Patches Model methods, Query methods, and user-defined Schema hooks to create spans.
|
|
46
|
-
*
|
|
47
|
-
* **IMPORTANT:** Call `instrumentMongoose()` BEFORE defining schemas/models
|
|
48
|
-
* to ensure hooks are automatically instrumented.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* import mongoose from 'mongoose';
|
|
53
|
-
* import { init } from 'autotel';
|
|
54
|
-
* import { instrumentMongoose } from 'autotel-plugins/mongoose';
|
|
55
|
-
*
|
|
56
|
-
* init({ service: 'my-app' });
|
|
57
|
-
*
|
|
58
|
-
* // Call BEFORE defining schemas
|
|
59
|
-
* instrumentMongoose(mongoose, { dbName: 'myapp' });
|
|
60
|
-
*
|
|
61
|
-
* const userSchema = new mongoose.Schema({ name: String });
|
|
62
|
-
* const User = mongoose.model('User', userSchema);
|
|
63
|
-
*
|
|
64
|
-
* // All operations are automatically traced
|
|
65
|
-
* await User.findOne({}).populate('posts').exec();
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function instrumentMongoose(mongoose: Mongoose, config?: MongooseInstrumentationConfig): Mongoose;
|
|
69
|
-
/**
|
|
70
|
-
* Legacy export for backwards compatibility.
|
|
71
|
-
* @deprecated Use `instrumentMongoose` instead.
|
|
72
|
-
*/
|
|
73
|
-
declare class MongooseInstrumentation {
|
|
74
|
-
private config?;
|
|
75
|
-
constructor(config?: MongooseInstrumentationConfig | undefined);
|
|
76
|
-
enable(mongoose: Mongoose): void;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { MongooseInstrumentation, type MongooseInstrumentationConfig, _STORED_PARENT_SPAN, instrumentMongoose };
|