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. Use build_test_tracer() for a non-exporting tracer in unit tests.
Instrumentors
Pass any BaseInstrumentor as a trailing argument and it is attached to the
provider built here -- no need to reach for the global one:
from opentelemetry.instrumentation.langchain import LangchainInstrumentor
setup_telemetry(config, LangchainInstrumentor())
Several are fine, and an existing list can be splatted:
setup_telemetry(config, LangchainInstrumentor(), RequestsInstrumentor())
setup_telemetry(config, *instrumentors)
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:
-
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 venkateshvasukiRepository reusable_otel_metricWorkflow publish.ymlEnvironment pypi -
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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| otel_metrics-0.2.0.tar.gz | 11.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| otel_metrics-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.1 kB
Release files / otel_metrics-0.2.0.tar.gz
| Download URL | otel_metrics-0.2.0.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb0823b757cd5d7b7787c59d1aa671cccd92b1e8c7b8bc4d6f3d33f5677e8058
|
|
BLAKE2b-256 checksum How to use checksums |
3ab241402a1254745fc584924baf5f0f3f284aac7091a0b4a616cacd17451855
|
| 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 logRelease files / otel_metrics-0.2.0-py3-none-any.whl
| Download URL | otel_metrics-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d7f90b0baa57166e129843a4eb7fe3362609deb81e9b03d146e3eb47b7d6689
|
|
BLAKE2b-256 checksum How to use checksums |
8e4494afb1fe516c503ae56faf9927822f004cfb655a141173e6f2d00fbcf0d3
|
| 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 logSecurity for otel-metrics 0.2.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.
Attestation for otel_metrics-0.2.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 logA 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.