@elysiumjs/argus 0.2.0 → 0.2.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/src/sdk.ts DELETED
@@ -1,122 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import type { TracingConfig } from './types';
16
-
17
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
18
- import { resourceFromAttributes } from '@opentelemetry/resources';
19
- import { NodeSDK } from '@opentelemetry/sdk-node';
20
- import { ConsoleSpanExporter, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-base';
21
- import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
22
-
23
- /**
24
- * ArgusSDK initializes OpenTelemetry for the Elysium framework.
25
- *
26
- * CRITICAL: For full auto-instrumentation this MUST be called before any
27
- * application code runs (e.g. from a `--preload` file). Auto-instrumentation
28
- * patches modules at import time; modules imported before OTel is initialized
29
- * won't be instrumented. `ArgusModule` initialises the SDK in `onInit`, which
30
- * only covers modules loaded afterwards; when the SDK was already initialised
31
- * (e.g. by a preload), the module detects it with {@link ArgusSDK.isInitialized}
32
- * and leaves it alone.
33
- *
34
- * @example
35
- * ```typescript
36
- * // src/instrument.ts (loaded FIRST via --preload or entrypoint)
37
- * import { ArgusSDK } from '@elysiumjs/argus';
38
- *
39
- * ArgusSDK.initialize({
40
- * enabled: true,
41
- * serviceName: 'my-api',
42
- * exporter: 'otlp-http',
43
- * endpoint: 'http://localhost:4318/v1/traces'
44
- * });
45
- * ```
46
- *
47
- * @author Axel Nana <axel.nana@workbud.com>
48
- */
49
- export class ArgusSDK {
50
- private static instance: ArgusSDK | undefined;
51
- private sdk: NodeSDK | null = null;
52
-
53
- private constructor() {}
54
-
55
- /**
56
- * Whether {@link ArgusSDK.initialize} has already been called.
57
- * @author Axel Nana <axel.nana@workbud.com>
58
- */
59
- public static isInitialized(): boolean {
60
- return ArgusSDK.instance !== undefined;
61
- }
62
-
63
- /**
64
- * Initializes the OpenTelemetry SDK.
65
- * Can only be called once — subsequent calls are ignored with a warning.
66
- * @author Axel Nana <axel.nana@workbud.com>
67
- * @param config The tracing configuration.
68
- */
69
- public static initialize(config: TracingConfig): void {
70
- if (ArgusSDK.instance) {
71
- console.error('[Argus] SDK already initialized. Ignoring duplicate call.');
72
- return;
73
- }
74
-
75
- ArgusSDK.instance = new ArgusSDK();
76
-
77
- if (!config.enabled) return;
78
-
79
- const exporter = ArgusSDK.createExporter(config);
80
-
81
- ArgusSDK.instance.sdk = new NodeSDK({
82
- resource: resourceFromAttributes({
83
- [ATTR_SERVICE_NAME]: config.serviceName
84
- }),
85
- traceExporter: exporter,
86
- ...(config.samplingRate !== undefined && {
87
- sampler: new TraceIdRatioBasedSampler(config.samplingRate)
88
- })
89
- });
90
-
91
- ArgusSDK.instance.sdk.start();
92
- }
93
-
94
- /**
95
- * Creates the appropriate trace exporter based on the config.
96
- * @author Axel Nana <axel.nana@workbud.com>
97
- * @param config The tracing configuration.
98
- * @returns A span exporter instance.
99
- */
100
- private static createExporter(config: TracingConfig) {
101
- switch (config.exporter) {
102
- case 'otlp-http':
103
- return new OTLPTraceExporter({
104
- url: config.endpoint ?? 'http://localhost:4318/v1/traces'
105
- });
106
- case 'console':
107
- default:
108
- return new ConsoleSpanExporter();
109
- }
110
- }
111
-
112
- /**
113
- * Shuts down the OpenTelemetry SDK gracefully.
114
- * @author Axel Nana <axel.nana@workbud.com>
115
- */
116
- public static async shutdown(): Promise<void> {
117
- if (ArgusSDK.instance?.sdk) {
118
- await ArgusSDK.instance.sdk.shutdown();
119
- }
120
- ArgusSDK.instance = undefined;
121
- }
122
- }
package/src/types.ts DELETED
@@ -1,47 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- /**
16
- * Configuration for the Argus telemetry SDK.
17
- * @author Axel Nana <axel.nana@workbud.com>
18
- */
19
- export interface TracingConfig {
20
- /**
21
- * Whether tracing is enabled.
22
- */
23
- enabled: boolean;
24
-
25
- /**
26
- * The service name reported in spans.
27
- */
28
- serviceName: string;
29
-
30
- /**
31
- * The exporter to use. Only `otlp-http` and `console` are supported.
32
- * gRPC is not supported on Bun.
33
- */
34
- exporter: 'otlp-http' | 'console';
35
-
36
- /**
37
- * The OTLP endpoint URL.
38
- * @default 'http://localhost:4318/v1/traces'
39
- */
40
- endpoint?: string;
41
-
42
- /**
43
- * Sampling rate between 0.0 and 1.0.
44
- * @default 1.0
45
- */
46
- samplingRate?: number;
47
- }
@@ -1,120 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { readFileSync } from 'node:fs';
16
- import { join } from 'node:path';
17
-
18
- import { Application, MissingModuleConfigError, Module } from '@elysiumjs/core';
19
- import { afterEach, describe, expect, it, mock, spyOn } from 'bun:test';
20
- import { Elysia } from 'elysia';
21
-
22
- import { ArgusModule, argusPlugin, ArgusSDK } from '../src';
23
-
24
- const withConfig = (config: Record<string, unknown>) => {
25
- @Module.register({ imports: [ArgusModule.with(config as any)] })
26
- class AppModule extends Module {}
27
- return AppModule;
28
- };
29
-
30
- describe('ArgusModule', () => {
31
- afterEach(() => {
32
- mock.restore();
33
- (ArgusSDK as any).instance = undefined;
34
- });
35
-
36
- it('has no bare side-effect imports in its entry point', () => {
37
- const source = readFileSync(join(import.meta.dir, '../src/index.ts'), 'utf8');
38
- const bare = source.match(/^import\s+['"][^'"]+['"]/gm) ?? [];
39
- expect(bare).toEqual([]);
40
- });
41
-
42
- it('requires a serviceName', async () => {
43
- @Module.register({ imports: [ArgusModule] })
44
- class Bare extends Module {}
45
- await expect(Application.testing({ modules: [Bare] })).rejects.toBeInstanceOf(
46
- MissingModuleConfigError
47
- );
48
- });
49
-
50
- it('starts the SDK with the resolved config on init', async () => {
51
- const init = spyOn(ArgusSDK, 'initialize').mockImplementation(() => {});
52
- const app = await Application.testing({
53
- modules: [withConfig({ serviceName: 'svc' })],
54
- boot: 'eager'
55
- });
56
- try {
57
- expect(init).toHaveBeenCalledWith(
58
- expect.objectContaining({ serviceName: 'svc', enabled: true, exporter: 'console' })
59
- );
60
- } finally {
61
- await app.shutdown();
62
- }
63
- });
64
-
65
- it('installs the argus plugin on serve', async () => {
66
- spyOn(ArgusSDK, 'initialize').mockImplementation(() => {});
67
- const app = await Application.testing({
68
- modules: [withConfig({ serviceName: 'svc' })],
69
- boot: 'eager'
70
- });
71
- try {
72
- const use = mock((_plugin: unknown) => {});
73
- const instance = app.kernel.moduleInstance(app.kernel.graph.node(ArgusModule)!);
74
- await instance.onServe({ use } as any);
75
- expect(use).toHaveBeenCalledTimes(1);
76
- const installed = (use.mock.calls[0] as unknown[])[0] as any;
77
- expect(installed).toBeInstanceOf(Elysia);
78
- expect(installed.config.name).toBe((argusPlugin() as any).config.name);
79
- } finally {
80
- await app.shutdown();
81
- }
82
- });
83
-
84
- it('shuts the SDK down on destroy when it was started', async () => {
85
- spyOn(ArgusSDK, 'initialize').mockImplementation(() => {});
86
- const shutdown = spyOn(ArgusSDK, 'shutdown').mockResolvedValue(undefined);
87
- const app = await Application.testing({
88
- modules: [withConfig({ serviceName: 'svc' })],
89
- boot: 'eager'
90
- });
91
- await app.shutdown();
92
- expect(shutdown).toHaveBeenCalledTimes(1);
93
- });
94
-
95
- it('leaves a pre-initialised SDK alone', async () => {
96
- const init = spyOn(ArgusSDK, 'initialize').mockImplementation(() => {});
97
- const shutdown = spyOn(ArgusSDK, 'shutdown').mockResolvedValue(undefined);
98
- spyOn(ArgusSDK, 'isInitialized').mockReturnValue(true);
99
- const app = await Application.testing({
100
- modules: [withConfig({ serviceName: 'svc' })],
101
- boot: 'eager'
102
- });
103
- await app.shutdown();
104
- expect(init).not.toHaveBeenCalled();
105
- expect(shutdown).not.toHaveBeenCalled();
106
- });
107
-
108
- it('does not shut the SDK down when its init failed', async () => {
109
- spyOn(ArgusSDK, 'initialize').mockImplementation(() => {
110
- throw new Error('boom');
111
- });
112
- const shutdown = spyOn(ArgusSDK, 'shutdown').mockResolvedValue(undefined);
113
- const app = await Application.testing({
114
- modules: [withConfig({ serviceName: 'svc' })],
115
- boot: 'eager'
116
- }).catch(() => undefined);
117
- await app?.shutdown();
118
- expect(shutdown).not.toHaveBeenCalled();
119
- });
120
- });
@@ -1,86 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { trace } from '@opentelemetry/api';
16
- import { afterEach, describe, expect, it, spyOn } from 'bun:test';
17
-
18
- import { withTraceContext } from '../src/correlation';
19
-
20
- describe('withTraceContext', () => {
21
- let getActiveSpanSpy: ReturnType<typeof spyOn>;
22
-
23
- afterEach(() => {
24
- getActiveSpanSpy?.mockRestore();
25
- });
26
-
27
- it('should return context unchanged when no active span', () => {
28
- getActiveSpanSpy = spyOn(trace, 'getActiveSpan').mockReturnValue(undefined as any);
29
-
30
- const ctx = { userId: '123' };
31
- const result = withTraceContext(ctx);
32
-
33
- expect(result).toEqual({ userId: '123' });
34
- expect(result).toBe(ctx); // Same reference
35
- });
36
-
37
- it('should enrich context with traceId and spanId', () => {
38
- const mockSpan = {
39
- spanContext: () => ({
40
- traceId: 'abc123',
41
- spanId: 'def456',
42
- traceFlags: 1
43
- })
44
- };
45
- getActiveSpanSpy = spyOn(trace, 'getActiveSpan').mockReturnValue(mockSpan as any);
46
-
47
- const result = withTraceContext({ userId: '123' });
48
-
49
- expect(result.userId).toBe('123');
50
- expect(result.traceId).toBe('abc123');
51
- expect(result.spanId).toBe('def456');
52
- });
53
-
54
- it('should work with empty context', () => {
55
- const mockSpan = {
56
- spanContext: () => ({
57
- traceId: 'trace-1',
58
- spanId: 'span-1',
59
- traceFlags: 1
60
- })
61
- };
62
- getActiveSpanSpy = spyOn(trace, 'getActiveSpan').mockReturnValue(mockSpan as any);
63
-
64
- const result = withTraceContext();
65
-
66
- expect(result.traceId).toBe('trace-1');
67
- expect(result.spanId).toBe('span-1');
68
- });
69
-
70
- it('should not mutate the original context', () => {
71
- const mockSpan = {
72
- spanContext: () => ({
73
- traceId: 'trace-1',
74
- spanId: 'span-1',
75
- traceFlags: 1
76
- })
77
- };
78
- getActiveSpanSpy = spyOn(trace, 'getActiveSpan').mockReturnValue(mockSpan as any);
79
-
80
- const original = { key: 'value' };
81
- const result = withTraceContext(original);
82
-
83
- expect(original).toEqual({ key: 'value' }); // Not mutated
84
- expect(result).not.toBe(original); // New object
85
- });
86
- });
package/tests/sdk.test.ts DELETED
@@ -1,129 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { afterAll, beforeEach, describe, expect, it, spyOn } from 'bun:test';
16
-
17
- import { ArgusSDK } from '../src/sdk';
18
-
19
- describe('ArgusSDK', () => {
20
- beforeEach(async () => {
21
- // Shut down any existing SDK before resetting
22
- await ArgusSDK.shutdown();
23
- (ArgusSDK as any).instance = undefined;
24
- });
25
-
26
- afterAll(async () => {
27
- await ArgusSDK.shutdown();
28
- (ArgusSDK as any).instance = undefined;
29
- });
30
-
31
- describe('initialize', () => {
32
- it('should create an instance when enabled is false', () => {
33
- ArgusSDK.initialize({
34
- enabled: false,
35
- serviceName: 'test-service',
36
- exporter: 'console'
37
- });
38
-
39
- // Should not throw, instance is created but SDK not started
40
- expect((ArgusSDK as any).instance).toBeDefined();
41
- });
42
-
43
- it('should log error on duplicate initialization', () => {
44
- const errorSpy = spyOn(console, 'error').mockImplementation(() => {});
45
-
46
- ArgusSDK.initialize({
47
- enabled: false,
48
- serviceName: 'test-1',
49
- exporter: 'console'
50
- });
51
-
52
- ArgusSDK.initialize({
53
- enabled: false,
54
- serviceName: 'test-2',
55
- exporter: 'console'
56
- });
57
-
58
- expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('already initialized'));
59
-
60
- errorSpy.mockRestore();
61
- });
62
-
63
- it('should initialize with console exporter', () => {
64
- ArgusSDK.initialize({
65
- enabled: true,
66
- serviceName: 'test-service',
67
- exporter: 'console'
68
- });
69
-
70
- expect((ArgusSDK as any).instance).toBeDefined();
71
- expect((ArgusSDK as any).instance.sdk).toBeDefined();
72
- });
73
-
74
- it('should initialize with otlp-http exporter', () => {
75
- ArgusSDK.initialize({
76
- enabled: true,
77
- serviceName: 'test-service',
78
- exporter: 'otlp-http',
79
- endpoint: 'http://localhost:4318/v1/traces'
80
- });
81
-
82
- expect((ArgusSDK as any).instance).toBeDefined();
83
- expect((ArgusSDK as any).instance.sdk).toBeDefined();
84
- });
85
-
86
- it('should accept samplingRate option', () => {
87
- ArgusSDK.initialize({
88
- enabled: true,
89
- serviceName: 'test-service',
90
- exporter: 'console',
91
- samplingRate: 0.5
92
- });
93
-
94
- expect((ArgusSDK as any).instance.sdk).toBeDefined();
95
- });
96
- });
97
-
98
- describe('shutdown', () => {
99
- it('should not throw when not initialized', async () => {
100
- await expect(ArgusSDK.shutdown()).resolves.toBeUndefined();
101
- });
102
-
103
- it('should not throw when initialized but disabled', async () => {
104
- ArgusSDK.initialize({
105
- enabled: false,
106
- serviceName: 'test-service',
107
- exporter: 'console'
108
- });
109
-
110
- await expect(ArgusSDK.shutdown()).resolves.toBeUndefined();
111
- });
112
-
113
- it('should shut down the SDK when initialized', async () => {
114
- ArgusSDK.initialize({
115
- enabled: true,
116
- serviceName: 'test-service',
117
- exporter: 'console'
118
- });
119
-
120
- const sdk = (ArgusSDK as any).instance.sdk;
121
- const shutdownSpy = spyOn(sdk, 'shutdown').mockResolvedValue(undefined);
122
-
123
- await ArgusSDK.shutdown();
124
- expect(shutdownSpy).toHaveBeenCalled();
125
-
126
- shutdownSpy.mockRestore();
127
- });
128
- });
129
- });
package/tests/setup.ts DELETED
@@ -1,13 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
@@ -1,173 +0,0 @@
1
- // Copyright (c) 2026-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { SpanStatusCode, trace } from '@opentelemetry/api';
16
- import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test';
17
-
18
- import { Traced } from '../src/decorators/traced';
19
-
20
- describe('@Traced decorator', () => {
21
- let mockSpan: any;
22
- let mockTracer: any;
23
- let getTracerSpy: ReturnType<typeof spyOn>;
24
-
25
- beforeEach(() => {
26
- mockSpan = {
27
- setStatus: mock(() => {}),
28
- recordException: mock(() => {}),
29
- end: mock(() => {})
30
- };
31
-
32
- mockTracer = {
33
- startActiveSpan: mock(async (_name: string, _options: any, fn: any) => {
34
- return fn(mockSpan);
35
- })
36
- };
37
-
38
- getTracerSpy = spyOn(trace, 'getTracer').mockReturnValue(mockTracer);
39
- });
40
-
41
- afterEach(() => {
42
- getTracerSpy.mockRestore();
43
- });
44
-
45
- it('should call the original method and return its result', async () => {
46
- class MyService {
47
- @Traced()
48
- async greet(name: string): Promise<string> {
49
- return `Hello, ${name}`;
50
- }
51
- }
52
-
53
- const service = new MyService();
54
- const result = await service.greet('World');
55
- expect(result).toBe('Hello, World');
56
- });
57
-
58
- it('should create a span with default name', async () => {
59
- class MyService {
60
- @Traced()
61
- async doWork(): Promise<void> {}
62
- }
63
-
64
- const service = new MyService();
65
- await service.doWork();
66
-
67
- expect(mockTracer.startActiveSpan).toHaveBeenCalled();
68
- const [spanName] = mockTracer.startActiveSpan.mock.calls[0];
69
- expect(spanName).toBe('MyService.doWork');
70
- });
71
-
72
- it('should create a span with custom name', async () => {
73
- class MyService {
74
- @Traced('custom.span.name')
75
- async doWork(): Promise<void> {}
76
- }
77
-
78
- const service = new MyService();
79
- await service.doWork();
80
-
81
- const [spanName] = mockTracer.startActiveSpan.mock.calls[0];
82
- expect(spanName).toBe('custom.span.name');
83
- });
84
-
85
- it('should set OK status on success', async () => {
86
- class MyService {
87
- @Traced()
88
- async success(): Promise<string> {
89
- return 'ok';
90
- }
91
- }
92
-
93
- const service = new MyService();
94
- await service.success();
95
-
96
- expect(mockSpan.setStatus).toHaveBeenCalledWith({
97
- code: SpanStatusCode.OK
98
- });
99
- expect(mockSpan.end).toHaveBeenCalled();
100
- });
101
-
102
- it('should set ERROR status and record exception on failure', async () => {
103
- const error = new Error('test failure');
104
-
105
- class MyService {
106
- @Traced()
107
- async failing(): Promise<void> {
108
- throw error;
109
- }
110
- }
111
-
112
- const service = new MyService();
113
- await expect(service.failing()).rejects.toThrow('test failure');
114
-
115
- expect(mockSpan.setStatus).toHaveBeenCalledWith({
116
- code: SpanStatusCode.ERROR,
117
- message: 'test failure'
118
- });
119
- expect(mockSpan.recordException).toHaveBeenCalledWith(error);
120
- expect(mockSpan.end).toHaveBeenCalled();
121
- });
122
-
123
- it('should handle non-Error throws', async () => {
124
- class MyService {
125
- @Traced()
126
- async throwString(): Promise<void> {
127
- throw 'string error';
128
- }
129
- }
130
-
131
- const service = new MyService();
132
- try {
133
- await service.throwString();
134
- } catch {
135
- // expected
136
- }
137
-
138
- expect(mockSpan.setStatus).toHaveBeenCalledWith({
139
- code: SpanStatusCode.ERROR,
140
- message: 'Unknown error'
141
- });
142
- });
143
-
144
- it('should always end the span', async () => {
145
- class MyService {
146
- @Traced()
147
- async mayFail(): Promise<void> {
148
- throw new Error('fail');
149
- }
150
- }
151
-
152
- const service = new MyService();
153
- try {
154
- await service.mayFail();
155
- } catch {
156
- // expected
157
- }
158
-
159
- expect(mockSpan.end).toHaveBeenCalledTimes(1);
160
- });
161
-
162
- it('should use the @elysiumjs/argus tracer', async () => {
163
- class MyService {
164
- @Traced()
165
- async work(): Promise<void> {}
166
- }
167
-
168
- const service = new MyService();
169
- await service.work();
170
-
171
- expect(getTracerSpy).toHaveBeenCalledWith('@elysiumjs/argus');
172
- });
173
- });