autotel-mongoose 10.1.1 → 12.0.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/package.json +2 -3
- package/src/config-custom.integration.test.ts +0 -91
- package/src/config-disabled.integration.test.ts +0 -79
- package/src/constants.ts +0 -25
- package/src/custom-methods.integration.test.ts +0 -507
- package/src/hooks.integration.test.ts +0 -129
- package/src/index.ts +0 -10
- package/src/instrumentation.integration.test.ts +0 -203
- package/src/instrumentation.ts +0 -1450
- package/src/statement.test.ts +0 -78
- package/src/statement.ts +0 -162
- package/src/test-support.ts +0 -32
- package/src/types.ts +0 -184
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autotel-mongoose",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "OpenTelemetry instrumentation for Mongoose with db.query.text capture and automatic redaction",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"dist",
|
|
18
|
-
"src",
|
|
19
18
|
"README.md",
|
|
20
19
|
"skills"
|
|
21
20
|
],
|
|
@@ -46,7 +45,7 @@
|
|
|
46
45
|
"tsdown": "^0.22.2",
|
|
47
46
|
"typescript": "^6.0.3",
|
|
48
47
|
"vitest": "^4.1.8",
|
|
49
|
-
"autotel": "4.
|
|
48
|
+
"autotel": "4.2.0"
|
|
50
49
|
},
|
|
51
50
|
"repository": {
|
|
52
51
|
"type": "git",
|
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
});
|
package/src/constants.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
// Stable code semconv — used for user-defined statics/methods/query helpers.
|
|
12
|
-
export const ATTR_CODE_FUNCTION_NAME = 'code.function.name' as const;
|
|
13
|
-
|
|
14
|
-
// Autotel-namespaced attributes for user-defined Mongoose functions.
|
|
15
|
-
// Mirrors the existing `hook.*` namespace used for schema hook spans.
|
|
16
|
-
export const ATTR_MONGOOSE_METHOD_NAME = 'mongoose.method.name' as const;
|
|
17
|
-
/** One of: "static" | "instance" | "query". */
|
|
18
|
-
export const ATTR_MONGOOSE_METHOD_TYPE = 'mongoose.method.type' as const;
|
|
19
|
-
export const ATTR_MONGOOSE_METHOD_MODEL = 'mongoose.method.model' as const;
|
|
20
|
-
export const ATTR_MONGOOSE_METHOD_PARAMETERS =
|
|
21
|
-
'mongoose.method.parameters' as const;
|
|
22
|
-
export const ATTR_MONGOOSE_METHOD_PARAMETER_COUNT =
|
|
23
|
-
'mongoose.method.parameter_count' as const;
|
|
24
|
-
|
|
25
|
-
export const DB_SYSTEM_NAME_VALUE_MONGODB = 'mongodb' as const;
|