@elysiumjs/argus 0.1.1 → 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/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,24 +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 'reflect-metadata';
16
-
17
- import { mock } from 'bun:test';
18
-
19
- mock.module('node:async_hooks', () => ({
20
- AsyncLocalStorage: class {
21
- public run = mock((_map: any, callback: any) => callback());
22
- public disable = mock();
23
- }
24
- }));
@@ -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
- });
@@ -1,65 +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 { describe, expect, it } from 'bun:test';
16
-
17
- import type { TracingConfig } from '../src/types';
18
-
19
- describe('TracingConfig type', () => {
20
- it('should accept a minimal config', () => {
21
- const config: TracingConfig = {
22
- enabled: true,
23
- serviceName: 'my-service',
24
- exporter: 'console'
25
- };
26
-
27
- expect(config.enabled).toBe(true);
28
- expect(config.serviceName).toBe('my-service');
29
- expect(config.exporter).toBe('console');
30
- });
31
-
32
- it('should accept otlp-http exporter with endpoint', () => {
33
- const config: TracingConfig = {
34
- enabled: true,
35
- serviceName: 'my-service',
36
- exporter: 'otlp-http',
37
- endpoint: 'http://localhost:4318/v1/traces'
38
- };
39
-
40
- expect(config.exporter).toBe('otlp-http');
41
- expect(config.endpoint).toBe('http://localhost:4318/v1/traces');
42
- });
43
-
44
- it('should accept samplingRate', () => {
45
- const config: TracingConfig = {
46
- enabled: true,
47
- serviceName: 'my-service',
48
- exporter: 'console',
49
- samplingRate: 0.5
50
- };
51
-
52
- expect(config.samplingRate).toBe(0.5);
53
- });
54
-
55
- it('should allow optional fields to be undefined', () => {
56
- const config: TracingConfig = {
57
- enabled: false,
58
- serviceName: 'test',
59
- exporter: 'console'
60
- };
61
-
62
- expect(config.endpoint).toBeUndefined();
63
- expect(config.samplingRate).toBeUndefined();
64
- });
65
- });
package/tsconfig.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "noEmit": true
5
- }
6
- }