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.
- Enable “Trusted Publishing” for the project on PyPI and link it to this repository.
- 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*.*.*.
- Create a scoped PyPI API token with publish privileges.
- Add it to the repository secrets as
PYPI_API_TOKEN. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69102bebd89a7949baa3a15fdbe35099d76da0c41bc20687bd5d3b925aa64fe4
|
|
| MD5 |
93c95f44ea7542888e38a7cf1d58e88c
|
|
| BLAKE2b-256 |
ea602be79dab0929ed620160530df0e81d2904f47c2890f1ff8855ae3bdbc1ec
|
Provenance
The following attestation bundles were made for otel_file_exporter-0.1.1.tar.gz:
Publisher:
publish.yml on Brishen/otel_file_exporter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
otel_file_exporter-0.1.1.tar.gz -
Subject digest:
69102bebd89a7949baa3a15fdbe35099d76da0c41bc20687bd5d3b925aa64fe4 - Sigstore transparency entry: 361694271
- Sigstore integration time:
-
Permalink:
Brishen/otel_file_exporter@bdb59aad554a02558310b5f31f0f5662b275f6cf -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Brishen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bdb59aad554a02558310b5f31f0f5662b275f6cf -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file otel_file_exporter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: otel_file_exporter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a91abee915cfc9e28df7d9ec8af44e26dec768af9607ee76b5c19eb03d16479
|
|
| MD5 |
add77a9fdd315feeefaeb5f9d2471613
|
|
| BLAKE2b-256 |
0c6d869faaa5dc4ad8d3ea7c0a097700f7f7b5234aa2dfca8f0c22209c7b34b7
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
otel_file_exporter-0.1.1-py3-none-any.whl -
Subject digest:
1a91abee915cfc9e28df7d9ec8af44e26dec768af9607ee76b5c19eb03d16479 - Sigstore transparency entry: 361694288
- Sigstore integration time:
-
Permalink:
Brishen/otel_file_exporter@bdb59aad554a02558310b5f31f0f5662b275f6cf -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Brishen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bdb59aad554a02558310b5f31f0f5662b275f6cf -
Trigger Event:
workflow_dispatch
-
Statement type: