nestjs-otel 3.0.0 → 3.0.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/CHANGELOG.md +21 -0
- package/README.md +34 -40
- package/examples/nestjs-prom-grafana-tempo/package.json +40 -37
- package/examples/nestjs-prom-grafana-tempo/src/tracing.ts +5 -5
- package/lib/metrics/metric-data.d.ts +4 -4
- package/lib/metrics/metric-data.js +6 -6
- package/lib/metrics/metric-data.js.map +1 -1
- package/lib/metrics/metric.service.d.ts +4 -4
- package/lib/metrics/metric.service.js +6 -6
- package/lib/metrics/metric.service.js.map +1 -1
- package/lib/tracing/decorators/span.js +23 -7
- package/lib/tracing/decorators/span.js.map +1 -1
- package/lib/tracing/decorators/span.spec.d.ts +1 -0
- package/lib/tracing/decorators/span.spec.js +96 -0
- package/lib/tracing/decorators/span.spec.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/src/metrics/metric-data.ts +7 -4
- package/src/metrics/metric.service.ts +20 -8
- package/src/tracing/decorators/span.spec.ts +91 -0
- package/src/tracing/decorators/span.ts +29 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
### [3.0.3](https://www.github.com/pragmaticivan/nestjs-otel/compare/v3.0.2...v3.0.3) (2022-03-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **tracing:** record exception and set correct span status ([616c12b](https://www.github.com/pragmaticivan/nestjs-otel/commit/616c12b157f7736e9fd45cd38bf9a4c21c11e140))
|
|
9
|
+
|
|
10
|
+
### [3.0.2](https://www.github.com/pragmaticivan/nestjs-otel/compare/v3.0.1...v3.0.2) (2022-03-24)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **tracing:** use startActiveSpan to ensure span in correct context ([d608b84](https://www.github.com/pragmaticivan/nestjs-otel/commit/d608b84e582b41105c6871ee2e7174f7a0116d96))
|
|
16
|
+
|
|
17
|
+
### [3.0.1](https://www.github.com/pragmaticivan/nestjs-otel/compare/v3.0.0...v3.0.1) (2022-01-03)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **#171:** fixes missing observation callback for observable metrics ([7d89c1f](https://www.github.com/pragmaticivan/nestjs-otel/commit/7d89c1f910b28d0661da6f2989ddea4b9bdcc643)), closes [#171](https://www.github.com/pragmaticivan/nestjs-otel/issues/171)
|
|
23
|
+
|
|
3
24
|
## [3.0.0](https://www.github.com/pragmaticivan/nestjs-otel/compare/v2.6.1...v3.0.0) (2021-12-30)
|
|
4
25
|
|
|
5
26
|
|
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
[](https://www.npmjs.com/package/nestjs-otel)
|
|
9
|
+
|
|
9
10
|
## Description
|
|
10
11
|
|
|
11
12
|
[OpenTelemetry](https://opentelemetry.io/) module for [Nest](https://github.com/nestjs/nest).
|
|
@@ -16,7 +17,7 @@ For questions and support please use the official [Discord channel](https://disc
|
|
|
16
17
|
|
|
17
18
|
## Why
|
|
18
19
|
|
|
19
|
-
Setting up observability metrics with nestjs requires multiple libraries and patterns. OpenTelemetry has support for multiple exporters and
|
|
20
|
+
Setting up observability metrics with nestjs requires multiple libraries and patterns. OpenTelemetry has support for multiple exporters and types of metrics such as Prometheus Metrics.
|
|
20
21
|
|
|
21
22
|
## Observability
|
|
22
23
|
|
|
@@ -43,10 +44,10 @@ Some peers dependencies are required when some configurations are enabled.
|
|
|
43
44
|
```ts
|
|
44
45
|
import {
|
|
45
46
|
CompositePropagator,
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
W3CTraceContextPropagator,
|
|
48
|
+
W3CBaggagePropagator,
|
|
48
49
|
} from '@opentelemetry/core';
|
|
49
|
-
import { BatchSpanProcessor } from '@opentelemetry/
|
|
50
|
+
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
50
51
|
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
|
|
51
52
|
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
52
53
|
import { JaegerPropagator } from '@opentelemetry/propagator-jaeger';
|
|
@@ -66,8 +67,8 @@ const otelSDK = new NodeSDK({
|
|
|
66
67
|
textMapPropagator: new CompositePropagator({
|
|
67
68
|
propagators: [
|
|
68
69
|
new JaegerPropagator(),
|
|
69
|
-
new
|
|
70
|
-
new
|
|
70
|
+
new W3CTraceContextPropagator(),
|
|
71
|
+
new W3CBaggagePropagator(),
|
|
71
72
|
new B3Propagator(),
|
|
72
73
|
new B3Propagator({
|
|
73
74
|
injectEncoding: B3InjectEncoding.MULTI_HEADER,
|
|
@@ -78,6 +79,7 @@ const otelSDK = new NodeSDK({
|
|
|
78
79
|
});
|
|
79
80
|
|
|
80
81
|
export default otelSDK;
|
|
82
|
+
|
|
81
83
|
// You can also use the shutdown method to gracefully shut down the SDK before process shutdown
|
|
82
84
|
// or on some operating system signal.
|
|
83
85
|
process.on('SIGTERM', () => {
|
|
@@ -85,7 +87,7 @@ process.on('SIGTERM', () => {
|
|
|
85
87
|
.shutdown()
|
|
86
88
|
.then(
|
|
87
89
|
() => console.log('SDK shut down successfully'),
|
|
88
|
-
|
|
90
|
+
err => console.log('Error shutting down SDK', err)
|
|
89
91
|
)
|
|
90
92
|
.finally(() => process.exit(0));
|
|
91
93
|
});
|
|
@@ -120,8 +122,9 @@ const OpenTelemetryModuleConfig = OpenTelemetryModule.forRoot({
|
|
|
120
122
|
apiMetrics: {
|
|
121
123
|
enable: true, // Includes api metrics
|
|
122
124
|
timeBuckets: [], // You can change the default time buckets
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
defaultAttributes: {
|
|
126
|
+
// You can set default labels for api metrics
|
|
127
|
+
custom: 'label',
|
|
125
128
|
},
|
|
126
129
|
ignoreRoutes: ['/favicon.ico'], // You can ignore specific routes (See https://docs.nestjs.com/middleware#excluding-routes for options)
|
|
127
130
|
ignoreUndefinedRoutes: false, //Records metrics for all URLs, even undefined ones
|
|
@@ -130,9 +133,7 @@ const OpenTelemetryModuleConfig = OpenTelemetryModule.forRoot({
|
|
|
130
133
|
});
|
|
131
134
|
|
|
132
135
|
@Module({
|
|
133
|
-
imports: [
|
|
134
|
-
OpenTelemetryModuleConfig,
|
|
135
|
-
],
|
|
136
|
+
imports: [OpenTelemetryModuleConfig],
|
|
136
137
|
})
|
|
137
138
|
export class AppModule {}
|
|
138
139
|
```
|
|
@@ -210,9 +211,7 @@ If you want to count how many instance of a specific class has been created:
|
|
|
210
211
|
|
|
211
212
|
```ts
|
|
212
213
|
@OtelInstanceCounter() // It will generate a counter called: app_MyClass_instances_total.
|
|
213
|
-
export class MyClass {
|
|
214
|
-
|
|
215
|
-
}
|
|
214
|
+
export class MyClass {}
|
|
216
215
|
```
|
|
217
216
|
|
|
218
217
|
### Metric Class Method
|
|
@@ -223,9 +222,7 @@ If you want to increment a counter on each call of a specific method:
|
|
|
223
222
|
@Injectable()
|
|
224
223
|
export class MyService {
|
|
225
224
|
@OtelMethodCounter()
|
|
226
|
-
doSomething() {
|
|
227
|
-
|
|
228
|
-
}
|
|
225
|
+
doSomething() {}
|
|
229
226
|
}
|
|
230
227
|
@Controller()
|
|
231
228
|
export class AppController {
|
|
@@ -241,12 +238,12 @@ export class AppController {
|
|
|
241
238
|
|
|
242
239
|
You have the following decorators:
|
|
243
240
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
241
|
+
- `@OtelCounter()`
|
|
242
|
+
- `@OtelUpDownCounter()`
|
|
243
|
+
- `@OtelHistogram()`
|
|
244
|
+
- `@OtelObservableGauge()`
|
|
245
|
+
- `@OtelObservableCounter()`
|
|
246
|
+
- `@OtelObservableUpDownCounter()`
|
|
250
247
|
|
|
251
248
|
Example of usage:
|
|
252
249
|
|
|
@@ -256,31 +253,29 @@ import { Counter } from '@opentelemetry/api-metrics';
|
|
|
256
253
|
|
|
257
254
|
@Controller()
|
|
258
255
|
export class AppController {
|
|
259
|
-
|
|
260
256
|
@Get('/home')
|
|
261
257
|
home(
|
|
262
|
-
@OtelCounter('app_counter_1_inc', { description: 'counter 1 description' }) counter1: Counter
|
|
258
|
+
@OtelCounter('app_counter_1_inc', { description: 'counter 1 description' }) counter1: Counter
|
|
263
259
|
) {
|
|
264
260
|
counter1.add(1);
|
|
265
261
|
}
|
|
266
262
|
}
|
|
267
|
-
|
|
268
263
|
```
|
|
269
264
|
|
|
270
265
|
## API Metrics with Middleware
|
|
271
266
|
|
|
272
|
-
Impl |Metric
|
|
273
|
-
|
|
274
|
-
| ✅
|
|
275
|
-
| ✅
|
|
276
|
-
| ✅
|
|
277
|
-
| ✅
|
|
278
|
-
| ✅
|
|
279
|
-
| ✅
|
|
280
|
-
| ✅
|
|
281
|
-
| ✅
|
|
282
|
-
| ✅
|
|
283
|
-
| ✅
|
|
267
|
+
| Impl | Metric | Description | Labels | Metric Type |
|
|
268
|
+
| ---- | ----------------------------- | ----------------------------------------- | -------------------- | ----------- |
|
|
269
|
+
| ✅ | http_request_total | Total number of HTTP requests. | method, path | Counter |
|
|
270
|
+
| ✅ | http_response_total | Total number of HTTP responses. | method, status, path | Counter |
|
|
271
|
+
| ✅ | http_response_success_total | Total number of all successful responses. | - | Counter |
|
|
272
|
+
| ✅ | http_response_error_total | Total number of all response errors. | - | Counter |
|
|
273
|
+
| ✅ | http_request_duration_seconds | HTTP latency value recorder in seconds. | method, status, path | Histogram |
|
|
274
|
+
| ✅ | http_client_error_total | Total number of client error requests. | - | Counter |
|
|
275
|
+
| ✅ | http_server_error_total | Total number of server error requests. | - | Counter |
|
|
276
|
+
| ✅ | http_server_aborts_total | Total number of data transfers aborted. | - | Counter |
|
|
277
|
+
| ✅ | http_request_size_bytes | Current total of incoming bytes. | - | Histogram |
|
|
278
|
+
| ✅ | http_response_size_bytes | Current total of outgoing bytes. | - | Histogram |
|
|
284
279
|
|
|
285
280
|
## Prometheus Metrics
|
|
286
281
|
|
|
@@ -335,7 +330,6 @@ Logs are automatically associated with tracing (Loki + Tempo):
|
|
|
335
330
|
|
|
336
331
|

|
|
337
332
|
|
|
338
|
-
|
|
339
333
|
## Stargazers over time
|
|
340
334
|
|
|
341
335
|
[](https://starchart.cc/pragmaticivan/nestjs-otel)
|
|
@@ -21,50 +21,53 @@
|
|
|
21
21
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@nestjs/common": "^8.
|
|
25
|
-
"@nestjs/core": "^8.
|
|
26
|
-
"@nestjs/platform-express": "^8.
|
|
27
|
-
"@nestjs/swagger": "^5.
|
|
28
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
29
|
-
"@opentelemetry/core": "^0.
|
|
30
|
-
"@opentelemetry/exporter-jaeger": "^0.
|
|
31
|
-
"@opentelemetry/exporter-prometheus": "^0.
|
|
32
|
-
"@opentelemetry/host-metrics": "^0.
|
|
33
|
-
"@opentelemetry/
|
|
34
|
-
"@opentelemetry/propagator-b3": "^0.
|
|
35
|
-
"@opentelemetry/propagator-jaeger": "^0.
|
|
36
|
-
"@opentelemetry/sdk-node": "^0.
|
|
37
|
-
"@
|
|
38
|
-
"nestjs-otel": "^
|
|
39
|
-
"nestjs-pino": "^
|
|
40
|
-
"opentelemetry-node-metrics": "^1.0
|
|
41
|
-
"pino": "^6.
|
|
24
|
+
"@nestjs/common": "^8.2.4",
|
|
25
|
+
"@nestjs/core": "^8.2.4",
|
|
26
|
+
"@nestjs/platform-express": "^8.2.4",
|
|
27
|
+
"@nestjs/swagger": "^5.1.5",
|
|
28
|
+
"@opentelemetry/auto-instrumentations-node": "^0.27.1",
|
|
29
|
+
"@opentelemetry/core": "^1.0.1",
|
|
30
|
+
"@opentelemetry/exporter-jaeger": "^1.0.1",
|
|
31
|
+
"@opentelemetry/exporter-prometheus": "^0.27.0",
|
|
32
|
+
"@opentelemetry/host-metrics": "^0.27.0",
|
|
33
|
+
"@opentelemetry/instrumentation-graphql": "^0.27.1",
|
|
34
|
+
"@opentelemetry/propagator-b3": "^1.0.1",
|
|
35
|
+
"@opentelemetry/propagator-jaeger": "^1.0.1",
|
|
36
|
+
"@opentelemetry/sdk-node": "^0.27.0",
|
|
37
|
+
"@types/graphql": "^14.5.0",
|
|
38
|
+
"nestjs-otel": "^3.0.0",
|
|
39
|
+
"nestjs-pino": "^2.4.0",
|
|
40
|
+
"opentelemetry-node-metrics": "^1.1.0",
|
|
41
|
+
"pino": "^7.6.2",
|
|
42
|
+
"pino-http": "^6.5.0",
|
|
42
43
|
"reflect-metadata": "^0.1.13",
|
|
43
44
|
"rimraf": "^3.0.2",
|
|
44
|
-
"rxjs": "^7.
|
|
45
|
-
"swagger-ui-express": "^4.
|
|
45
|
+
"rxjs": "^7.5.1",
|
|
46
|
+
"swagger-ui-express": "^4.3.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@nestjs/cli": "^8.1.
|
|
49
|
-
"@nestjs/schematics": "^8.0.
|
|
50
|
-
"@nestjs/testing": "^8.
|
|
49
|
+
"@nestjs/cli": "^8.1.6",
|
|
50
|
+
"@nestjs/schematics": "^8.0.5",
|
|
51
|
+
"@nestjs/testing": "^8.2.4",
|
|
52
|
+
"@opentelemetry/api-metrics": "^0.27.0",
|
|
51
53
|
"@types/express": "^4.17.13",
|
|
52
|
-
"@types/jest": "^
|
|
53
|
-
"@types/node": "^
|
|
54
|
+
"@types/jest": "^27.0.3",
|
|
55
|
+
"@types/node": "^17.0.5",
|
|
56
|
+
"@types/pino-http": "^5.8.1",
|
|
54
57
|
"@types/supertest": "^2.0.11",
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
56
|
-
"@typescript-eslint/parser": "^
|
|
57
|
-
"eslint": "^
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
|
59
|
+
"@typescript-eslint/parser": "^5.8.1",
|
|
60
|
+
"eslint": "^8.5.0",
|
|
58
61
|
"eslint-config-prettier": "8.3.0",
|
|
59
|
-
"eslint-plugin-prettier": "^
|
|
60
|
-
"jest": "^27.
|
|
61
|
-
"prettier": "^2.
|
|
62
|
-
"supertest": "^6.1.
|
|
63
|
-
"ts-jest": "^27.
|
|
64
|
-
"ts-loader": "^9.2.
|
|
65
|
-
"ts-node": "^10.
|
|
66
|
-
"tsconfig-paths": "^3.
|
|
67
|
-
"typescript": "^4.
|
|
62
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
63
|
+
"jest": "^27.4.5",
|
|
64
|
+
"prettier": "^2.5.1",
|
|
65
|
+
"supertest": "^6.1.6",
|
|
66
|
+
"ts-jest": "^27.1.2",
|
|
67
|
+
"ts-loader": "^9.2.6",
|
|
68
|
+
"ts-node": "^10.4.0",
|
|
69
|
+
"tsconfig-paths": "^3.12.0",
|
|
70
|
+
"typescript": "^4.5.4"
|
|
68
71
|
},
|
|
69
72
|
"jest": {
|
|
70
73
|
"moduleFileExtensions": [
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CompositePropagator,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
W3CTraceContextPropagator,
|
|
4
|
+
W3CBaggagePropagator,
|
|
5
5
|
} from '@opentelemetry/core';
|
|
6
|
-
import { BatchSpanProcessor } from '@opentelemetry/
|
|
6
|
+
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
7
7
|
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
|
|
8
8
|
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
9
9
|
import { JaegerPropagator } from '@opentelemetry/propagator-jaeger';
|
|
@@ -23,8 +23,8 @@ const otelSDK = new NodeSDK({
|
|
|
23
23
|
textMapPropagator: new CompositePropagator({
|
|
24
24
|
propagators: [
|
|
25
25
|
new JaegerPropagator(),
|
|
26
|
-
new
|
|
27
|
-
new
|
|
26
|
+
new W3CTraceContextPropagator(),
|
|
27
|
+
new W3CBaggagePropagator(),
|
|
28
28
|
new B3Propagator(),
|
|
29
29
|
new B3Propagator({
|
|
30
30
|
injectEncoding: B3InjectEncoding.MULTI_HEADER,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Counter, MetricOptions, UpDownCounter, Histogram, ObservableGauge, ObservableCounter, ObservableUpDownCounter } from '@opentelemetry/api-metrics';
|
|
1
|
+
import { Counter, MetricOptions, UpDownCounter, Histogram, ObservableGauge, ObservableCounter, ObservableUpDownCounter, ObservableResult } from '@opentelemetry/api-metrics';
|
|
2
2
|
export declare type GenericMetric = Counter | UpDownCounter | Histogram | ObservableGauge | ObservableCounter | ObservableUpDownCounter;
|
|
3
3
|
export declare enum MetricType {
|
|
4
4
|
'Counter' = "Counter",
|
|
@@ -12,6 +12,6 @@ export declare const meterData: Map<string, GenericMetric>;
|
|
|
12
12
|
export declare function getOrCreateHistogram(name: string, options: MetricOptions): Histogram;
|
|
13
13
|
export declare function getOrCreateCounter(name: string, options: MetricOptions): Counter;
|
|
14
14
|
export declare function getOrCreateUpDownCounter(name: string, options: MetricOptions): UpDownCounter;
|
|
15
|
-
export declare function getOrCreateObservableGauge(name: string, options: MetricOptions): ObservableGauge;
|
|
16
|
-
export declare function getOrCreateObservableCounter(name: string, options: MetricOptions): ObservableCounter;
|
|
17
|
-
export declare function getOrCreateObservableUpDownCounter(name: string, options: MetricOptions): ObservableUpDownCounter;
|
|
15
|
+
export declare function getOrCreateObservableGauge(name: string, options: MetricOptions, callback?: (observableResult: ObservableResult) => void): ObservableGauge;
|
|
16
|
+
export declare function getOrCreateObservableCounter(name: string, options: MetricOptions, callback?: (observableResult: ObservableResult) => void): ObservableCounter;
|
|
17
|
+
export declare function getOrCreateObservableUpDownCounter(name: string, options: MetricOptions, callback?: (observableResult: ObservableResult) => void): ObservableUpDownCounter;
|
|
@@ -43,32 +43,32 @@ function getOrCreateUpDownCounter(name, options) {
|
|
|
43
43
|
return upDownCounter;
|
|
44
44
|
}
|
|
45
45
|
exports.getOrCreateUpDownCounter = getOrCreateUpDownCounter;
|
|
46
|
-
function getOrCreateObservableGauge(name, options) {
|
|
46
|
+
function getOrCreateObservableGauge(name, options, callback) {
|
|
47
47
|
if (exports.meterData.has(name)) {
|
|
48
48
|
return exports.meterData.get(name);
|
|
49
49
|
}
|
|
50
50
|
const meter = api_metrics_1.metrics.getMeterProvider().getMeter(opentelemetry_constants_1.OTEL_METER_NAME);
|
|
51
|
-
const observableGauge = meter.createObservableGauge(name, options);
|
|
51
|
+
const observableGauge = meter.createObservableGauge(name, options, callback);
|
|
52
52
|
exports.meterData.set(name, observableGauge);
|
|
53
53
|
return observableGauge;
|
|
54
54
|
}
|
|
55
55
|
exports.getOrCreateObservableGauge = getOrCreateObservableGauge;
|
|
56
|
-
function getOrCreateObservableCounter(name, options) {
|
|
56
|
+
function getOrCreateObservableCounter(name, options, callback) {
|
|
57
57
|
if (exports.meterData.has(name)) {
|
|
58
58
|
return exports.meterData.get(name);
|
|
59
59
|
}
|
|
60
60
|
const meter = api_metrics_1.metrics.getMeterProvider().getMeter(opentelemetry_constants_1.OTEL_METER_NAME);
|
|
61
|
-
const observableCounter = meter.createObservableCounter(name, options);
|
|
61
|
+
const observableCounter = meter.createObservableCounter(name, options, callback);
|
|
62
62
|
exports.meterData.set(name, observableCounter);
|
|
63
63
|
return observableCounter;
|
|
64
64
|
}
|
|
65
65
|
exports.getOrCreateObservableCounter = getOrCreateObservableCounter;
|
|
66
|
-
function getOrCreateObservableUpDownCounter(name, options) {
|
|
66
|
+
function getOrCreateObservableUpDownCounter(name, options, callback) {
|
|
67
67
|
if (exports.meterData.has(name)) {
|
|
68
68
|
return exports.meterData.get(name);
|
|
69
69
|
}
|
|
70
70
|
const meter = api_metrics_1.metrics.getMeterProvider().getMeter(opentelemetry_constants_1.OTEL_METER_NAME);
|
|
71
|
-
const observableCounter = meter.createObservableCounter(name, options);
|
|
71
|
+
const observableCounter = meter.createObservableCounter(name, options, callback);
|
|
72
72
|
exports.meterData.set(name, observableCounter);
|
|
73
73
|
return observableCounter;
|
|
74
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metric-data.js","sourceRoot":"","sources":["../../src/metrics/metric-data.ts"],"names":[],"mappings":";;;AAAA,4DAGoC;AACpC,wEAA6D;AAU7D,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,iCAAqB,CAAA;IACrB,6CAAiC,CAAA;IACjC,qCAAyB,CAAA;IACzB,iDAAqC,CAAA;IACrC,qDAAyC,CAAA;IACzC,iEAAqD,CAAA;AACvD,CAAC,EAPW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAOrB;AAEY,QAAA,SAAS,GAA+B,IAAI,GAAG,EAAE,CAAC;AAE/D,SAAgB,oBAAoB,CAClC,IAAY,EACZ,OAAsB;IAEtB,IAAI,iBAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,iBAAS,CAAC,GAAG,CAAC,IAAI,CAAc,CAAC;KACzC;IAED,MAAM,KAAK,GAAG,qBAAO,CAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC,yCAAe,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACvD,iBAAS,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC/B,OAAO,SAAS,CAAC;AACnB,CAAC;AAZD,oDAYC;AAED,SAAgB,kBAAkB,CAChC,IAAY,EACZ,OAAsB;IAEtB,IAAI,iBAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,iBAAS,CAAC,GAAG,CAAC,IAAI,CAAY,CAAC;KACvC;IAED,MAAM,KAAK,GAAG,qBAAO,CAAC,gB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AAiB,GAAG,KAAK,CAAC,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjF,iBAAS,CAAC,GAAG,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACvC,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAdD,gFAcC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MetricOptions } from '@opentelemetry/api-metrics';
|
|
1
|
+
import { MetricOptions, ObservableResult } from '@opentelemetry/api-metrics';
|
|
2
2
|
export declare class MetricService {
|
|
3
3
|
getCounter(name: string, options?: MetricOptions): import("@opentelemetry/api-metrics").Counter;
|
|
4
4
|
getUpDownCounter(name: string, options?: MetricOptions): import("@opentelemetry/api-metrics").UpDownCounter;
|
|
5
5
|
getHistogram(name: string, options?: MetricOptions): import("@opentelemetry/api-metrics").Histogram;
|
|
6
|
-
getObservableCounter(name: string, options?: MetricOptions): import("@opentelemetry/api-metrics").ObservableBase;
|
|
7
|
-
getObservableGauge(name: string, options?: MetricOptions): import("@opentelemetry/api-metrics").ObservableBase;
|
|
8
|
-
getObservableUpDownCounter(name: string, options?: MetricOptions): import("@opentelemetry/api-metrics").ObservableBase;
|
|
6
|
+
getObservableCounter(name: string, options?: MetricOptions, callback?: (observableResult: ObservableResult) => void): import("@opentelemetry/api-metrics").ObservableBase;
|
|
7
|
+
getObservableGauge(name: string, options?: MetricOptions, callback?: (observableResult: ObservableResult) => void): import("@opentelemetry/api-metrics").ObservableBase;
|
|
8
|
+
getObservableUpDownCounter(name: string, options?: MetricOptions, callback?: (observableResult: ObservableResult) => void): import("@opentelemetry/api-metrics").ObservableBase;
|
|
9
9
|
}
|
|
@@ -19,14 +19,14 @@ let MetricService = class MetricService {
|
|
|
19
19
|
getHistogram(name, options) {
|
|
20
20
|
return (0, metric_data_1.getOrCreateHistogram)(name, options);
|
|
21
21
|
}
|
|
22
|
-
getObservableCounter(name, options) {
|
|
23
|
-
return (0, metric_data_1.getOrCreateObservableCounter)(name, options);
|
|
22
|
+
getObservableCounter(name, options, callback) {
|
|
23
|
+
return (0, metric_data_1.getOrCreateObservableCounter)(name, options, callback);
|
|
24
24
|
}
|
|
25
|
-
getObservableGauge(name, options) {
|
|
26
|
-
return (0, metric_data_1.getOrCreateObservableGauge)(name, options);
|
|
25
|
+
getObservableGauge(name, options, callback) {
|
|
26
|
+
return (0, metric_data_1.getOrCreateObservableGauge)(name, options, callback);
|
|
27
27
|
}
|
|
28
|
-
getObservableUpDownCounter(name, options) {
|
|
29
|
-
return (0, metric_data_1.getOrCreateObservableUpDownCounter)(name, options);
|
|
28
|
+
getObservableUpDownCounter(name, options, callback) {
|
|
29
|
+
return (0, metric_data_1.getOrCreateObservableUpDownCounter)(name, options, callback);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
MetricService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metric.service.js","sourceRoot":"","sources":["../../src/metrics/metric.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAI5C,+CAIuB;AAGvB,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,UAAU,CAAC,IAAY,EAAE,OAAuB;QAC9C,OAAO,IAAA,gCAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,gBAAgB,CAAC,IAAY,EAAE,OAAuB;QACpD,OAAO,IAAA,sCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,YAAY,CAAC,IAAY,EAAE,OAAuB;QAChD,OAAO,IAAA,kCAAoB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,oBAAoB,
|
|
1
|
+
{"version":3,"file":"metric.service.js","sourceRoot":"","sources":["../../src/metrics/metric.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAI5C,+CAIuB;AAGvB,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,UAAU,CAAC,IAAY,EAAE,OAAuB;QAC9C,OAAO,IAAA,gCAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,gBAAgB,CAAC,IAAY,EAAE,OAAuB;QACpD,OAAO,IAAA,sCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,YAAY,CAAC,IAAY,EAAE,OAAuB;QAChD,OAAO,IAAA,kCAAoB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,oBAAoB,CAClB,IAAY,EACZ,OAAuB,EACvB,QAAuD;QAEvD,OAAO,IAAA,0CAA4B,EAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;IAED,kBAAkB,CAChB,IAAY,EACZ,OAAuB,EACvB,QAAuD;QAEvD,OAAO,IAAA,wCAA0B,EAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7D,CAAC;IAED,0BAA0B,CACxB,IAAY,EACZ,OAAuB,EACvB,QAAuD;QAEvD,OAAO,IAAA,gDAAkC,EAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;CACF,CAAA;AApCY,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAoCzB;AApCY,sCAAa"}
|
|
@@ -2,22 +2,38 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Span = void 0;
|
|
4
4
|
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const recordException = (span, error) => {
|
|
6
|
+
span.recordException(error);
|
|
7
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
|
|
8
|
+
};
|
|
5
9
|
function Span(name) {
|
|
6
10
|
return (target, propertyKey, propertyDescriptor) => {
|
|
7
11
|
const method = propertyDescriptor.value;
|
|
8
12
|
propertyDescriptor.value = function PropertyDescriptor(...args) {
|
|
9
|
-
const currentSpan = api_1.trace.getSpan(api_1.context.active());
|
|
10
13
|
const tracer = api_1.trace.getTracer('default');
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
const spanName = name || `${target.constructor.name}.${propertyKey}`;
|
|
15
|
+
return tracer.startActiveSpan(spanName, span => {
|
|
13
16
|
if (method.constructor.name === 'AsyncFunction') {
|
|
14
|
-
return method
|
|
17
|
+
return method
|
|
18
|
+
.apply(this, args)
|
|
19
|
+
.catch(error => {
|
|
20
|
+
recordException(span, error);
|
|
21
|
+
throw error;
|
|
22
|
+
})
|
|
23
|
+
.finally(() => {
|
|
15
24
|
span.end();
|
|
16
25
|
});
|
|
17
26
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
try {
|
|
28
|
+
return method.apply(this, args);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
recordException(span, error);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
span.end();
|
|
36
|
+
}
|
|
21
37
|
});
|
|
22
38
|
};
|
|
23
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"span.js","sourceRoot":"","sources":["../../../src/tracing/decorators/span.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"span.js","sourceRoot":"","sources":["../../../src/tracing/decorators/span.ts"],"names":[],"mappings":";;;AAAA,4CAA4E;AAE5E,MAAM,eAAe,GAAG,CAAC,IAAa,EAAE,KAAU,EAAE,EAAE;IACpD,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,oBAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AACzE,CAAC,CAAC;AAEF,SAAgB,IAAI,CAAC,IAAa;IAChC,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,kBAAsC,EAAE,EAAE;QAClF,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC;QAExC,kBAAkB,CAAC,KAAK,GAAG,SAAS,kBAAkB,CAAC,GAAG,IAAW;YACnE,MAAM,MAAM,GAAG,WAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YAC1C,MAAM,QAAQ,GAAG,IAAI,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,WAAW,EAAE,CAAC;YAErE,OAAO,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE;gBAC7C,IAAI,MAAM,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,EAAE;oBAC/C,OAAO,MAAM;yBACV,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;yBACjB,KAAK,CAAC,KAAK,CAAC,EAAE;wBACb,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;wBAE7B,MAAM,KAAK,CAAC;oBACd,CAAC,CAAC;yBACD,OAAO,CAAC,GAAG,EAAE;wBACZ,IAAI,CAAC,GAAG,EAAE,CAAC;oBACb,CAAC,CAAC,CAAC;iBACN;gBAED,IAAI;oBACF,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;iBACjC;gBAAC,OAAO,KAAK,EAAE;oBACd,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;oBAE7B,MAAM,KAAK,CAAC;iBACb;wBAAS;oBACR,IAAI,CAAC,GAAG,EAAE,CAAC;iBACZ;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAlCD,oBAkCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const api_1 = require("@opentelemetry/api");
|
|
13
|
+
const sdk_node_1 = require("@opentelemetry/sdk-node");
|
|
14
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
15
|
+
const span_1 = require("./span");
|
|
16
|
+
class TestSpan {
|
|
17
|
+
singleSpan() { }
|
|
18
|
+
doubleSpan() {
|
|
19
|
+
return this.singleSpan();
|
|
20
|
+
}
|
|
21
|
+
error() {
|
|
22
|
+
throw new Error('hello world');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, span_1.Span)(),
|
|
27
|
+
__metadata("design:type", Function),
|
|
28
|
+
__metadata("design:paramtypes", []),
|
|
29
|
+
__metadata("design:returntype", void 0)
|
|
30
|
+
], TestSpan.prototype, "singleSpan", null);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, span_1.Span)(),
|
|
33
|
+
__metadata("design:type", Function),
|
|
34
|
+
__metadata("design:paramtypes", []),
|
|
35
|
+
__metadata("design:returntype", void 0)
|
|
36
|
+
], TestSpan.prototype, "doubleSpan", null);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, span_1.Span)(),
|
|
39
|
+
__metadata("design:type", Function),
|
|
40
|
+
__metadata("design:paramtypes", []),
|
|
41
|
+
__metadata("design:returntype", void 0)
|
|
42
|
+
], TestSpan.prototype, "error", null);
|
|
43
|
+
describe('Span', () => {
|
|
44
|
+
let instance;
|
|
45
|
+
let traceExporter;
|
|
46
|
+
let spanProcessor;
|
|
47
|
+
let provider;
|
|
48
|
+
beforeAll(async () => {
|
|
49
|
+
instance = new TestSpan();
|
|
50
|
+
traceExporter = new sdk_node_1.tracing.InMemorySpanExporter();
|
|
51
|
+
spanProcessor = new sdk_node_1.tracing.SimpleSpanProcessor(traceExporter);
|
|
52
|
+
provider = new sdk_trace_node_1.NodeTracerProvider();
|
|
53
|
+
provider.addSpanProcessor(spanProcessor);
|
|
54
|
+
provider.register();
|
|
55
|
+
});
|
|
56
|
+
afterEach(async () => {
|
|
57
|
+
spanProcessor.forceFlush();
|
|
58
|
+
traceExporter.reset();
|
|
59
|
+
});
|
|
60
|
+
afterAll(async () => {
|
|
61
|
+
await provider.shutdown();
|
|
62
|
+
});
|
|
63
|
+
it('should set correct span', async () => {
|
|
64
|
+
instance.singleSpan();
|
|
65
|
+
const spans = traceExporter.getFinishedSpans();
|
|
66
|
+
expect(spans).toHaveLength(1);
|
|
67
|
+
expect(spans.map(span => span.name)).toEqual(['TestSpan.singleSpan']);
|
|
68
|
+
});
|
|
69
|
+
it('should set correct span even when calling other method with Span decorator', async () => {
|
|
70
|
+
instance.doubleSpan();
|
|
71
|
+
const spans = traceExporter.getFinishedSpans();
|
|
72
|
+
expect(spans).toHaveLength(2);
|
|
73
|
+
expect(spans.map(span => span.name)).toEqual(['TestSpan.singleSpan', 'TestSpan.doubleSpan']);
|
|
74
|
+
});
|
|
75
|
+
it('should propagate errors', () => {
|
|
76
|
+
expect(instance.error).toThrowError('hello world');
|
|
77
|
+
});
|
|
78
|
+
it('should set setStatus to ERROR and message to error message', async () => {
|
|
79
|
+
expect(instance.error).toThrowError('hello world');
|
|
80
|
+
const spans = traceExporter.getFinishedSpans();
|
|
81
|
+
expect(spans).toHaveLength(1);
|
|
82
|
+
expect(spans[0].status).toEqual({ code: api_1.SpanStatusCode.ERROR, message: 'hello world' });
|
|
83
|
+
});
|
|
84
|
+
it('should set recordException with error', () => {
|
|
85
|
+
expect(instance.error).toThrowError('hello world');
|
|
86
|
+
const spans = traceExporter.getFinishedSpans();
|
|
87
|
+
expect(spans).toHaveLength(1);
|
|
88
|
+
expect(spans[0].events).toHaveLength(1);
|
|
89
|
+
expect(spans[0].events[0]).toEqual({
|
|
90
|
+
name: 'exception',
|
|
91
|
+
attributes: expect.anything(),
|
|
92
|
+
time: expect.anything(),
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=span.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span.spec.js","sourceRoot":"","sources":["../../../src/tracing/decorators/span.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAAoD;AACpD,sDAAkD;AAClD,kEAAmE;AACnE,iCAA8B;AAE9B,MAAM,QAAQ;IAEZ,UAAU,KAAI,CAAC;IAGf,UAAU;QACR,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;IAGD,KAAK;QACH,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;CACF;AAXC;IADC,IAAA,WAAI,GAAE;;;;0CACQ;AAGf;IADC,IAAA,WAAI,GAAE;;;;0CAGN;AAGD;IADC,IAAA,WAAI,GAAE;;;;qCAGN;AAGH,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,IAAI,QAAkB,CAAC;IACvB,IAAI,aAA2C,CAAC;IAChD,IAAI,aAA0C,CAAC;IAC/C,IAAI,QAA4B,CAAC;IAEjC,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC1B,aAAa,GAAG,IAAI,kBAAO,CAAC,oBAAoB,EAAE,CAAC;QACnD,aAAa,GAAG,IAAI,kBAAO,CAAC,mBAAmB,CAAC,aAAa,CAAC,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