Skip to main content

Lightweight OpenTelemetry file exporter that writes traces, logs and metrics to local JSON Lines files

Project description

otel_file_exporter

A lightweight OpenTelemetry file exporter that writes traces, logs and metrics to local JSON Lines files – no external back-ends required.
All traces, logs and metrics are written locally as newline-delimited JSON (*.jsonl) so they can be inspected with your favorite tools or fed into pipelines later.

telemetry/
├─ traces.jsonl   <- Spans
├─ logs.jsonl     <- Structured application logs
└─ metrics.jsonl  <- OTLP metrics exports

Why?

  • Zero-dependency observability for demos, local development and CI
  • Uses the official OpenTelemetry SDK – switch to OTLP / Jaeger / etc. at any time
  • Demonstrates structured logging and custom OpenTelemetry exporters

Requirements

  • Python 3.13 or newer (matches pyproject.toml)
  • Windows, macOS or Linux – no native deps

Quick start

python -m venv .venv
.\.venv\Scripts\activate
pip install -e .
python examples\fastapi_app.py

Then open http://localhost:8000/docs for the interactive Swagger UI.

Example requests

curl http://localhost:8000/health
curl http://localhost:8000/items/123?include_description=true

Watch the telemetry directory fill with JSONL lines while you interact with the API.

Environment variables

Var Default Purpose
SERVICE_NAME fastapi-otel-demo Resource attribute in traces/logs/metrics
SERVICE_VERSION 1.0.0 Resource attribute
ENVIRONMENT development Resource attribute
LOG_LEVEL INFO Console & JSONL log level
TRACE_SAMPLE_RATE 1.0 0.0-1.0 probability sampler
METRICS_EXPORT_INTERVAL 5000 Export interval in ms
OUTPUT_DIR ./telemetry Where JSONL files are written
PORT 8000 HTTP port for the demo app

Set them in the shell, a .env file or your container orchestrator.

Library usage

Import the pre-configured helpers in your own code:

from otel_file_exporter import tracer, logger, app_metrics

with tracer.start_as_current_span("my_work"):
    logger.info("Hello with trace context!")

Project layout

examples/
└─ fastapi_app.py   # Self-contained demo API
src/otel_file_exporter/
    ├─ __init__.py
    └─ otel.py      # Custom exporters & bootstrap helpers
pyproject.toml
README.md

Development

pip install -e ".[dev]"   # add your own dev dependencies extras
pytest -q                 # add tests as you go

Feel free to open issues or PRs – contributions are welcome!

Publishing to PyPI

1. Trusted publishing (recommended)

The workflow in .github/workflows/release.yml uses PyPI’s Trusted Publishing (OIDC) together with
pypa/gh-action-pypi-publish@release/v1.

  1. Enable “Trusted Publishing” for the project on PyPI and link it to this repository.
  2. Create a GitHub Release (or press Run workflow in the Actions tab).
    The build artifacts are uploaded and automatically published to PyPI – no secret required.

2. Classic API-token publishing

The fallback workflow in .github/workflows/publish.yml is triggered whenever you push a git tag that matches v*.*.*.

  1. Create a scoped PyPI API token with publish privileges.
  2. Add it to the repository secrets as PYPI_API_TOKEN.
  3. Tag and push a new version:
git tag v0.2.0
git push --tags

License

This project is licensed under the MIT License. See LICENSE for details.

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_file_exporter-0.1.1.tar.gz (12.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_file_exporter-0.1.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file otel_file_exporter-0.1.1.tar.gz.

File metadata

  • Download URL: otel_file_exporter-0.1.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for otel_file_exporter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69102bebd89a7949baa3a15fdbe35099d76da0c41bc20687bd5d3b925aa64fe4
MD5 93c95f44ea7542888e38a7cf1d58e88c
BLAKE2b-256 ea602be79dab0929ed620160530df0e81d2904f47c2890f1ff8855ae3bdbc1ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for otel_file_exporter-0.1.1.tar.gz:

Publisher: publish.yml on Brishen/otel_file_exporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file otel_file_exporter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for otel_file_exporter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a91abee915cfc9e28df7d9ec8af44e26dec768af9607ee76b5c19eb03d16479
MD5 add77a9fdd315feeefaeb5f9d2471613
BLAKE2b-256 0c6d869faaa5dc4ad8d3ea7c0a097700f7f7b5234aa2dfca8f0c22209c7b34b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for otel_file_exporter-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Brishen/otel_file_exporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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