Skip to main content

Ships Metaflow task logs to a centralized backend via OpenTelemetry

Project description

metaflow-logs

CI PyPI Python License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metaflow_logs-0.1.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metaflow_logs-0.1.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

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

Hashes for metaflow_logs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 36ecad4148c7b361bf7bc03f42e09ab869e7085112c5edb4b1a6614e14fe0e46
MD5 32e044be21835d737cd219f0f7a35900
BLAKE2b-256 10274b386ff5abb0c0bed31685cf25e709b132edd9467240bf8c546cb49b93c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_logs-0.1.0.tar.gz:

Publisher: publish.yml on npow/metaflow-logs

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

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

Hashes for metaflow_logs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e726d1ff33530a926dc5af4a1ceab2504dd1b1e0966a9f367bfb7758d37abe72
MD5 ba79ca36be70880bf9c7f60e9bbde6d8
BLAKE2b-256 a163e137ede3e32d3dd9102a6cf049bb0cde7094dc571094d820f77059598940

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_logs-0.1.0-py3-none-any.whl:

Publisher: publish.yml on npow/metaflow-logs

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