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

# 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.8.tar.gz (4.1 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.8-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_otel_py-0.0.8.tar.gz
  • Upload date:
  • Size: 4.1 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.8.tar.gz
Algorithm Hash digest
SHA256 062510617a34af70ed88753aab2f7a8b43f60e01cc2932ebd250edd293422ebf
MD5 185271e34f3a2b2b5509bdcfcc784a7c
BLAKE2b-256 d4f9a041d6ce2006306ab9a74dda4c7f49456c75dc30f938d612b3ffad34561e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_otel_py-0.0.8-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.11

File hashes

Hashes for simple_otel_py-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 90bc1fd8fa65169adfce70c8c388c97c0e555b22b83c07080b2ba79a0e825c8e
MD5 a8bcca2854bf7c15cf1590cebcce7bc3
BLAKE2b-256 799bf1649dd525d601bec754f3e503905d1fca8ef14b1767c9aa2be59ab2f713

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