Implement comprehensive distributed tracing for HTTP requests and LLM operations using OpenTelemetry with GenAI semantic conventions. Features: - TelemetryService: SDK initialization with OTLP HTTP exporter - TelemetryInterceptor: Automatic HTTP request spans - @TraceLlmCall decorator: LLM operation tracing - GenAI semantic conventions for model/token tracking - Graceful degradation when tracing disabled Instrumented: - All HTTP requests (automatic spans) - OllamaProvider chat/chatStream/embed operations - Token counts, model names, durations Environment: - OTEL_ENABLED (default: true) - OTEL_SERVICE_NAME (default: mosaic-api) - OTEL_EXPORTER_OTLP_ENDPOINT (default: localhost:4318) Tests: 23 passing with full coverage Fixes #131 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
24 lines
707 B
TypeScript
24 lines
707 B
TypeScript
import { Module, Global } from "@nestjs/common";
|
|
import { TelemetryService } from "./telemetry.service";
|
|
import { TelemetryInterceptor } from "./telemetry.interceptor";
|
|
import { SpanContextService } from "./span-context.service";
|
|
|
|
/**
|
|
* Global module providing OpenTelemetry distributed tracing.
|
|
* Automatically instruments HTTP requests and provides utilities for LLM tracing.
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* @Module({
|
|
* imports: [TelemetryModule],
|
|
* })
|
|
* export class AppModule {}
|
|
* ```
|
|
*/
|
|
@Global()
|
|
@Module({
|
|
providers: [TelemetryService, TelemetryInterceptor, SpanContextService],
|
|
exports: [TelemetryService, TelemetryInterceptor, SpanContextService],
|
|
})
|
|
export class TelemetryModule {}
|