mirror of
https://github.com/langgenius/dify.git
synced 2026-03-04 23:36:20 +08:00
Implement core enterprise OpenTelemetry infrastructure with type-safe enums for all telemetry primitives (spans, counters, histograms). Architecture: - EnterpriseExporter: Own TracerProvider + shared global MeterProvider - EnterpriseDataTrace: Duck-typed trace handler (not BaseTraceInstance subclass) - Flask extension: Lifecycle management and singleton exporter access - Enums: Single source of truth for span names and metric names Key features: - Type-safe telemetry with IDE autocomplete and compile-time checking - Configurable trace sampling (default 100%) - 100% accurate metrics (always collected, no sampling) - Privacy controls via ENTERPRISE_INCLUDE_CONTENT flag - Zero overhead when disabled (enterprise flag gates) Components: - enterprise/telemetry/entities: Span/Counter/Histogram enums - enterprise/telemetry/exporter.py: OTEL exporter setup - enterprise/telemetry/enterprise_trace.py: Trace handler using enums - extensions/ext_enterprise_telemetry.py: Flask extension - app_factory.py: Register extension in init list