Skip to main content

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!")

## If needed, you can pass a scope_name to create multiple logger
acme_logger = otel.get_logger("acme")

# 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

simple_otel_py-0.0.9.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

simple_otel_py-0.0.9-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file simple_otel_py-0.0.9.tar.gz.

File metadata

  • Download URL: simple_otel_py-0.0.9.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for simple_otel_py-0.0.9.tar.gz
Algorithm Hash digest
SHA256 f0bd86a8d13302e7e40a36b409b222a2ddd3c7031b4f3e8a0c04e8c8114fa8eb
MD5 7fb0c062ac7c4399e3dfe61554a31f1d
BLAKE2b-256 c28ff4eba4cb24ab4517774a6306755d677f8cd8c7d6bd310a8993319810470c

See more details on using hashes here.

File details

Details for the file simple_otel_py-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: simple_otel_py-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for simple_otel_py-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 4e7ea7f9936d108e117a5762a53812fccae6fc8470ba644694cefe495f03e981
MD5 cb83a4316265b30ee9e4a3010b8b3726
BLAKE2b-256 54ce4d40f685af1e69a6e68080f8157e1ab899dbe59608c8ca0c1fe0669ea4bf

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