@moostjs/otel 0.4.6 → 0.4.8
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 +1110 -39
- package/dist/index.d.ts +192 -2
- package/dist/index.mjs +1107 -43
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import * as _opentelemetry_api from '@opentelemetry/api';
|
|
2
2
|
import { Span, SpanOptions } from '@opentelemetry/api';
|
|
3
|
+
import * as _prostojs_mate from '@prostojs/mate';
|
|
4
|
+
import { TMateParamMeta } from '@prostojs/mate';
|
|
5
|
+
import { TProvideRegistry, TReplaceRegistry } from '@prostojs/infact';
|
|
6
|
+
import { BatchSpanProcessor, ReadableSpan, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
7
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
8
|
+
import { ContextInjector, TContextInjectorHook } from 'moost';
|
|
3
9
|
|
|
4
10
|
interface TOtelContext {
|
|
5
11
|
otel?: {
|
|
6
12
|
span?: Span;
|
|
13
|
+
route?: string;
|
|
7
14
|
};
|
|
8
15
|
}
|
|
9
16
|
declare function useOtelContext(): {
|
|
10
17
|
trace: _opentelemetry_api.TraceAPI;
|
|
11
|
-
withChildSpan: <T>(name: string, cb: (...a: any[]) => T, opts?: SpanOptions) =>
|
|
18
|
+
withChildSpan: <T>(name: string, cb: (...a: any[]) => T, opts?: SpanOptions) => () => T;
|
|
12
19
|
getSpan: () => Span | undefined;
|
|
13
20
|
getSpanContext: () => _opentelemetry_api.SpanContext | undefined;
|
|
14
21
|
getPropagationHeaders: () => {
|
|
@@ -19,6 +26,7 @@ declare function useOtelContext(): {
|
|
|
19
26
|
tracestate?: undefined;
|
|
20
27
|
};
|
|
21
28
|
registerSpan: (span: Span) => unknown;
|
|
29
|
+
pushSpan: (span: Span) => void;
|
|
22
30
|
};
|
|
23
31
|
declare function useTrace(): _opentelemetry_api.TraceAPI;
|
|
24
32
|
declare function useSpan(): Span | undefined;
|
|
@@ -39,4 +47,186 @@ declare function useOtelPropagation(): {
|
|
|
39
47
|
|
|
40
48
|
declare function enableOtelForMoost(): void;
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Annotate controller and/or handler to filter
|
|
52
|
+
* out the corresponding spans from transporting
|
|
53
|
+
*
|
|
54
|
+
* Requires use of MoostBatchSpanProcessor or MoostSimpleSpanProcessor
|
|
55
|
+
*/
|
|
56
|
+
declare const OtelIgnoreSpan: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
57
|
+
/**
|
|
58
|
+
* Annotate controller and/or handler to suppress metrics
|
|
59
|
+
*/
|
|
60
|
+
declare const OtelIgnoreMeter: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
61
|
+
|
|
62
|
+
type TAny = any;
|
|
63
|
+
type TAnyFn = (...a: TAny[]) => unknown;
|
|
64
|
+
type TObject = object;
|
|
65
|
+
type TFunction = Function;
|
|
66
|
+
type TClassConstructor<T = unknown> = new (...args: TAny[]) => T;
|
|
67
|
+
interface TEmpty {
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface TClassFunction<T extends TAnyFn = TAnyFn> {
|
|
71
|
+
handler: T;
|
|
72
|
+
}
|
|
73
|
+
type TClassFunctionConstructor<T extends TAnyFn = TAnyFn> = new (...a: TAny[]) => TClassFunction<T>;
|
|
74
|
+
type TCallableClassFunction<T extends TAnyFn = TAnyFn> = T | TClassFunctionConstructor;
|
|
75
|
+
|
|
76
|
+
type TInterceptorBefore = (reply: (response: TAny) => void) => void | Promise<void>;
|
|
77
|
+
type TInterceptorAfter = (response: TAny, reply: (response: TAny) => void) => void | Promise<void>;
|
|
78
|
+
type TInterceptorOnError = (error: Error, reply: (response: TAny) => void) => void | Promise<void>;
|
|
79
|
+
interface TInterceptorFn {
|
|
80
|
+
(before: (fn: TInterceptorBefore) => void, after: (fn: TInterceptorAfter) => void, onError: (fn: TInterceptorOnError) => void): unknown | Promise<unknown>;
|
|
81
|
+
priority?: TInterceptorPriority;
|
|
82
|
+
}
|
|
83
|
+
declare enum TInterceptorPriority {
|
|
84
|
+
BEFORE_ALL = 0,
|
|
85
|
+
BEFORE_GUARD = 1,
|
|
86
|
+
GUARD = 2,
|
|
87
|
+
AFTER_GUARD = 3,
|
|
88
|
+
INTERCEPTOR = 4,
|
|
89
|
+
CATCH_ERROR = 5,
|
|
90
|
+
AFTER_ALL = 6
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type TDecoratorLevel = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
|
|
94
|
+
|
|
95
|
+
interface TPipeMetas<T extends TObject = TEmpty> {
|
|
96
|
+
classMeta?: TMoostMetadata & T;
|
|
97
|
+
methodMeta?: TMoostMetadata & T;
|
|
98
|
+
propMeta?: TMoostMetadata & T;
|
|
99
|
+
paramMeta?: TMoostParamsMetadata & T;
|
|
100
|
+
targetMeta?: TMoostParamsMetadata & T;
|
|
101
|
+
instance?: TObject;
|
|
102
|
+
type: TFunction;
|
|
103
|
+
index?: number;
|
|
104
|
+
key: string | symbol;
|
|
105
|
+
}
|
|
106
|
+
interface TPipeFn<T extends TObject = TEmpty> {
|
|
107
|
+
(value: unknown, metas: TPipeMetas<T>, level: TDecoratorLevel): unknown | Promise<unknown>;
|
|
108
|
+
priority?: TPipePriority;
|
|
109
|
+
}
|
|
110
|
+
declare enum TPipePriority {
|
|
111
|
+
BEFORE_RESOLVE = 0,
|
|
112
|
+
RESOLVE = 1,
|
|
113
|
+
AFTER_RESOLVE = 2,
|
|
114
|
+
BEFORE_TRANSFORM = 3,
|
|
115
|
+
TRANSFORM = 4,
|
|
116
|
+
AFTER_TRANSFORM = 5,
|
|
117
|
+
BEFORE_VALIDATE = 6,
|
|
118
|
+
VALIDATE = 7,
|
|
119
|
+
AFTER_VALIDATE = 8
|
|
120
|
+
}
|
|
121
|
+
interface TPipeData {
|
|
122
|
+
handler: TPipeFn;
|
|
123
|
+
priority: TPipePriority;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface TMoostMetadata<H extends TObject = TEmpty> extends TCommonMetaFields, TCommonMoostMeta {
|
|
127
|
+
requiredProps?: Array<string | symbol>;
|
|
128
|
+
controller?: {
|
|
129
|
+
prefix?: string;
|
|
130
|
+
};
|
|
131
|
+
importController?: Array<{
|
|
132
|
+
prefix?: string;
|
|
133
|
+
typeResolver?: TClassConstructor | (() => TClassConstructor | TObject | Promise<TClassConstructor | TObject>);
|
|
134
|
+
provide?: TProvideRegistry;
|
|
135
|
+
}>;
|
|
136
|
+
properties?: Array<string | symbol>;
|
|
137
|
+
injectable?: true | TInjectableScope;
|
|
138
|
+
interceptors?: TInterceptorData[];
|
|
139
|
+
handlers?: Array<TMoostHandler<H>>;
|
|
140
|
+
returnType?: TFunction;
|
|
141
|
+
provide?: TProvideRegistry;
|
|
142
|
+
replace?: TReplaceRegistry;
|
|
143
|
+
params: Array<TMateParamMeta & TMoostParamsMetadata>;
|
|
144
|
+
}
|
|
145
|
+
interface TMoostParamsMetadata extends TCommonMetaFields, TCommonMoostMeta {
|
|
146
|
+
circular?: () => TAny;
|
|
147
|
+
inject?: string | symbol | TClassConstructor;
|
|
148
|
+
nullable?: boolean;
|
|
149
|
+
paramSource?: string;
|
|
150
|
+
paramName?: string;
|
|
151
|
+
}
|
|
152
|
+
type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
|
|
153
|
+
type TMoostHandler<T> = {
|
|
154
|
+
type: string;
|
|
155
|
+
path?: string;
|
|
156
|
+
} & T;
|
|
157
|
+
interface TInterceptorData {
|
|
158
|
+
handler: TCallableClassFunction<TInterceptorFn>;
|
|
159
|
+
priority: TInterceptorPriority;
|
|
160
|
+
}
|
|
161
|
+
interface TCommonMetaFields {
|
|
162
|
+
id?: string;
|
|
163
|
+
label?: string;
|
|
164
|
+
value?: unknown;
|
|
165
|
+
description?: string;
|
|
166
|
+
optional?: boolean;
|
|
167
|
+
required?: boolean;
|
|
168
|
+
}
|
|
169
|
+
interface TCommonMoostMeta {
|
|
170
|
+
inherit?: boolean;
|
|
171
|
+
pipes?: TPipeData[];
|
|
172
|
+
resolver?: (metas: TPipeMetas<TAny>, level: TDecoratorLevel) => unknown;
|
|
173
|
+
type?: TFunction;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
interface TOtelMate {
|
|
177
|
+
otelIgnoreSpan: boolean;
|
|
178
|
+
otelIgnoreMeter: boolean;
|
|
179
|
+
}
|
|
180
|
+
declare function getOtelMate(): _prostojs_mate.Mate<TMoostMetadata<TEmpty> & TOtelMate & {
|
|
181
|
+
params: (TOtelMate & _prostojs_mate.TMateParamMeta)[];
|
|
182
|
+
}, TMoostMetadata<TEmpty> & TOtelMate & {
|
|
183
|
+
params: (TOtelMate & _prostojs_mate.TMateParamMeta)[];
|
|
184
|
+
}>;
|
|
185
|
+
|
|
186
|
+
declare class MoostBatchSpanProcessor extends BatchSpanProcessor {
|
|
187
|
+
onEnd(span: ReadableSpan): void;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
declare class MoostSimpleSpanProcessor extends SimpleSpanProcessor {
|
|
191
|
+
onEnd(span: ReadableSpan): void;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare function shouldSpanBeIgnored(span: ReadableSpan): boolean;
|
|
195
|
+
|
|
196
|
+
type TAttributes = Record<string, string | number | boolean>;
|
|
197
|
+
declare class SpanInjector extends ContextInjector<TContextInjectorHook> {
|
|
198
|
+
with<T>(name: TContextInjectorHook, attributes: TAttributes, cb: () => T): T;
|
|
199
|
+
with<T>(name: TContextInjectorHook, cb: () => T): T;
|
|
200
|
+
patchRsponse(): void;
|
|
201
|
+
startEvent<T>(name: string, eventType: string, cb: () => T): T;
|
|
202
|
+
getEventType(): string;
|
|
203
|
+
getIgnoreSpan(): boolean | undefined;
|
|
204
|
+
getControllerHandlerMeta(): {
|
|
205
|
+
ignoreMeter: boolean | undefined;
|
|
206
|
+
ignoreSpan: boolean | undefined;
|
|
207
|
+
attrs: {
|
|
208
|
+
'moost.controller': string;
|
|
209
|
+
'moost.handler': string | undefined;
|
|
210
|
+
'moost.handler_description': string | undefined;
|
|
211
|
+
'moost.handler_label': string | undefined;
|
|
212
|
+
'moost.handler_id': string | undefined;
|
|
213
|
+
'moost.ignore': boolean | undefined;
|
|
214
|
+
'moost.route': string | undefined;
|
|
215
|
+
'moost.event_type': string;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
hook(name: 'Handler:not_found' | 'Handler:routed' | 'C', route?: string): void;
|
|
219
|
+
withSpan<T>(span: Span, cb: () => T, opts: {
|
|
220
|
+
rootSpan: boolean;
|
|
221
|
+
endSpan: boolean;
|
|
222
|
+
}): T;
|
|
223
|
+
startEventMetrics(a: Record<string, string | number | boolean | undefined>, route?: string): void;
|
|
224
|
+
endEventMetrics(a: Record<string, string | number | boolean | undefined>, error?: Error): void;
|
|
225
|
+
getRequest(): IncomingMessage | undefined;
|
|
226
|
+
getResponse(): (ServerResponse<IncomingMessage> & {
|
|
227
|
+
_statusCode?: number | undefined;
|
|
228
|
+
_contentLength?: number | undefined;
|
|
229
|
+
}) | undefined;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { MoostBatchSpanProcessor, MoostSimpleSpanProcessor, OtelIgnoreMeter, OtelIgnoreSpan, SpanInjector, type TOtelContext, type TOtelMate, enableOtelForMoost, getOtelMate, shouldSpanBeIgnored, useOtelContext, useOtelPropagation, useSpan, useTrace };
|