@moostjs/otel 0.4.5 → 0.4.7

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.d.ts CHANGED
@@ -1,5 +1,9 @@
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';
3
7
 
4
8
  interface TOtelContext {
5
9
  otel?: {
@@ -39,4 +43,145 @@ declare function useOtelPropagation(): {
39
43
 
40
44
  declare function enableOtelForMoost(): void;
41
45
 
42
- export { type TOtelContext, enableOtelForMoost, useOtelContext, useOtelPropagation, useSpan, useTrace };
46
+ /**
47
+ * Annotate controller and/or handler to filter
48
+ * out the corresponding spans from transporting
49
+ *
50
+ * Requires use of MoostBatchSpanProcessor or MoostSimpleSpanProcessor
51
+ */
52
+ declare const OtelIgnoreSpan: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
53
+
54
+ type TAny = any;
55
+ type TAnyFn = (...a: TAny[]) => unknown;
56
+ type TObject = object;
57
+ type TFunction = Function;
58
+ type TClassConstructor<T = unknown> = new (...args: TAny[]) => T;
59
+ interface TEmpty {
60
+ }
61
+
62
+ interface TClassFunction<T extends TAnyFn = TAnyFn> {
63
+ handler: T;
64
+ }
65
+ type TClassFunctionConstructor<T extends TAnyFn = TAnyFn> = new (...a: TAny[]) => TClassFunction<T>;
66
+ type TCallableClassFunction<T extends TAnyFn = TAnyFn> = T | TClassFunctionConstructor;
67
+
68
+ type TInterceptorBefore = (reply: (response: TAny) => void) => void | Promise<void>;
69
+ type TInterceptorAfter = (response: TAny, reply: (response: TAny) => void) => void | Promise<void>;
70
+ type TInterceptorOnError = (error: Error, reply: (response: TAny) => void) => void | Promise<void>;
71
+ interface TInterceptorFn {
72
+ (before: (fn: TInterceptorBefore) => void, after: (fn: TInterceptorAfter) => void, onError: (fn: TInterceptorOnError) => void): unknown | Promise<unknown>;
73
+ priority?: TInterceptorPriority;
74
+ }
75
+ declare enum TInterceptorPriority {
76
+ BEFORE_ALL = 0,
77
+ BEFORE_GUARD = 1,
78
+ GUARD = 2,
79
+ AFTER_GUARD = 3,
80
+ INTERCEPTOR = 4,
81
+ CATCH_ERROR = 5,
82
+ AFTER_ALL = 6
83
+ }
84
+
85
+ type TDecoratorLevel = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
86
+
87
+ interface TPipeMetas<T extends TObject = TEmpty> {
88
+ classMeta?: TMoostMetadata & T;
89
+ methodMeta?: TMoostMetadata & T;
90
+ propMeta?: TMoostMetadata & T;
91
+ paramMeta?: TMoostParamsMetadata & T;
92
+ targetMeta?: TMoostParamsMetadata & T;
93
+ instance?: TObject;
94
+ type: TFunction;
95
+ index?: number;
96
+ key: string | symbol;
97
+ }
98
+ interface TPipeFn<T extends TObject = TEmpty> {
99
+ (value: unknown, metas: TPipeMetas<T>, level: TDecoratorLevel): unknown | Promise<unknown>;
100
+ priority?: TPipePriority;
101
+ }
102
+ declare enum TPipePriority {
103
+ BEFORE_RESOLVE = 0,
104
+ RESOLVE = 1,
105
+ AFTER_RESOLVE = 2,
106
+ BEFORE_TRANSFORM = 3,
107
+ TRANSFORM = 4,
108
+ AFTER_TRANSFORM = 5,
109
+ BEFORE_VALIDATE = 6,
110
+ VALIDATE = 7,
111
+ AFTER_VALIDATE = 8
112
+ }
113
+ interface TPipeData {
114
+ handler: TPipeFn;
115
+ priority: TPipePriority;
116
+ }
117
+
118
+ interface TMoostMetadata<H extends TObject = TEmpty> extends TCommonMetaFields, TCommonMoostMeta {
119
+ requiredProps?: Array<string | symbol>;
120
+ controller?: {
121
+ prefix?: string;
122
+ };
123
+ importController?: Array<{
124
+ prefix?: string;
125
+ typeResolver?: TClassConstructor | (() => TClassConstructor | TObject | Promise<TClassConstructor | TObject>);
126
+ provide?: TProvideRegistry;
127
+ }>;
128
+ properties?: Array<string | symbol>;
129
+ injectable?: true | TInjectableScope;
130
+ interceptors?: TInterceptorData[];
131
+ handlers?: Array<TMoostHandler<H>>;
132
+ returnType?: TFunction;
133
+ provide?: TProvideRegistry;
134
+ replace?: TReplaceRegistry;
135
+ params: Array<TMateParamMeta & TMoostParamsMetadata>;
136
+ }
137
+ interface TMoostParamsMetadata extends TCommonMetaFields, TCommonMoostMeta {
138
+ circular?: () => TAny;
139
+ inject?: string | symbol | TClassConstructor;
140
+ nullable?: boolean;
141
+ paramSource?: string;
142
+ paramName?: string;
143
+ }
144
+ type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
145
+ type TMoostHandler<T> = {
146
+ type: string;
147
+ path?: string;
148
+ } & T;
149
+ interface TInterceptorData {
150
+ handler: TCallableClassFunction<TInterceptorFn>;
151
+ priority: TInterceptorPriority;
152
+ }
153
+ interface TCommonMetaFields {
154
+ id?: string;
155
+ label?: string;
156
+ value?: unknown;
157
+ description?: string;
158
+ optional?: boolean;
159
+ required?: boolean;
160
+ }
161
+ interface TCommonMoostMeta {
162
+ inherit?: boolean;
163
+ pipes?: TPipeData[];
164
+ resolver?: (metas: TPipeMetas<TAny>, level: TDecoratorLevel) => unknown;
165
+ type?: TFunction;
166
+ }
167
+
168
+ interface TOtelMate {
169
+ otelIgnoreSpan: boolean;
170
+ }
171
+ declare function getOtelMate(): _prostojs_mate.Mate<TMoostMetadata<TEmpty> & TOtelMate & {
172
+ params: (TOtelMate & _prostojs_mate.TMateParamMeta)[];
173
+ }, TMoostMetadata<TEmpty> & TOtelMate & {
174
+ params: (TOtelMate & _prostojs_mate.TMateParamMeta)[];
175
+ }>;
176
+
177
+ declare class MoostBatchSpanProcessor extends BatchSpanProcessor {
178
+ onEnd(span: ReadableSpan): void;
179
+ }
180
+
181
+ declare class MoostSimpleSpanProcessor extends SimpleSpanProcessor {
182
+ onEnd(span: ReadableSpan): void;
183
+ }
184
+
185
+ declare function shouldSpanBeIgnored(span: ReadableSpan): boolean;
186
+
187
+ export { MoostBatchSpanProcessor, MoostSimpleSpanProcessor, OtelIgnoreSpan, type TOtelContext, type TOtelMate, enableOtelForMoost, getOtelMate, shouldSpanBeIgnored, useOtelContext, useOtelPropagation, useSpan, useTrace };