{"library":"opentelemetry-exporter-gcp-logging","title":"Google Cloud Logging exporter for OpenTelemetry","description":"The `opentelemetry-exporter-gcp-logging` library provides an OpenTelemetry Log exporter that sends log data to Google Cloud Logging. It's part of the OpenTelemetry Python Contrib project for Google Cloud operations. The current version is 1.11.0a0, and releases generally follow the OpenTelemetry Python SDK's release cadence, with specific updates for Google Cloud integration.","language":"python","status":"active","last_verified":"Thu May 14","install":{"commands":["pip install opentelemetry-exporter-gcp-logging"],"cli":null},"imports":["from opentelemetry.exporter.cloud_logging import CloudLoggingExporter"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import logging\nfrom opentelemetry.sdk._logs import LoggerProvider, LoggingHandler\nfrom opentelemetry.sdk._logs.export import BatchLogRecordProcessor, SimpleLogRecordProcessor\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry._logs import set_logger_provider\nfrom opentelemetry.exporter.cloud_logging import CloudLoggingExporter\n\n# Configure OpenTelemetry LoggerProvider\nresource = Resource.create(\n    {\n        \"service.name\": \"my-python-app\",\n        \"service.instance.id\": \"instance-1\",\n    }\n)\n\nlogger_provider = LoggerProvider(resource=resource)\nset_logger_provider(logger_provider)\n\n# --- Example 1: Exporting via RPC (default for older versions, or if structured_json_file is not set) ---\nexporter_rpc = CloudLoggingExporter(default_log_name='my_app_logs_rpc')\nlogger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter_rpc))\n\n# --- Example 2: Exporting as structured JSON to stdout (recommended for GCP environments >= v1.11.0) ---\n# This is more efficient for environments with Cloud Logging agent that scrapes stdout\nexporter_json = CloudLoggingExporter(default_log_name='my_app_logs_json', structured_json_file=True)\nlogger_provider.add_log_record_processor(SimpleLogRecordProcessor(exporter_json)) # Simple processor is often sufficient for stdout export\n\n# Attach OTLP handler to the root logger\nhandler = LoggingHandler(level=logging.INFO, logger_provider=logger_provider)\nlogging.getLogger().addHandler(handler)\n\n# Create a namespaced logger for your application\n# It's recommended not to use the root logger with OTLP handler directly for app logs\napp_logger = logging.getLogger(\"my_app_module\")\napp_logger.info(\"This is an info log with OTel context!\")\napp_logger.warning(\"A warning occurred: %s\", \"something went wrong\")\n\n# Logs will be exported asynchronously by BatchLogRecordProcessor\n# For SimpleLogRecordProcessor, logs are sent immediately\n\n# It's good practice to shut down the logger provider when the application exits\n# This ensures all buffered logs are flushed.\n# In a real application, you'd typically do this in a graceful shutdown hook.\nlogger_provider.shutdown()\nprint(\"Logs sent to Cloud Logging (or stdout for structured JSON exporter).\")","lang":"python","description":"This quickstart demonstrates how to configure the `CloudLoggingExporter` to send Python logs to Google Cloud Logging. It includes examples for both the traditional RPC-based export (using `BatchLogRecordProcessor`) and the recommended structured JSON export to stdout (using `SimpleLogRecordProcessor`), which is more efficient when running in GCP environments with a Cloud Logging agent.","tag":null,"tag_description":null,"last_tested":"2026-04-25","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-14","installed_version":"1.12.0a0","pypi_latest":"1.12.0a0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":6.1,"avg_import_s":2.36,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":null,"import_time_s":2.48,"mem_mb":31.1,"disk_size":"75.7M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":2.79,"mem_mb":30.4,"disk_size":"74.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":6.7,"import_time_s":1.41,"mem_mb":25.3,"disk_size":"73M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":1.33,"mem_mb":24.5,"disk_size":"72M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":2.9,"mem_mb":38.2,"disk_size":"80.8M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":3.41,"mem_mb":38,"disk_size":"79.9M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":6,"import_time_s":1.92,"mem_mb":32.9,"disk_size":"79M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":1.95,"mem_mb":32.7,"disk_size":"78M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":2.98,"mem_mb":38.2,"disk_size":"72.2M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":3.36,"mem_mb":38.1,"disk_size":"71.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":5,"import_time_s":2.25,"mem_mb":33,"disk_size":"70M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":2.28,"mem_mb":32.9,"disk_size":"69M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":2.8,"mem_mb":38.8,"disk_size":"71.9M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":3.22,"mem_mb":38.6,"disk_size":"70.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":5.1,"import_time_s":2.19,"mem_mb":33.5,"disk_size":"70M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":2.45,"mem_mb":33.3,"disk_size":"69M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":null,"import_time_s":2.21,"mem_mb":36.2,"disk_size":"75.7M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":2.33,"mem_mb":36.1,"disk_size":"74.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"noisy","install_time_s":7.5,"import_time_s":1.55,"mem_mb":30.3,"disk_size":"73M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opentelemetry-exporter-gcp-logging","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":1.47,"mem_mb":30.2,"disk_size":"73M"}]}}