OpenTelemetry Standard Log Format library for Python
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file otel_log-0.3.3.tar.gz.
File metadata
- Download URL: otel_log-0.3.3.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0288441ad9e364697f3a6eb30554b45d7c8b9e10583218938d39446edd9689da
|
|
| MD5 |
4ee74917db3cf6db14dc326cafbffbcc
|
|
| BLAKE2b-256 |
54c0c8e2a2cf42c25e24cd78654ba00f5504c84fcba4123668bdc7bff589c19f
|
File details
Details for the file otel_log-0.3.3-py3-none-any.whl.
File metadata
- Download URL: otel_log-0.3.3-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23d00b8ca06f11c10fcdce216511e604d044564acc7d7abfa58ee593d6b5a503
|
|
| MD5 |
e5904c6d388a3a18b049dc5b9f2a9e15
|
|
| BLAKE2b-256 |
905d1f82b89623e5bc11a77b5374cc98c9889871e820e60e6c745d4a96a5e582
|