node-telemetry-trace 1.0.0 → 1.1.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/.github/workflows/ci.yml +13 -0
- package/CHANGELOG.md +12 -0
- package/CONTRIBUTING.md +12 -0
- package/dist/context/context.d.ts +7 -0
- package/dist/context/context.js +16 -0
- package/dist/exporters/console.exporter.d.ts +4 -0
- package/dist/exporters/console.exporter.js +15 -0
- package/dist/exporters/console.exporter.spec.d.ts +1 -0
- package/dist/exporters/console.exporter.spec.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +1 -1
- package/jest.config.js +0 -7
- package/src/index.ts +0 -2
- package/src/interfaces/span.interface.ts +0 -14
- package/src/services/tracing.service.spec.ts +0 -22
- package/src/services/tracing.service.ts +0 -23
- package/tsconfig.json +0 -10
package/CHANGELOG.md
ADDED
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TracingContext = void 0;
|
|
4
|
+
class TracingContext {
|
|
5
|
+
static setSpan(key, span) {
|
|
6
|
+
this.contexts.set(key, span);
|
|
7
|
+
}
|
|
8
|
+
static getSpan(key) {
|
|
9
|
+
return this.contexts.get(key);
|
|
10
|
+
}
|
|
11
|
+
static clear(key) {
|
|
12
|
+
this.contexts.delete(key);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.TracingContext = TracingContext;
|
|
16
|
+
TracingContext.contexts = new Map();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsoleExporter = void 0;
|
|
4
|
+
class ConsoleExporter {
|
|
5
|
+
export(span) {
|
|
6
|
+
console.log('[Trace]', {
|
|
7
|
+
traceId: span.traceId,
|
|
8
|
+
spanId: span.spanId,
|
|
9
|
+
operation: span.operationName,
|
|
10
|
+
duration: span.endTime ? span.endTime.getTime() - span.startTime.getTime() : 0,
|
|
11
|
+
tags: span.tags,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ConsoleExporter = ConsoleExporter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const console_exporter_1 = require("./console.exporter");
|
|
4
|
+
describe('ConsoleExporter', () => {
|
|
5
|
+
let exporter;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
exporter = new console_exporter_1.ConsoleExporter();
|
|
8
|
+
});
|
|
9
|
+
it('should export span to console', () => {
|
|
10
|
+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
11
|
+
const span = {
|
|
12
|
+
spanId: '123',
|
|
13
|
+
traceId: '456',
|
|
14
|
+
operationName: 'test-op',
|
|
15
|
+
startTime: new Date(),
|
|
16
|
+
endTime: new Date(),
|
|
17
|
+
tags: {},
|
|
18
|
+
end: jest.fn(),
|
|
19
|
+
};
|
|
20
|
+
exporter.export(span);
|
|
21
|
+
expect(consoleSpy).toHaveBeenCalled();
|
|
22
|
+
consoleSpy.mockRestore();
|
|
23
|
+
});
|
|
24
|
+
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./services/tracing.service"), exports);
|
|
18
18
|
__exportStar(require("./interfaces/span.interface"), exports);
|
|
19
|
+
__exportStar(require("./context/context"), exports);
|
|
20
|
+
__exportStar(require("./exporters/console.exporter"), exports);
|
package/package.json
CHANGED
package/jest.config.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export interface Span {
|
|
2
|
-
spanId: string;
|
|
3
|
-
traceId: string;
|
|
4
|
-
operationName: string;
|
|
5
|
-
startTime: Date;
|
|
6
|
-
endTime?: Date;
|
|
7
|
-
tags: Record<string, any>;
|
|
8
|
-
end(): void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface TracingOptions {
|
|
12
|
-
serviceName: string;
|
|
13
|
-
sampleRate?: number;
|
|
14
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { TracingService } from './tracing.service';
|
|
2
|
-
|
|
3
|
-
describe('TracingService', () => {
|
|
4
|
-
let service: TracingService;
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
service = new TracingService({ serviceName: 'test-service' });
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should create spans', () => {
|
|
11
|
-
const span = service.startSpan('test-operation');
|
|
12
|
-
expect(span).toBeDefined();
|
|
13
|
-
expect(span.operationName).toBe('test-operation');
|
|
14
|
-
expect(span.spanId).toBeDefined();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should end spans', () => {
|
|
18
|
-
const span = service.startSpan('test-operation');
|
|
19
|
-
span.end();
|
|
20
|
-
expect(span.endTime).toBeDefined();
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Span, TracingOptions } from '../interfaces/span.interface';
|
|
2
|
-
|
|
3
|
-
export class TracingService {
|
|
4
|
-
constructor(private options: TracingOptions) {}
|
|
5
|
-
|
|
6
|
-
startSpan(operationName: string): Span {
|
|
7
|
-
const span: Span = {
|
|
8
|
-
spanId: this.generateId(),
|
|
9
|
-
traceId: this.generateId(),
|
|
10
|
-
operationName,
|
|
11
|
-
startTime: new Date(),
|
|
12
|
-
tags: {},
|
|
13
|
-
end: function() {
|
|
14
|
-
this.endTime = new Date();
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
return span;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private generateId(): string {
|
|
21
|
-
return Math.random().toString(36).substring(7);
|
|
22
|
-
}
|
|
23
|
-
}
|