{"library":"opencensus-ext-logging","title":"OpenCensus Logging Integration","description":"This library provides an integration for the OpenCensus tracing framework with Python's standard `logging` module. It enriches standard log records with `traceId`, `spanId`, and `traceSampled` attributes, enabling correlation of application logs with distributed traces. The current version is 0.1.1. The OpenCensus project is largely deprecated in favor of OpenTelemetry, with official support for some related exporters (e.g., Azure Monitor) ending by September 2024.","language":"python","status":"deprecated","last_verified":"Fri May 15","install":{"commands":["pip install opencensus-ext-logging"],"cli":null},"imports":["from opencensus.trace import config_integration"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import logging\nimport os\nfrom opencensus.trace import config_integration\nfrom opencensus.trace import tracer as tracer_module\nfrom opencensus.trace.exporters import PrintExporter\nfrom opencensus.trace.samplers import AlwaysOnSampler\n\n# 1. Configure the logging integration\n# This must be done *before* loggers are created for existing loggers to be affected.\nconfig_integration.trace_integrations(['logging'])\n\n# 2. Set up a basic Python logger\nlogger = logging.getLogger(__name__)\nlogger.setLevel(logging.INFO)\nhandler = logging.StreamHandler()\nformatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - TraceId: %(traceId)s - SpanId: %(spanId)s - %(message)s')\nhandler.setFormatter(formatter)\nlogger.addHandler(handler)\n\n# 3. Set up an OpenCensus tracer with an exporter (e.g., PrintExporter)\n# This will activate trace context, making trace and span IDs available for logging.\nexporter = PrintExporter()\nsampler = AlwaysOnSampler()\ntracer = tracer_module.Tracer(exporter=exporter, sampler=sampler)\n\nlogger.info(\"This log message will not have trace/span IDs yet as no span is active.\")\n\n# 4. Use the tracer to create a span to enable trace context propagation\nwith tracer.span(name='my_operation') as span:\n    logger.info(\"This log message should now have trace and span IDs.\")\n    with tracer.span(name='sub_operation'):\n        logger.warning(\"Another log message within a sub-span.\")\n\nlogger.info(\"This log message is outside the span and will not have trace/span IDs from the active span.\")","lang":"python","description":"This quickstart demonstrates how to enable the OpenCensus logging integration and how log messages are enriched with `traceId` and `spanId` when an OpenCensus trace span is active. The `PrintExporter` is used to visualize the trace information, and the standard Python logging handler outputs the enriched log records.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"0.1.1","pypi_latest":"0.1.1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":4.3,"avg_import_s":0.2,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.18,"mem_mb":4.3,"disk_size":"48.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.6,"import_time_s":0.06,"mem_mb":3.4,"disk_size":"49M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.5,"mem_mb":4.6,"disk_size":"52.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.3,"import_time_s":0.12,"mem_mb":3.8,"disk_size":"53M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.4,"mem_mb":4.5,"disk_size":"44.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.8,"import_time_s":0.11,"mem_mb":3.7,"disk_size":"45M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.37,"mem_mb":4.8,"disk_size":"43.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.6,"import_time_s":0.11,"mem_mb":4,"disk_size":"45M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.1,"mem_mb":4.3,"disk_size":"48.6M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opencensus-ext-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":5.4,"import_time_s":0.08,"mem_mb":3.4,"disk_size":"49M"}]}}