Skip to main content

OpenTelemetry observability SDK for Python — structured logging, distributed tracing, and auto-instrumentation

Project description

otel-log

OpenTelemetry-compliant structured logging for Python. Produces JSON logs conforming to the OTel Log Data Model and optionally configures distributed tracing from a single call.

Installation

# Logging only (lightweight — only opentelemetry-api required)
pip install otel-log

# Logging + tracing
pip install otel-log[tracing]

Quick Start

import otel_log

result = otel_log.setup("my-service", version="1.0.0")

import logging
logging.info("Hello world")
# => {"Timestamp":"...","SeverityText":"INFO","SeverityNumber":9,"Body":"Hello world","Resource":{"service.name":"my-service","service.version":"1.0.0"}}

result.shutdown()

With Tracing

import otel_log

result = otel_log.setup("my-service", endpoint="localhost:4317")

with result.tracer.start_as_current_span("my-operation"):
    logging.info("Inside a span")
    # TraceId, SpanId, TraceFlags auto-injected into the JSON output

Advanced Usage

For auto-instrumentors, custom exporters, or fine-grained configuration:

from otel_log import OTelInitializer, ResourceConfig, InstrumentationConfig

result = OTelInitializer.initialize(
    resource_config=ResourceConfig(
        service_name="my-service",
        service_version="1.0.0",
        deployment_environment="production",
        custom_attributes={"cloud.region": "us-east-1"},
    ),
    instrumentation_config=InstrumentationConfig(
        endpoint="localhost:4317",
        protocol="grpc",
    ),
)

Environment Variables

Variable Required Description
OTEL_SERVICE_NAME Yes Service name (overrides config)
OTEL_EXPORTER_OTLP_ENDPOINT No OTLP trace exporter endpoint. If unset, tracing is disabled (no-op).
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT No OTLP log exporter endpoint. If unset, logs go to console only.
OTEL_RESOURCE_ATTRIBUTES No Comma-separated key=value resource attributes

Output Format

All logs conform to the shared JSON schema:

{
  "Timestamp": "2026-03-22T12:00:00.000000Z",
  "SeverityText": "INFO",
  "SeverityNumber": 9,
  "Body": "User logged in",
  "Resource": {"service.name": "my-service"},
  "TraceId": "0af7651916cd43dd8448eb211c80319c",
  "SpanId": "b7ad6b7169203331",
  "TraceFlags": "01"
}

License

Proprietary. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otel_log-0.5.2.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

otel_log-0.5.2-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file otel_log-0.5.2.tar.gz.

File metadata

  • Download URL: otel_log-0.5.2.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for otel_log-0.5.2.tar.gz
Algorithm Hash digest
SHA256 b74dc03f7bc5ff4a82c620575d1e4b9c6989a6883987d1e38701f565f93398fe
MD5 6ee0addd349d9eff201df2bade56a9cb
BLAKE2b-256 de7ef92fe1d922bcf221ac3f1c0a08ea3605c06e92da08a827a016912e44166d

See more details on using hashes here.

File details

Details for the file otel_log-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: otel_log-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for otel_log-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7a4cb62a61754c7ce98de6c23f0298c3c541eedc54a5f31e6a3f2ebdee057b12
MD5 6b5c8df39959f3b2a1c197f4c4304224
BLAKE2b-256 f5139f43e7c1ddcf46e51d2a693d32cf150c79684a7f3142cbe2b7c463f3ca56

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page