A simple library for setting up OpenTelemetry logging, tracing, and metrics in Python applications. To send them to an open otel collector
Project description
simple_otel_py
A simple library for setting up OpenTelemetry logging, tracing, and metrics in Python applications.
Features
- 🔹 Easy integration with OpenTelemetry
- 📊 Logs, traces, and metrics sent to an existing (open) OTLP collector
- 🖥️ Console logging for debugging
- 📡 Support for OpenTelemetry instrumentation
Installation
pip install simple_otel_py
Usage
Initialize OpenTelemetry Components
from simple_otel_py import OtelSetup
# Create an instance with service name and OTLP collector endpoint
otel = OtelSetup(name="my_service", otlp_collector_endpoint="http://localhost:4317")
# Initialize logging
logger = otel.get_logger()
logger.info("This is a test log!")
# You can provide your own formatter to the logger
import logging
formatter = logging.Formatter('%(asctime)s | %(name)s | %(levelname)s | %(message)s')
logger = otel.get_logger(formatter)
# Initialize tracing
[trace, tracer] = otel.init_tracing()
with tracer.start_as_current_span("test_span"):
logger.info("Tracing this operation!")
# you can add attributes to the trace
current_span = trace.get_current_span()
current_span.set_attribute("my.custom.attr", "something")
## or add tracing via decorator
@tracer.start_as_current_span("Tracing this operation!")
# Initialize metrics
meter = otel.init_metrics()
counter = meter.create_counter("my_counter")
counter.add(1)
# Enable auto-instrumentation for requests
request_inst = otel.get_request_instrumentor()
request_inst().instrument()
# Make a request (will be traced automatically)
import requests
response = requests.get("https://example.com")
print(response.status_code)
Configuration
Ensure you have an OpenTelemetry collector running, such as:
docker run --rm -p 4317:4317 -p 4318:4318 \
otel/opentelemetry-collector-contrib:latest
License
This project is licensed under the MIT License.
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
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 simple_otel_py-0.0.3.tar.gz.
File metadata
- Download URL: simple_otel_py-0.0.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffd080f950bd53527b15b1e5efce1cd351133a36f11175fe06ffaaf6a0f1bccd
|
|
| MD5 |
afd9252d2563a9a77d6752f2aa28ed48
|
|
| BLAKE2b-256 |
86a38762067244328caa95813343137f1417a095c7767f3a181a9a1894a75080
|
File details
Details for the file simple_otel_py-0.0.3-py3-none-any.whl.
File metadata
- Download URL: simple_otel_py-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e588a5ba9fc6b3a14f5c96a04ea3a63ed867b6b448302278d3017787822e2a37
|
|
| MD5 |
09256032dcdf4c05b7354678d91325d6
|
|
| BLAKE2b-256 |
f95352ceb6eb33ef4fb63e344bee008756b1a627af82cd7250c31472dfb684d7
|