@moostjs/otel 0.4.7 → 0.4.9

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
@@ -4,15 +4,18 @@ import * as _prostojs_mate from '@prostojs/mate';
4
4
  import { TMateParamMeta } from '@prostojs/mate';
5
5
  import { TProvideRegistry, TReplaceRegistry } from '@prostojs/infact';
6
6
  import { BatchSpanProcessor, ReadableSpan, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
7
+ import { IncomingMessage, ServerResponse } from 'http';
8
+ import { ContextInjector, TContextInjectorHook } from 'moost';
7
9
 
8
10
  interface TOtelContext {
9
11
  otel?: {
10
12
  span?: Span;
13
+ route?: string;
11
14
  };
12
15
  }
13
16
  declare function useOtelContext(): {
14
17
  trace: _opentelemetry_api.TraceAPI;
15
- withChildSpan: <T>(name: string, cb: (...a: any[]) => T, opts?: SpanOptions) => T | (() => T);
18
+ withChildSpan: <T>(name: string, cb: (...a: any[]) => T, opts?: SpanOptions) => () => T;
16
19
  getSpan: () => Span | undefined;
17
20
  getSpanContext: () => _opentelemetry_api.SpanContext | undefined;
18
21
  getPropagationHeaders: () => {
@@ -23,6 +26,7 @@ declare function useOtelContext(): {
23
26
  tracestate?: undefined;
24
27
  };
25
28
  registerSpan: (span: Span) => unknown;
29
+ pushSpan: (span: Span) => void;
26
30
  };
27
31
  declare function useTrace(): _opentelemetry_api.TraceAPI;
28
32
  declare function useSpan(): Span | undefined;
@@ -50,6 +54,10 @@ declare function enableOtelForMoost(): void;
50
54
  * Requires use of MoostBatchSpanProcessor or MoostSimpleSpanProcessor
51
55
  */
52
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;
53
61
 
54
62
  type TAny = any;
55
63
  type TAnyFn = (...a: TAny[]) => unknown;
@@ -167,6 +175,7 @@ interface TCommonMoostMeta {
167
175
 
168
176
  interface TOtelMate {
169
177
  otelIgnoreSpan: boolean;
178
+ otelIgnoreMeter: boolean;
170
179
  }
171
180
  declare function getOtelMate(): _prostojs_mate.Mate<TMoostMetadata<TEmpty> & TOtelMate & {
172
181
  params: (TOtelMate & _prostojs_mate.TMateParamMeta)[];
@@ -184,4 +193,40 @@ declare class MoostSimpleSpanProcessor extends SimpleSpanProcessor {
184
193
 
185
194
  declare function shouldSpanBeIgnored(span: ReadableSpan): boolean;
186
195
 
187
- export { MoostBatchSpanProcessor, MoostSimpleSpanProcessor, OtelIgnoreSpan, type TOtelContext, type TOtelMate, enableOtelForMoost, getOtelMate, shouldSpanBeIgnored, useOtelContext, useOtelPropagation, useSpan, useTrace };
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>(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 | undefined;
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 };