{"id":4672,"library":"opentracing","title":"OpenTracing Python API","description":"OpenTracing is a vendor-neutral API for distributed tracing. This Python library (version 2.4.0) provides the OpenTracing API specification and a basic no-op implementation, requiring a concrete tracer implementation (e.g., Jaeger, Zipkin) for actual tracing data collection. The OpenTracing project has been officially archived by the CNCF, with its functionality superseded by OpenTelemetry. New projects are strongly encouraged to use OpenTelemetry, and existing users should plan for migration.","status":"deprecated","version":"2.4.0","language":"en","source_language":"en","source_url":"https://github.com/opentracing/opentracing-python","tags":["tracing","observability","distributed tracing","api","deprecated"],"install":[{"cmd":"pip install opentracing","lang":"bash","label":"Install OpenTracing API"}],"dependencies":[],"imports":[{"symbol":"Tracer","correct":"from opentracing import Tracer"},{"symbol":"Span","correct":"from opentracing import Span"},{"symbol":"SpanContext","correct":"from opentracing import SpanContext"},{"symbol":"Reference","correct":"from opentracing import Reference"},{"note":"The Format enum is located in the `propagation` submodule.","wrong":"from opentracing import Format","symbol":"Format","correct":"from opentracing.propagation import Format"},{"note":"The global tracer is accessed via `opentracing.global_tracer()` or set via `opentracing.set_global_tracer()`.","wrong":"opentracing.tracer","symbol":"global_tracer","correct":"from opentracing import global_tracer"},{"symbol":"MockTracer","correct":"from opentracing.mocktracer import MockTracer"},{"note":"Specific scope managers are imported from the `scope_managers` submodule, depending on the concurrency model.","symbol":"ScopeManager (e.g., ThreadLocalScopeManager)","correct":"from opentracing.scope_managers.thread_local import ThreadLocalScopeManager"}],"quickstart":{"code":"import opentracing\nfrom opentracing.mocktracer import MockTracer\n\n# 1. Initialize a Tracer implementation (e.g., MockTracer for testing)\n# In a real application, you would use a concrete tracer like JaegerTracer.\ntracer = MockTracer()\nopentracing.set_global_tracer(tracer)\n\n# 2. Start a root span\nwith opentracing.global_tracer().start_active_span('root_operation') as scope:\n    root_span = scope.span\n    root_span.set_tag('component', 'quickstart_example')\n    root_span.log_kv({'event': 'started root operation'})\n\n    # 3. Create a child span\n    with opentracing.global_tracer().start_active_span('child_operation') as child_scope:\n        child_span = child_scope.span\n        child_span.set_tag('type', 'internal_call')\n        child_span.log_kv({'event': 'executing child logic'})\n\n    root_span.log_kv({'event': 'finished root operation'})\n\n# For MockTracer, retrieve finished spans for assertion\nfinished_spans = tracer.finished_spans\nassert len(finished_spans) == 2\nassert finished_spans[0].operation_name == 'child_operation'\nassert finished_spans[1].operation_name == 'root_operation'\n\nprint(f\"Captured {len(finished_spans)} spans:\")\nfor span in finished_spans:\n    print(f\" - {span.operation_name}, Tags: {span.tags}, Logs: {span.logs}\")","lang":"python","description":"This quickstart demonstrates how to initialize a MockTracer (for testing), set it as the global tracer, and then create nested spans using `start_active_span` with context managers. In a production environment, `MockTracer` would be replaced by a specific tracer client (e.g., `JaegerTracer`, `ZipkinTracer`) that exports telemetry data to a tracing backend."},"warnings":[{"fix":"For new projects, use OpenTelemetry. For existing OpenTracing projects, plan a migration to OpenTelemetry. OpenTelemetry provides an OpenTracing shim for backward compatibility during transitional phases.","message":"The OpenTracing project has been officially archived by the CNCF and its functionality is now superseded by OpenTelemetry. New projects should implement OpenTelemetry directly.","severity":"breaking","affected_versions":"All versions, as this reflects project status"},{"fix":"Install a concrete tracer library (e.g., `pip install jaeger-client`) and initialize it, then set it as the global tracer: `opentracing.set_global_tracer(your_actual_tracer)`.","message":"The `opentracing` library itself provides only an API and a no-op (no operation) tracer implementation. To actually collect and export trace data, you must install and configure a specific OpenTracing-compatible tracer implementation (e.g., `jaeger-client`, `zipkin-opentracing`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review span parenting logic; explicitly use `child_of` or `ignore_active_span=True` if the default auto-parenting behavior is not desired. Adapt code to use `start_active_span()` and context managers for simpler span lifecycle management.","message":"Version 2.0.0 introduced `Scope` and `ScopeManager` for in-process context propagation. This was a breaking change, altering how active spans are managed. `Tracer.start_span()` now automatically uses the current active Span as a parent unless `ignore_active_span=True` is explicitly set.","severity":"breaking","affected_versions":"2.0.0 and later"},{"fix":"Ensure that the OpenTracing tracer (and its underlying implementation) is initialized *within each child process* after the fork, rather than once in the parent process.","message":"When using `multiprocessing` in Python, the tracer initialized in the parent process is not automatically inherited or re-initialized in child processes. This can lead to child process spans not being reported.","severity":"gotcha","affected_versions":"All versions when using multiprocessing"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}