observability_otel module

OpenTelemetry setup (safe, optional, idempotent).

This module configures tracing (OTLP exporter) and auto-instrumentation for:

  • Flask (when a Flask app instance is provided)

  • requests (HTTP client)

  • PyMongo

Design goals:

  • Fail-open: if OpenTelemetry packages are not installed or misconfigured, setup_telemetry silently returns without raising.

  • Idempotent: multiple calls are safe; only the first successful init takes effect.

  • Non-invasive: avoid changing existing structlog configuration; we rely on observability._add_otel_ids to inject trace_id/span_id when tracing is active.

observability_otel.setup_telemetry(*, service_name='codebot-service', service_version=None, environment=None, flask_app=None)[מקור]

Initialize OpenTelemetry tracing and basic instrumentation.

פרמטרים:
  • service_name (str) – Logical service name for resource attributes.

  • service_version (Optional[str]) – Version string reported with resource.

  • environment (Optional[str]) – Environment hint (e.g., production/staging/development).

  • flask_app (Optional[Flask]) – Flask app instance for explicit instrumentation; if None, Flask instrumentation is skipped.

Return type:

None