@moostjs/otel 0.5.21 → 0.5.22

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,11 +1,9 @@
1
+ /// <reference types="node" />
1
2
  import * as _opentelemetry_api from '@opentelemetry/api';
2
3
  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';
4
+ import { Mate, TMoostMetadata, TMateParamMeta, ContextInjector, TContextInjectorHook } from 'moost';
6
5
  import { BatchSpanProcessor, ReadableSpan, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
7
6
  import { IncomingMessage, ServerResponse } from 'http';
8
- import { ContextInjector, TContextInjectorHook } from 'moost';
9
7
 
10
8
  interface TOtelContext {
11
9
  otel?: {
@@ -52,145 +50,17 @@ declare function useOtelPropagation(): {
52
50
 
53
51
  declare function enableOtelForMoost(): void;
54
52
 
55
- /**
56
- * Annotate controller and/or handler to filter
57
- * out the corresponding spans from transporting
58
- *
59
- * Requires use of MoostBatchSpanProcessor or MoostSimpleSpanProcessor
60
- */
61
53
  declare const OtelIgnoreSpan: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
62
- /**
63
- * Annotate controller and/or handler to suppress metrics
64
- */
65
54
  declare const OtelIgnoreMeter: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
66
55
 
67
- type TAny = any;
68
- type TAnyFn = (...a: TAny[]) => unknown;
69
- type TObject = object;
70
- type TFunction = Function;
71
- type TClassConstructor<T = unknown> = new (...args: TAny[]) => T;
72
- interface TEmpty {
73
- }
74
-
75
- interface TClassFunction<T extends TAnyFn = TAnyFn> {
76
- handler: T;
77
- }
78
- type TClassFunctionConstructor<T extends TAnyFn = TAnyFn> = new (...a: TAny[]) => TClassFunction<T>;
79
- type TCallableClassFunction<T extends TAnyFn = TAnyFn> = T | TClassFunctionConstructor;
80
-
81
- type TInterceptorBefore = (reply: (response: TAny) => void) => void | Promise<void>;
82
- type TInterceptorAfter = (response: TAny, reply: (response: TAny) => void) => void | Promise<void>;
83
- type TInterceptorOnError = (error: Error, reply: (response: TAny) => void) => void | Promise<void>;
84
- interface TInterceptorFn {
85
- (before: (fn: TInterceptorBefore) => void, after: (fn: TInterceptorAfter) => void, onError: (fn: TInterceptorOnError) => void): unknown | Promise<unknown>;
86
- priority?: TInterceptorPriority;
87
- _name?: string;
88
- }
89
- declare enum TInterceptorPriority {
90
- BEFORE_ALL = 0,
91
- BEFORE_GUARD = 1,
92
- GUARD = 2,
93
- AFTER_GUARD = 3,
94
- INTERCEPTOR = 4,
95
- CATCH_ERROR = 5,
96
- AFTER_ALL = 6
97
- }
98
-
99
- type TDecoratorLevel = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
100
-
101
- interface TPipeMetas<T extends TObject = TEmpty> {
102
- classMeta?: TMoostMetadata & T;
103
- methodMeta?: TMoostMetadata & T;
104
- propMeta?: TMoostMetadata & T;
105
- paramMeta?: TMoostParamsMetadata & T;
106
- targetMeta?: TMoostParamsMetadata & T;
107
- instance?: TObject;
108
- scopeId?: string | symbol;
109
- type: TFunction;
110
- index?: number;
111
- key: string | symbol;
112
- }
113
- interface TPipeFn<T extends TObject = TEmpty> {
114
- (value: unknown, metas: TPipeMetas<T>, level: TDecoratorLevel): unknown | Promise<unknown>;
115
- priority?: TPipePriority;
116
- }
117
- declare enum TPipePriority {
118
- BEFORE_RESOLVE = 0,
119
- RESOLVE = 1,
120
- AFTER_RESOLVE = 2,
121
- BEFORE_TRANSFORM = 3,
122
- TRANSFORM = 4,
123
- AFTER_TRANSFORM = 5,
124
- BEFORE_VALIDATE = 6,
125
- VALIDATE = 7,
126
- AFTER_VALIDATE = 8
127
- }
128
- interface TPipeData {
129
- handler: TPipeFn;
130
- priority: TPipePriority;
131
- }
132
-
133
- interface TMoostMetadata<H extends TObject = TEmpty> extends TCommonMetaFields, TCommonMoostMeta {
134
- requiredProps?: Array<string | symbol>;
135
- controller?: {
136
- prefix?: string;
137
- };
138
- importController?: Array<{
139
- prefix?: string;
140
- typeResolver?: TClassConstructor | (() => TClassConstructor | TObject | Promise<TClassConstructor | TObject>);
141
- provide?: TProvideRegistry;
142
- }>;
143
- properties?: Array<string | symbol>;
144
- injectable?: true | TInjectableScope;
145
- interceptors?: TInterceptorData[];
146
- handlers?: Array<TMoostHandler<H>>;
147
- returnType?: TFunction;
148
- provide?: TProvideRegistry;
149
- replace?: TReplaceRegistry;
150
- loggerTopic?: string;
151
- params: Array<TMateParamMeta & TMoostParamsMetadata>;
152
- }
153
- interface TMoostParamsMetadata extends TCommonMetaFields, TCommonMoostMeta {
154
- circular?: () => TAny;
155
- inject?: string | symbol | TClassConstructor;
156
- nullable?: boolean;
157
- paramSource?: string;
158
- paramName?: string;
159
- fromScope?: string | symbol;
160
- }
161
- type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
162
- type TMoostHandler<T> = {
163
- type: string;
164
- path?: string;
165
- } & T;
166
- interface TInterceptorData {
167
- handler: TCallableClassFunction<TInterceptorFn>;
168
- priority: TInterceptorPriority;
169
- name: string;
170
- }
171
- interface TCommonMetaFields {
172
- id?: string;
173
- label?: string;
174
- value?: unknown;
175
- description?: string;
176
- optional?: boolean;
177
- required?: boolean;
178
- }
179
- interface TCommonMoostMeta {
180
- inherit?: boolean;
181
- pipes?: TPipeData[];
182
- resolver?: (metas: TPipeMetas<TAny>, level: TDecoratorLevel) => unknown;
183
- type?: TFunction;
184
- }
185
-
186
56
  interface TOtelMate {
187
57
  otelIgnoreSpan: boolean;
188
58
  otelIgnoreMeter: boolean;
189
59
  }
190
- declare function getOtelMate(): _prostojs_mate.Mate<TMoostMetadata<TEmpty> & TOtelMate & {
191
- params: (TOtelMate & _prostojs_mate.TMateParamMeta)[];
192
- }, TMoostMetadata<TEmpty> & TOtelMate & {
193
- params: (TOtelMate & _prostojs_mate.TMateParamMeta)[];
60
+ declare function getOtelMate(): Mate<TMoostMetadata & TOtelMate & {
61
+ params: Array<TOtelMate & TMateParamMeta>;
62
+ }, TMoostMetadata & TOtelMate & {
63
+ params: Array<TOtelMate & TMateParamMeta>;
194
64
  }>;
195
65
 
196
66
  declare class MoostBatchSpanProcessor extends BatchSpanProcessor {
@@ -247,18 +117,6 @@ interface TSpanInput {
247
117
  name: string;
248
118
  options?: SpanOptions;
249
119
  }
250
- /**
251
- * Starts or continues a span, executes the callback within the span's context,
252
- * and handles span completion and error recording. Supports both synchronous and asynchronous callbacks.
253
- * An optional post-processing callback can be used to enrich the span before it ends.
254
- *
255
- * @template T
256
- * @param {TSpanInput | Span} span - The span input containing name and options, or an existing span.
257
- * @param {() => T} cb - The callback function to execute within the span's context.
258
- * @param {TPostSpanProcessFn<T>=} postProcess - An optional post-processing callback to enrich the span before it ends. **CAUTION: When used, you must end the span yourself `span.end()`.**
259
- * @returns {T} The result of the callback function.
260
- * @throws {Error} Will throw an error if the callback function throws.
261
- */
262
120
  declare function withSpan<T>(span: TSpanInput | Span, cb: () => T, postProcess?: TPostSpanProcessFn<T>): T;
263
121
 
264
122
  export { MoostBatchSpanProcessor, MoostSimpleSpanProcessor, OtelIgnoreMeter, OtelIgnoreSpan, SpanInjector, type TOtelContext, type TOtelMate, type TPostSpanProcessFn, type TSpanInput, enableOtelForMoost, getOtelMate, shouldSpanBeIgnored, useOtelContext, useOtelPropagation, useSpan, useTrace, withSpan };