UNPKG

@jufab/opentelemetry-angular-interceptor

Version:

@jufab/opentelemetry-angular-interceptor is an Angular Library to deploy [OpenTelemetry](https://opentelemetry.io/) in your Angular application

111 lines (110 loc) 3.46 kB
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http'; import { PlatformLocation } from '@angular/common'; import { Observable } from 'rxjs'; import { DiagLogger } from '@opentelemetry/api'; import { WebTracerProvider, StackContextManager } from '@opentelemetry/sdk-trace-web'; import { OpenTelemetryConfig } from '../configuration/opentelemetry-config'; import { IExporter } from '../services/exporter/exporter.interface'; import { IPropagator } from '../services/propagator/propagator.interface'; import { CustomSpan } from './custom-span.interface'; import * as i0 from "@angular/core"; /** * OpenTelemetryInterceptor class */ export declare class OpenTelemetryHttpInterceptor implements HttpInterceptor { private config; private exporterService; private propagatorService; private logger; private customSpan; private platformLocation; /** * tracer */ tracer: WebTracerProvider; /** * context manager */ contextManager: StackContextManager; /** * Log or not body */ logBody: boolean; /** * constructor * * @param config configuration * @param exporterService service exporter injected * @param propagatorService propagator injected * @param logger define logger * @param customSpan a customSpan interface to add attributes * @param platformLocation encapsulates all calls to DOM APIs */ constructor(config: OpenTelemetryConfig, exporterService: IExporter, propagatorService: IPropagator, logger: DiagLogger, customSpan: CustomSpan, platformLocation: PlatformLocation); /** * Overide method * Interceptor from HttpInterceptor Angular * * @param request the current request * @param next next */ intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>>; /** * Get current scheme, hostname and port */ private getURL; /** * Generate Resource Attributes */ private loadResourceAttributes; /** * Initialise a span for a request intercepted * * @param request request */ private initSpan; /** * Add header propagator in request and conserve original header * * @param request request */ private injectContextAndHeader; /** * Verify to insert or not a Span Exporter */ private insertOrNotSpanExporter; /** * Insert in tracer the console span if config is true */ private insertConsoleSpanExporter; /** * Insert BatchSpanProcessor in production mode * SimpleSpanProcessor otherwise */ private insertSpanProcessorProductionMode; /** * define the Probability Sampler * By Default, it's always (or 1) * * @param sampleConfig the sample configuration */ private defineProbabilitySampler; /** * convert String to Number (or undefined) * * @param value * @returns number or undefined */ private convertStringToNumber; /** * Set custom attributes in span with a CustomSpan * * @param span * @param request * @param response * @returns Span */ private setCustomSpan; static ɵfac: i0.ɵɵFactoryDeclaration<OpenTelemetryHttpInterceptor, [null, null, null, { optional: true; }, { optional: true; }, null]>; static ɵprov: i0.ɵɵInjectableDeclaration<OpenTelemetryHttpInterceptor>; }