Ships Metaflow task logs to a centralized backend via OpenTelemetry
Project description
metaflow-logs
A Metaflow extension that ships task stdout and stderr to any OpenTelemetry-compatible backend (Grafana Loki, Datadog, New Relic, Elasticsearch, Honeycomb, …). Each log line is tagged with full task context — flow name, run ID, step name, task ID, attempt — making logs filterable and correlatable from any OTel-aware tool.
Quick start
pip install metaflow-logs
Add the decorator to any step:
from metaflow import FlowSpec, step
from metaflow_extensions.logs.plugins.decorator import LogsDecorator
class MyFlow(FlowSpec):
@LogsDecorator()
@step
def train(self):
print("epoch 1 complete")
self.next(self.end)
@step
def end(self):
pass
if __name__ == "__main__":
MyFlow()
Point it at your OTel collector:
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
python flow.py run
Each log line arrives in your backend tagged with:
| Attribute | Example |
|---|---|
metaflow.flow |
MyFlow |
metaflow.run_id |
123 |
metaflow.step |
train |
metaflow.task_id |
456 |
metaflow.attempt |
0 |
metaflow.log_source |
task or runtime |
Configuration
All configuration is via standard OTel environment variables:
| Variable | Default | Purpose |
|---|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT |
http://localhost:4318 |
OTel collector endpoint |
OTEL_EXPORTER_OTLP_HEADERS |
— | Auth headers (e.g. Authorization=Bearer ...) |
OTEL_SERVICE_NAME |
metaflow |
Service name in your backend |
Falls back to a console exporter if opentelemetry-exporter-otlp-proto-http is not installed.
How it works
Reads Metaflow's structured MFLOG files (MFLOG_STDOUT, MFLOG_STDERR) at step completion and emits each line as an OTel LogRecord. Runtime logs (Metaflow internals) are emitted at DEBUG severity; task logs (your code's stdout/stderr) at INFO.
Development
git clone https://github.com/npow/metaflow-logs
cd metaflow-logs
pip install -e .
pytest tests/ -v
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 metaflow_logs-0.1.0.tar.gz.
File metadata
- Download URL: metaflow_logs-0.1.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36ecad4148c7b361bf7bc03f42e09ab869e7085112c5edb4b1a6614e14fe0e46
|
|
| MD5 |
32e044be21835d737cd219f0f7a35900
|
|
| BLAKE2b-256 |
10274b386ff5abb0c0bed31685cf25e709b132edd9467240bf8c546cb49b93c3
|
Provenance
The following attestation bundles were made for metaflow_logs-0.1.0.tar.gz:
Publisher:
publish.yml on npow/metaflow-logs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metaflow_logs-0.1.0.tar.gz -
Subject digest:
36ecad4148c7b361bf7bc03f42e09ab869e7085112c5edb4b1a6614e14fe0e46 - Sigstore transparency entry: 1153961485
- Sigstore integration time:
-
Permalink:
npow/metaflow-logs@11f320c4c96d02b5424c2eb1113d215e2072a546 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/npow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@11f320c4c96d02b5424c2eb1113d215e2072a546 -
Trigger Event:
release
-
Statement type:
File details
Details for the file metaflow_logs-0.1.0-py3-none-any.whl.
File metadata
- Download URL: metaflow_logs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e726d1ff33530a926dc5af4a1ceab2504dd1b1e0966a9f367bfb7758d37abe72
|
|
| MD5 |
ba79ca36be70880bf9c7f60e9bbde6d8
|
|
| BLAKE2b-256 |
a163e137ede3e32d3dd9102a6cf049bb0cde7094dc571094d820f77059598940
|
Provenance
The following attestation bundles were made for metaflow_logs-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on npow/metaflow-logs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metaflow_logs-0.1.0-py3-none-any.whl -
Subject digest:
e726d1ff33530a926dc5af4a1ceab2504dd1b1e0966a9f367bfb7758d37abe72 - Sigstore transparency entry: 1153961486
- Sigstore integration time:
-
Permalink:
npow/metaflow-logs@11f320c4c96d02b5424c2eb1113d215e2072a546 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/npow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@11f320c4c96d02b5424c2eb1113d215e2072a546 -
Trigger Event:
release
-
Statement type: