Skip to main content

otel-metrics

Reusable OpenTelemetry library: simplified wrappers around OTel metric instruments, plus an OTLP tracing pipeline.

Install

pip install otel-metrics

Or from a built wheel:

pip install dist/otel_metrics-0.1.0-py3-none-any.whl

Usage

from enum import auto

from otel_metrics import MetricName, OtelConfig, setup_metrics

# Define your metric names
class MyMetrics(MetricName):
    REQUEST_COUNT = auto()
    REQUEST_DURATION_MS = auto()

# Configure and initialize
config = OtelConfig(endpoint="http://localhost:4317", service_name="my-service")
metrics = setup_metrics(config)

# Create instruments
counter = metrics.counter(MyMetrics.REQUEST_COUNT, description="Total requests")
timer = metrics.timer(MyMetrics.REQUEST_DURATION_MS, description="Request latency")

# Record
counter.inc()

Timing operations

from otel_metrics import TimestampNS

start = TimestampNS.now()
# ... do work ...
timer.record(start)

Configuration

OtelConfig is a pydantic-settings model. Values resolve from constructor args or environment variables:

Field Env var Default
endpoint OTEL_EXPORTER_OTLP_ENDPOINT (required)
service_name OTEL_SERVICE_NAME (required)
protocol OTEL_EXPORTER_OTLP_PROTOCOL grpc
headers OTEL_EXPORTER_OTLP_HEADERS None

Supported protocols: grpc, http/protobuf.

headers accepts either a mapping or the OTLP key=value,key2=value2 string form, and is forwarded to both the metrics and traces exporters. Values may be URL-encoded per the OTLP spec, but plain values are accepted too.

Tracing

from otel_metrics import OtelConfig, setup_telemetry

config = OtelConfig(
    endpoint="https://api.braintrust.dev/otel",
    service_name="my-service",
    protocol="http/protobuf",
    headers={"Authorization": "Bearer <key>", "x-bt-parent": "project_id:<id>"},
)
tracer = setup_telemetry(config)

with tracer.start_as_current_span("my-operation"):
    ...

setup_telemetry sets the process-global tracer provider, so call it once at startup and before importing anything that captures a tracer. Use build_test_tracer() for a non-exporting tracer in unit tests.

Testing

Use build_test_metrics() to get a no-op Metrics instance for unit tests:

from otel_metrics import build_test_metrics

metrics = build_test_metrics()

Development

uv sync
uv run pytest
uv run ruff check .

Build

uv build

Produces a wheel and an sdist in dist/.

Releasing

Publishing happens on merge to main. The workflow runs the tests and builds on every merge, but only uploads when the version in pyproject.toml is one PyPI has not seen — so bumping the version is what cuts a release. Merging anything else is a no-op for the index.

To release: bump version, open a PR, merge it.

Uploads use PyPI Trusted Publishing, so no API token lives in this repo. It needs a one-time setup on each index:

  1. On PyPI, go to Your projects → Publishing (or Account → Publishing for a name that has never been published) and add a GitHub publisher:

    Field Value
    Owner venkateshvasuki
    Repository reusable_otel_metric
    Workflow publish.yml
    Environment pypi
  2. In this repo's Settings → Environments, create an environment named pypi. Add required reviewers there if releases should need a human approval.

Repeat with an environment named testpypi on test.pypi.org to use the manual Run workflow button, which defaults to TestPyPI.

Metadata

Release files for otel-metrics 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for otel-metrics 0.1.0
File Size Uploaded Provenance
otel_metrics-0.1.0.tar.gz 10.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for otel-metrics 0.1.0
File Interpreter ABI Platform
otel_metrics-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / otel_metrics-0.1.0.tar.gz

Download URL otel_metrics-0.1.0.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4a8756c8a347f60a0090280aa861550283fcb2bc46f4d39c01d1907627864d19
BLAKE2b-256 checksum
How to use checksums
cd7cafdfec9c47dbe112ba9933885980ad4263e868ebeeb8de7ee38f684c6791
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release files / otel_metrics-0.1.0-py3-none-any.whl

Download URL otel_metrics-0.1.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7dd9f86ec59beeb2115927682e5b85bbf361bd58da034209af811dc08cbd9716
BLAKE2b-256 checksum
How to use checksums
c0dba51aa16c71d1be42658717500c96936584b338a064398abc8ec02d1def05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Security for otel-metrics 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for otel_metrics-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page