Skip to main content

Utilidades simplificadas para instrumentación con OpenTelemetry

Project description

OpenTelemetry Utils

A Python library designed to simplify application instrumentation using OpenTelemetry. This library provides an abstraction layer that makes instrumentation more intuitive and less intrusive in your business logic.

Features

  • Simplified OpenTelemetry configuration
  • Intuitive API for distributed tracing
  • Utilities for metrics and structured logging
  • OpenTelemetry Collector integration
  • Complete context propagation support
  • Full compatibility with asynchronous applications

Installation

To install the library from the private repository:

pip install git+ssh://git@github.com/your-organization/otel-utils.git

Or add this to your requirements.txt:

git+ssh://git@github.com/your-organization/otel-utils.git@v0.1.0

Basic Usage

Initial Configuration

from otel_utils import OtelConfig, OtelConfigurator

config = OtelConfig(
    service_name="my-service",
    environment="production"
)

OtelConfigurator(config)

Tracing

from otel_utils import Tracer

tracer = Tracer("my-service")

# Using the decorator
@tracer.trace("my_operation")
async def my_function():
    # Your code here
    pass

# Using the context manager
with tracer.create_span("my_operation") as span:
    span.set_attribute("key", "value")
    # Your code here

Metrics

from otel_utils import Metrics

metrics = Metrics("my-service")

# Simple counter
counter = metrics.get_counter("requests_total")
counter.add(1, {"endpoint": "/api/v1/resource"})

# Histogram for latencies
with metrics.measure_duration("request_duration"):
    # Your code here
    pass

Structured Logging

from otel_utils import StructuredLogger

logger = StructuredLogger("my-service")

with logger.operation_context("process_order", order_id="123"):
    logger.info("Starting processing")
    # Your code here

OpenTelemetry Collector Integration

This library is designed to work seamlessly with the OpenTelemetry Collector. Telemetry data is sent using the OTLP protocol, which is the OpenTelemetry standard.

# collector configuration example
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318

exporters:
  # configure your exporters here

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [your-exporter]

Best Practices

Separation of Concerns

Keep instrumentation separate from business logic by creating domain-specific abstractions. Your business code should remain clean and focused on its primary responsibilities.

Consistent Naming

Use coherent naming conventions for spans, metrics, and logs across your services. This makes it easier to correlate and analyze telemetry data.

Relevant Context

Include useful contextual information in spans and logs, but be mindful of sensitive data. Focus on information that aids debugging and monitoring.

Appropriate Granularity

Don't instrument everything. Focus on significant operations that provide value for monitoring and debugging. Consider the overhead and noise ratio when adding instrumentation.

Development

To set up the development environment:

# Create virtualenv
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

Contributing

  1. Create a feature branch (git checkout -b feature/new-feature)
  2. Commit your changes (git commit -am 'Add new feature')
  3. Push to the branch (git push origin feature/new-feature)
  4. Create a Pull Request

I hope this documentation helps you understand and effectively use the OpenTelemetry Utils library. Each section is designed to guide you through the essential aspects of instrumenting your applications while maintaining clean and maintainable code. Let me know if you need any clarification or have questions about specific features or use cases. We can explore any aspect of the library in more detail.

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_utils-0.1.11.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

otel_utils-0.1.11-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file otel_utils-0.1.11.tar.gz.

File metadata

  • Download URL: otel_utils-0.1.11.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.1.0

File hashes

Hashes for otel_utils-0.1.11.tar.gz
Algorithm Hash digest
SHA256 54cc2beede150b064f0a0324e632a52589317e33334953a13356b49567bc9af2
MD5 eeab22fb8274fb4b229e8083c4499048
BLAKE2b-256 07b16ece803b38b574c8f5968687074b0699ec3d72fe2a76ca71c30e3b8d9e39

See more details on using hashes here.

File details

Details for the file otel_utils-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: otel_utils-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.1.0

File hashes

Hashes for otel_utils-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 006f23faff8522b1be930aa132bc97a43ea17c8c9a04fa39e8414cb25f75f6c8
MD5 9c076f6fa75bfa19d32a42cdd9da4f40
BLAKE2b-256 7ce282e57f2c4668befaaf6db6f69aefcf0e258c005c3c82b9d98922944d863a

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