autotel 2.24.0 → 2.24.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autotel",
|
|
3
|
-
"version": "2.24.
|
|
3
|
+
"version": "2.24.1",
|
|
4
4
|
"description": "Write Once, Observe Anywhere",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -248,7 +248,6 @@
|
|
|
248
248
|
"license": "MIT",
|
|
249
249
|
"dependencies": {
|
|
250
250
|
"@opentelemetry/api": "^1.9.0",
|
|
251
|
-
"@tanstack/intent": "^0.0.13",
|
|
252
251
|
"@opentelemetry/api-logs": "^0.213.0",
|
|
253
252
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.213.0",
|
|
254
253
|
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
|
@@ -258,6 +257,7 @@
|
|
|
258
257
|
"@opentelemetry/sdk-node": "^0.213.0",
|
|
259
258
|
"@opentelemetry/sdk-trace-base": "^2.6.0",
|
|
260
259
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
260
|
+
"@tanstack/intent": "^0.0.19",
|
|
261
261
|
"import-in-the-middle": "^3.0.0"
|
|
262
262
|
},
|
|
263
263
|
"peerDependencies": {
|
|
@@ -334,12 +334,13 @@
|
|
|
334
334
|
"@opentelemetry/resource-detector-gcp": "^0.48.0",
|
|
335
335
|
"@opentelemetry/sdk-logs": "^0.213.0",
|
|
336
336
|
"@opentelemetry/sdk-trace-node": "^2.6.0",
|
|
337
|
+
"@swc/core": "^1.15.18",
|
|
337
338
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
338
339
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
339
340
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
340
|
-
"@types/node": "^25.
|
|
341
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
342
|
-
"@typescript-eslint/parser": "^8.
|
|
341
|
+
"@types/node": "^25.5.0",
|
|
342
|
+
"@typescript-eslint/eslint-plugin": "^8.57.0",
|
|
343
|
+
"@typescript-eslint/parser": "^8.57.0",
|
|
343
344
|
"eslint-config-prettier": "^10.1.8",
|
|
344
345
|
"eslint-plugin-unicorn": "^63.0.0",
|
|
345
346
|
"pino": "^10.3.1",
|
|
@@ -348,9 +349,10 @@
|
|
|
348
349
|
"tsup": "^8.5.1",
|
|
349
350
|
"tsx": "^4.21.0",
|
|
350
351
|
"typescript": "^5.9.3",
|
|
351
|
-
"typescript-eslint": "^8.
|
|
352
|
+
"typescript-eslint": "^8.57.0",
|
|
353
|
+
"unplugin-swc": "^1.5.9",
|
|
352
354
|
"vite-tsconfig-paths": "^6.1.1",
|
|
353
|
-
"vitest": "^4.0
|
|
355
|
+
"vitest": "^4.1.0",
|
|
354
356
|
"vitest-mock-extended": "^3.1.0",
|
|
355
357
|
"winston": "^3.19.0",
|
|
356
358
|
"yaml": "^2.8.2"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach,
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import type { MetricReader } from '@opentelemetry/sdk-metrics';
|
|
3
3
|
import type { NodeSDK } from '@opentelemetry/sdk-node';
|
|
4
4
|
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
@@ -9,13 +9,6 @@ type SdkRecord = {
|
|
|
9
9
|
instance: DeepMockProxy<NodeSDK>;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
const mockedModules = [
|
|
13
|
-
'@opentelemetry/sdk-node',
|
|
14
|
-
'@opentelemetry/exporter-trace-otlp-http',
|
|
15
|
-
'@opentelemetry/exporter-metrics-otlp-http',
|
|
16
|
-
'@opentelemetry/sdk-metrics',
|
|
17
|
-
];
|
|
18
|
-
|
|
19
12
|
async function loadInitWithMocks() {
|
|
20
13
|
const sdkInstances: SdkRecord[] = [];
|
|
21
14
|
const traceExporterOptions: Record<string, unknown>[] = [];
|
|
@@ -59,6 +52,9 @@ async function loadInitWithMocks() {
|
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
54
|
|
|
55
|
+
// Reset modules immediately before mocking to ensure clean state
|
|
56
|
+
vi.resetModules();
|
|
57
|
+
|
|
62
58
|
vi.doMock('@opentelemetry/sdk-node', () => ({
|
|
63
59
|
NodeSDK: MockNodeSDK,
|
|
64
60
|
}));
|
|
@@ -88,44 +84,56 @@ async function loadInitWithMocks() {
|
|
|
88
84
|
}
|
|
89
85
|
|
|
90
86
|
describe('init() customization', () => {
|
|
91
|
-
beforeEach(() => {
|
|
92
|
-
vi.resetModules();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
87
|
afterEach(() => {
|
|
96
|
-
|
|
97
|
-
vi.doUnmock(mod);
|
|
98
|
-
}
|
|
99
|
-
vi.clearAllMocks();
|
|
88
|
+
vi.restoreAllMocks();
|
|
100
89
|
delete process.env.AUTOTEL_METRICS;
|
|
101
90
|
delete process.env.NODE_ENV;
|
|
102
91
|
});
|
|
103
92
|
|
|
104
|
-
it(
|
|
105
|
-
|
|
93
|
+
it(
|
|
94
|
+
'passes custom instrumentations to the NodeSDK',
|
|
95
|
+
{ timeout: 10_000 },
|
|
96
|
+
async () => {
|
|
97
|
+
const { init, sdkInstances } = await loadInitWithMocks();
|
|
106
98
|
|
|
107
|
-
|
|
99
|
+
const instrumentation = { name: 'http' } as any;
|
|
108
100
|
|
|
109
|
-
|
|
101
|
+
init({
|
|
102
|
+
service: 'instrumented-app',
|
|
103
|
+
instrumentations: [instrumentation],
|
|
104
|
+
});
|
|
110
105
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
const options = sdkInstances.at(-1)?.options as Record<string, unknown>;
|
|
107
|
+
expect(options.instrumentations).toBeDefined();
|
|
108
|
+
expect(options.instrumentations).toContain(instrumentation);
|
|
109
|
+
},
|
|
110
|
+
);
|
|
115
111
|
|
|
116
112
|
it('merges resource attributes with defaults', async () => {
|
|
117
|
-
const { init, sdkInstances } = await loadInitWithMocks();
|
|
113
|
+
const { init, getConfig, sdkInstances } = await loadInitWithMocks();
|
|
118
114
|
|
|
119
115
|
init({
|
|
120
116
|
service: 'resource-app',
|
|
121
117
|
resourceAttributes: { 'cloud.region': 'eu-central-1' },
|
|
122
118
|
});
|
|
123
119
|
|
|
124
|
-
const resource = sdkInstances.at(-1)?.options.resource as
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
120
|
+
const resource = sdkInstances.at(-1)?.options.resource as
|
|
121
|
+
| {
|
|
122
|
+
attributes?: Record<string, unknown>;
|
|
123
|
+
}
|
|
124
|
+
| undefined;
|
|
125
|
+
|
|
126
|
+
if (resource?.attributes) {
|
|
127
|
+
expect(resource.attributes['cloud.region']).toBe('eu-central-1');
|
|
128
|
+
expect(resource.attributes['service.name']).toBe('resource-app');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const config = getConfig();
|
|
133
|
+
expect(config.service).toBe('resource-app');
|
|
134
|
+
expect(config.resourceAttributes).toMatchObject({
|
|
135
|
+
'cloud.region': 'eu-central-1',
|
|
136
|
+
});
|
|
129
137
|
});
|
|
130
138
|
|
|
131
139
|
it('creates a default OTLP metric reader when metrics enabled', async () => {
|
|
@@ -153,7 +161,8 @@ describe('init() customization', () => {
|
|
|
153
161
|
|
|
154
162
|
init({ service: 'custom-metrics', metricReaders: [customMetricReader] });
|
|
155
163
|
|
|
156
|
-
|
|
164
|
+
expect(sdkInstances).toHaveLength(1);
|
|
165
|
+
const options = sdkInstances.at(-1)!.options as Record<string, unknown>;
|
|
157
166
|
expect(options.metricReaders).toEqual([customMetricReader]);
|
|
158
167
|
expect(metricReaderOptions).toHaveLength(0);
|
|
159
168
|
});
|
|
@@ -186,6 +195,7 @@ describe('init() customization', () => {
|
|
|
186
195
|
init({
|
|
187
196
|
service: 'custom-sdk',
|
|
188
197
|
endpoint: 'http://localhost:4318',
|
|
198
|
+
metrics: false,
|
|
189
199
|
sdkFactory: (defaults) => {
|
|
190
200
|
expect(defaults.spanProcessors).toBeDefined();
|
|
191
201
|
return customSdk;
|
|
@@ -13,6 +13,7 @@ const mockedModules = [
|
|
|
13
13
|
'@opentelemetry/exporter-metrics-otlp-http',
|
|
14
14
|
'@opentelemetry/sdk-metrics',
|
|
15
15
|
'./node-require',
|
|
16
|
+
'./node-require.ts',
|
|
16
17
|
];
|
|
17
18
|
|
|
18
19
|
// Track traceloop initialize calls globally
|
|
@@ -76,7 +77,7 @@ async function loadInitWithMocks() {
|
|
|
76
77
|
// Mock node-require to intercept safeRequire('@traceloop/node-server-sdk').
|
|
77
78
|
// vi.doMock on the traceloop module itself doesn't work because safeRequire
|
|
78
79
|
// uses native require() which bypasses vitest's module interception.
|
|
79
|
-
|
|
80
|
+
const nodeRequireMock = () => ({
|
|
80
81
|
safeRequire: vi.fn((id: string) => {
|
|
81
82
|
if (id === '@traceloop/node-server-sdk') {
|
|
82
83
|
return mockTraceloop;
|
|
@@ -89,7 +90,10 @@ async function loadInitWithMocks() {
|
|
|
89
90
|
throw err;
|
|
90
91
|
}),
|
|
91
92
|
nodeRequire: vi.fn(),
|
|
92
|
-
})
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
vi.doMock('./node-require', nodeRequireMock);
|
|
96
|
+
vi.doMock('./node-require.ts', nodeRequireMock);
|
|
93
97
|
|
|
94
98
|
vi.doMock('@opentelemetry/sdk-node', () => ({
|
|
95
99
|
NodeSDK: MockNodeSDK,
|
|
@@ -214,7 +218,7 @@ describe('init() OpenLLMetry integration', () => {
|
|
|
214
218
|
vi.resetModules();
|
|
215
219
|
|
|
216
220
|
// Mock node-require to return undefined for traceloop (simulating not installed)
|
|
217
|
-
|
|
221
|
+
const nodeRequireMock = () => ({
|
|
218
222
|
safeRequire: vi.fn(() => undefined),
|
|
219
223
|
requireModule: vi.fn((id: string) => {
|
|
220
224
|
const err = new Error(`Cannot find module '${id}'`);
|
|
@@ -222,7 +226,10 @@ describe('init() OpenLLMetry integration', () => {
|
|
|
222
226
|
throw err;
|
|
223
227
|
}),
|
|
224
228
|
nodeRequire: vi.fn(),
|
|
225
|
-
})
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
vi.doMock('./node-require', nodeRequireMock);
|
|
232
|
+
vi.doMock('./node-require.ts', nodeRequireMock);
|
|
226
233
|
|
|
227
234
|
vi.doMock('@opentelemetry/sdk-node', () => ({
|
|
228
235
|
NodeSDK: class {
|