@moostjs/otel 0.4.11 → 0.4.13
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/dist/index.cjs +60 -46
- package/dist/index.d.ts +16 -3
- package/dist/index.mjs +60 -46
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -78,41 +78,51 @@ function useOtelPropagation() {
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
81
|
+
let moostMetrics;
|
|
82
|
+
function getMoostMetrics() {
|
|
83
|
+
if (!moostMetrics) {
|
|
84
|
+
const meter = api.metrics.getMeter('moost-meter');
|
|
85
|
+
moostMetrics = {
|
|
86
|
+
httpRequestCount: meter.createCounter('http.server.requests', {
|
|
87
|
+
description: 'The number of HTTP requests received',
|
|
88
|
+
}),
|
|
89
|
+
httpResponseCount: meter.createCounter('http.server.responses', {
|
|
90
|
+
description: 'The number of HTTP responses sent',
|
|
91
|
+
}),
|
|
92
|
+
httpActiveRequests: meter.createUpDownCounter('http.server.active_requests', {
|
|
93
|
+
description: 'The number of active HTTP requests',
|
|
94
|
+
}),
|
|
95
|
+
httpRequestSize: meter.createHistogram('http.server.request.size', {
|
|
96
|
+
description: 'The size of HTTP request bodies',
|
|
97
|
+
unit: 'byte',
|
|
98
|
+
}),
|
|
99
|
+
httpResponseSize: meter.createHistogram('http.server.response.size', {
|
|
100
|
+
description: 'The size of HTTP response bodies',
|
|
101
|
+
unit: 'byte',
|
|
102
|
+
}),
|
|
103
|
+
httpErrorCount: meter.createCounter('http.server.errors', {
|
|
104
|
+
description: 'The number of HTTP requests that resulted in an error',
|
|
105
|
+
}),
|
|
106
|
+
moostEventCount: meter.createCounter('moost.events.count', {
|
|
107
|
+
description: 'The number of HTTP requests received',
|
|
108
|
+
}),
|
|
109
|
+
moostActiveEvents: meter.createUpDownCounter('moost.events.active', {
|
|
110
|
+
description: 'The number of active HTTP requests',
|
|
111
|
+
}),
|
|
112
|
+
moostErrorCount: meter.createCounter('moost.events.errors', {
|
|
113
|
+
description: 'The number of HTTP requests that resulted in an error',
|
|
114
|
+
}),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return moostMetrics;
|
|
118
|
+
}
|
|
113
119
|
|
|
114
120
|
const tracer = api.trace.getTracer('moost-tracer');
|
|
115
121
|
class SpanInjector extends moost.ContextInjector {
|
|
122
|
+
constructor() {
|
|
123
|
+
super(...arguments);
|
|
124
|
+
this.metrics = getMoostMetrics();
|
|
125
|
+
}
|
|
116
126
|
with(name, attributes, cb) {
|
|
117
127
|
const fn = typeof attributes === 'function' ? attributes : cb;
|
|
118
128
|
const attrs = typeof attributes === 'object' ? attributes : undefined;
|
|
@@ -200,12 +210,16 @@ class SpanInjector extends moost.ContextInjector {
|
|
|
200
210
|
},
|
|
201
211
|
};
|
|
202
212
|
}
|
|
203
|
-
hook(name, route) {
|
|
213
|
+
hook(method, name, route) {
|
|
214
|
+
if (method === 'WF_STEP') {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
204
217
|
if (name === 'Handler:not_found') {
|
|
205
218
|
const chm = this.getControllerHandlerMeta();
|
|
206
219
|
this.startEventMetrics(chm.attrs, route);
|
|
207
220
|
}
|
|
208
221
|
else if (name === 'Controller:registered') {
|
|
222
|
+
const _route = moost.useAsyncEventContext().store('otel').get('route');
|
|
209
223
|
const chm = this.getControllerHandlerMeta();
|
|
210
224
|
if (!chm.ignoreMeter) {
|
|
211
225
|
this.startEventMetrics(chm.attrs, route);
|
|
@@ -215,10 +229,10 @@ class SpanInjector extends moost.ContextInjector {
|
|
|
215
229
|
if (span) {
|
|
216
230
|
span.setAttributes(chm.attrs);
|
|
217
231
|
if (chm.attrs['moost.event_type'] === 'HTTP') {
|
|
218
|
-
span.updateName(`${this.getRequest()?.method || ''} ${
|
|
232
|
+
span.updateName(`${this.getRequest()?.method || ''} ${_route || '<unresolved>'}`);
|
|
219
233
|
}
|
|
220
234
|
else {
|
|
221
|
-
span.updateName(`${chm.attrs['moost.event_type']} ${
|
|
235
|
+
span.updateName(`${chm.attrs['moost.event_type']} ${_route || '<unresolved>'}`);
|
|
222
236
|
}
|
|
223
237
|
}
|
|
224
238
|
}
|
|
@@ -278,15 +292,15 @@ class SpanInjector extends moost.ContextInjector {
|
|
|
278
292
|
route,
|
|
279
293
|
url: req?.url,
|
|
280
294
|
};
|
|
281
|
-
|
|
282
|
-
|
|
295
|
+
this.metrics.httpRequestCount.add(1, attrs);
|
|
296
|
+
this.metrics.httpActiveRequests.add(1, attrs);
|
|
283
297
|
}
|
|
284
298
|
const attrs = {
|
|
285
299
|
...a,
|
|
286
300
|
route,
|
|
287
301
|
};
|
|
288
|
-
|
|
289
|
-
|
|
302
|
+
this.metrics.moostEventCount.add(1, attrs);
|
|
303
|
+
this.metrics.moostActiveEvents.add(1, attrs);
|
|
290
304
|
}
|
|
291
305
|
endEventMetrics(a, error) {
|
|
292
306
|
const route = moost.useAsyncEventContext().store('otel').get('route');
|
|
@@ -298,21 +312,21 @@ class SpanInjector extends moost.ContextInjector {
|
|
|
298
312
|
route,
|
|
299
313
|
url: req?.url,
|
|
300
314
|
};
|
|
301
|
-
|
|
315
|
+
this.metrics.httpActiveRequests.add(-1, attrs);
|
|
302
316
|
if (error) {
|
|
303
|
-
|
|
317
|
+
this.metrics.httpErrorCount.add(1, attrs);
|
|
304
318
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
319
|
+
this.metrics.httpRequestSize.record(req?.socket.bytesRead || 0, attrs);
|
|
320
|
+
this.metrics.httpResponseSize.record(res?._contentLength || 0, attrs);
|
|
321
|
+
this.metrics.httpResponseCount.add(1, { ...attrs, status: res?._statusCode });
|
|
308
322
|
}
|
|
309
323
|
const attrs = {
|
|
310
324
|
...a,
|
|
311
325
|
route,
|
|
312
326
|
};
|
|
313
|
-
|
|
327
|
+
this.metrics.moostActiveEvents.add(-1, attrs);
|
|
314
328
|
if (error) {
|
|
315
|
-
|
|
329
|
+
this.metrics.moostErrorCount.add(1, attrs);
|
|
316
330
|
}
|
|
317
331
|
}
|
|
318
332
|
getRequest() {
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ type TInterceptorOnError = (error: Error, reply: (response: TAny) => void) => vo
|
|
|
79
79
|
interface TInterceptorFn {
|
|
80
80
|
(before: (fn: TInterceptorBefore) => void, after: (fn: TInterceptorAfter) => void, onError: (fn: TInterceptorOnError) => void): unknown | Promise<unknown>;
|
|
81
81
|
priority?: TInterceptorPriority;
|
|
82
|
+
_name?: string;
|
|
82
83
|
}
|
|
83
84
|
declare enum TInterceptorPriority {
|
|
84
85
|
BEFORE_ALL = 0,
|
|
@@ -157,6 +158,7 @@ type TMoostHandler<T> = {
|
|
|
157
158
|
interface TInterceptorData {
|
|
158
159
|
handler: TCallableClassFunction<TInterceptorFn>;
|
|
159
160
|
priority: TInterceptorPriority;
|
|
161
|
+
name: string;
|
|
160
162
|
}
|
|
161
163
|
interface TCommonMetaFields {
|
|
162
164
|
id?: string;
|
|
@@ -195,10 +197,21 @@ declare function shouldSpanBeIgnored(span: ReadableSpan): boolean;
|
|
|
195
197
|
|
|
196
198
|
type TAttributes = Record<string, string | number | boolean>;
|
|
197
199
|
declare class SpanInjector extends ContextInjector<TContextInjectorHook> {
|
|
200
|
+
metrics: {
|
|
201
|
+
httpRequestCount: _opentelemetry_api.Counter<_opentelemetry_api.Attributes>;
|
|
202
|
+
httpResponseCount: _opentelemetry_api.Counter<_opentelemetry_api.Attributes>;
|
|
203
|
+
httpActiveRequests: _opentelemetry_api.Counter<_opentelemetry_api.Attributes>;
|
|
204
|
+
httpRequestSize: _opentelemetry_api.Histogram<_opentelemetry_api.Attributes>;
|
|
205
|
+
httpResponseSize: _opentelemetry_api.Histogram<_opentelemetry_api.Attributes>;
|
|
206
|
+
httpErrorCount: _opentelemetry_api.Counter<_opentelemetry_api.Attributes>;
|
|
207
|
+
moostEventCount: _opentelemetry_api.Counter<_opentelemetry_api.Attributes>;
|
|
208
|
+
moostActiveEvents: _opentelemetry_api.Counter<_opentelemetry_api.Attributes>;
|
|
209
|
+
moostErrorCount: _opentelemetry_api.Counter<_opentelemetry_api.Attributes>;
|
|
210
|
+
};
|
|
198
211
|
with<T>(name: TContextInjectorHook, attributes: TAttributes, cb: () => T): T;
|
|
199
212
|
with<T>(name: TContextInjectorHook, cb: () => T): T;
|
|
200
|
-
patchRsponse(): void;
|
|
201
|
-
startEvent<T>(eventType: string, cb: () => T): T;
|
|
213
|
+
protected patchRsponse(): void;
|
|
214
|
+
protected startEvent<T>(eventType: string, cb: () => T): T;
|
|
202
215
|
getEventType(): string;
|
|
203
216
|
getIgnoreSpan(): boolean | undefined;
|
|
204
217
|
getControllerHandlerMeta(): {
|
|
@@ -215,7 +228,7 @@ declare class SpanInjector extends ContextInjector<TContextInjectorHook> {
|
|
|
215
228
|
'moost.event_type': string;
|
|
216
229
|
};
|
|
217
230
|
};
|
|
218
|
-
hook(name: 'Handler:not_found' | 'Handler:routed' | 'Controller:registered', route?: string): void;
|
|
231
|
+
hook(method: string, name: 'Handler:not_found' | 'Handler:routed' | 'Controller:registered', route?: string): void;
|
|
219
232
|
withSpan<T>(span: Span, cb: () => T, opts: {
|
|
220
233
|
rootSpan: boolean;
|
|
221
234
|
endSpan: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -76,41 +76,51 @@ function useOtelPropagation() {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
79
|
+
let moostMetrics;
|
|
80
|
+
function getMoostMetrics() {
|
|
81
|
+
if (!moostMetrics) {
|
|
82
|
+
const meter = metrics.getMeter('moost-meter');
|
|
83
|
+
moostMetrics = {
|
|
84
|
+
httpRequestCount: meter.createCounter('http.server.requests', {
|
|
85
|
+
description: 'The number of HTTP requests received',
|
|
86
|
+
}),
|
|
87
|
+
httpResponseCount: meter.createCounter('http.server.responses', {
|
|
88
|
+
description: 'The number of HTTP responses sent',
|
|
89
|
+
}),
|
|
90
|
+
httpActiveRequests: meter.createUpDownCounter('http.server.active_requests', {
|
|
91
|
+
description: 'The number of active HTTP requests',
|
|
92
|
+
}),
|
|
93
|
+
httpRequestSize: meter.createHistogram('http.server.request.size', {
|
|
94
|
+
description: 'The size of HTTP request bodies',
|
|
95
|
+
unit: 'byte',
|
|
96
|
+
}),
|
|
97
|
+
httpResponseSize: meter.createHistogram('http.server.response.size', {
|
|
98
|
+
description: 'The size of HTTP response bodies',
|
|
99
|
+
unit: 'byte',
|
|
100
|
+
}),
|
|
101
|
+
httpErrorCount: meter.createCounter('http.server.errors', {
|
|
102
|
+
description: 'The number of HTTP requests that resulted in an error',
|
|
103
|
+
}),
|
|
104
|
+
moostEventCount: meter.createCounter('moost.events.count', {
|
|
105
|
+
description: 'The number of HTTP requests received',
|
|
106
|
+
}),
|
|
107
|
+
moostActiveEvents: meter.createUpDownCounter('moost.events.active', {
|
|
108
|
+
description: 'The number of active HTTP requests',
|
|
109
|
+
}),
|
|
110
|
+
moostErrorCount: meter.createCounter('moost.events.errors', {
|
|
111
|
+
description: 'The number of HTTP requests that resulted in an error',
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return moostMetrics;
|
|
116
|
+
}
|
|
111
117
|
|
|
112
118
|
const tracer = trace.getTracer('moost-tracer');
|
|
113
119
|
class SpanInjector extends ContextInjector {
|
|
120
|
+
constructor() {
|
|
121
|
+
super(...arguments);
|
|
122
|
+
this.metrics = getMoostMetrics();
|
|
123
|
+
}
|
|
114
124
|
with(name, attributes, cb) {
|
|
115
125
|
const fn = typeof attributes === 'function' ? attributes : cb;
|
|
116
126
|
const attrs = typeof attributes === 'object' ? attributes : undefined;
|
|
@@ -198,12 +208,16 @@ class SpanInjector extends ContextInjector {
|
|
|
198
208
|
},
|
|
199
209
|
};
|
|
200
210
|
}
|
|
201
|
-
hook(name, route) {
|
|
211
|
+
hook(method, name, route) {
|
|
212
|
+
if (method === 'WF_STEP') {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
202
215
|
if (name === 'Handler:not_found') {
|
|
203
216
|
const chm = this.getControllerHandlerMeta();
|
|
204
217
|
this.startEventMetrics(chm.attrs, route);
|
|
205
218
|
}
|
|
206
219
|
else if (name === 'Controller:registered') {
|
|
220
|
+
const _route = useAsyncEventContext$1().store('otel').get('route');
|
|
207
221
|
const chm = this.getControllerHandlerMeta();
|
|
208
222
|
if (!chm.ignoreMeter) {
|
|
209
223
|
this.startEventMetrics(chm.attrs, route);
|
|
@@ -213,10 +227,10 @@ class SpanInjector extends ContextInjector {
|
|
|
213
227
|
if (span) {
|
|
214
228
|
span.setAttributes(chm.attrs);
|
|
215
229
|
if (chm.attrs['moost.event_type'] === 'HTTP') {
|
|
216
|
-
span.updateName(`${this.getRequest()?.method || ''} ${
|
|
230
|
+
span.updateName(`${this.getRequest()?.method || ''} ${_route || '<unresolved>'}`);
|
|
217
231
|
}
|
|
218
232
|
else {
|
|
219
|
-
span.updateName(`${chm.attrs['moost.event_type']} ${
|
|
233
|
+
span.updateName(`${chm.attrs['moost.event_type']} ${_route || '<unresolved>'}`);
|
|
220
234
|
}
|
|
221
235
|
}
|
|
222
236
|
}
|
|
@@ -276,15 +290,15 @@ class SpanInjector extends ContextInjector {
|
|
|
276
290
|
route,
|
|
277
291
|
url: req?.url,
|
|
278
292
|
};
|
|
279
|
-
|
|
280
|
-
|
|
293
|
+
this.metrics.httpRequestCount.add(1, attrs);
|
|
294
|
+
this.metrics.httpActiveRequests.add(1, attrs);
|
|
281
295
|
}
|
|
282
296
|
const attrs = {
|
|
283
297
|
...a,
|
|
284
298
|
route,
|
|
285
299
|
};
|
|
286
|
-
|
|
287
|
-
|
|
300
|
+
this.metrics.moostEventCount.add(1, attrs);
|
|
301
|
+
this.metrics.moostActiveEvents.add(1, attrs);
|
|
288
302
|
}
|
|
289
303
|
endEventMetrics(a, error) {
|
|
290
304
|
const route = useAsyncEventContext$1().store('otel').get('route');
|
|
@@ -296,21 +310,21 @@ class SpanInjector extends ContextInjector {
|
|
|
296
310
|
route,
|
|
297
311
|
url: req?.url,
|
|
298
312
|
};
|
|
299
|
-
|
|
313
|
+
this.metrics.httpActiveRequests.add(-1, attrs);
|
|
300
314
|
if (error) {
|
|
301
|
-
|
|
315
|
+
this.metrics.httpErrorCount.add(1, attrs);
|
|
302
316
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
317
|
+
this.metrics.httpRequestSize.record(req?.socket.bytesRead || 0, attrs);
|
|
318
|
+
this.metrics.httpResponseSize.record(res?._contentLength || 0, attrs);
|
|
319
|
+
this.metrics.httpResponseCount.add(1, { ...attrs, status: res?._statusCode });
|
|
306
320
|
}
|
|
307
321
|
const attrs = {
|
|
308
322
|
...a,
|
|
309
323
|
route,
|
|
310
324
|
};
|
|
311
|
-
|
|
325
|
+
this.metrics.moostActiveEvents.add(-1, attrs);
|
|
312
326
|
if (error) {
|
|
313
|
-
|
|
327
|
+
this.metrics.moostErrorCount.add(1, attrs);
|
|
314
328
|
}
|
|
315
329
|
}
|
|
316
330
|
getRequest() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/otel",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "@moostjs/otel",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@opentelemetry/api": "^1.9.0",
|
|
41
41
|
"@opentelemetry/sdk-trace-base": "^1.25.1",
|
|
42
|
-
"moost": "0.4.
|
|
42
|
+
"moost": "0.4.13"
|
|
43
43
|
}
|
|
44
44
|
}
|