Skip to content

feat(tracing): respect otel service name via env variable#3231

Merged
saikonen merged 5 commits into
Netflix:masterfrom
vivekkhimani:vivek/otel-service-name
Jun 22, 2026
Merged

feat(tracing): respect otel service name via env variable#3231
saikonen merged 5 commits into
Netflix:masterfrom
vivekkhimani:vivek/otel-service-name

Conversation

@vivekkhimani

@vivekkhimani vivekkhimani commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

PR Type

  • Bug fix
  • New feature
  • Core Runtime change (higher bar -- see CONTRIBUTING.md)
  • Docs / tooling
  • Refactoring

Summary

Make Metaflow's OpenTelemetry service.name configurable via a new METAFLOW_OTEL_SERVICE_NAME config instead of hardcoding "metaflow". The default is unchanged ("metaflow"), so this is fully backward compatible.

Issue

Fixes #3228

Reproduction

  • Added a new OTEL_SERVICE_NAME config in metaflow_config.py.

  • tracing_modules.py now reads OTEL_SERVICE_NAME instead of the hardcoded "metaflow" string when building the OTel Resource.

  • The resolved value is propagated to remote tasks as METAFLOW_OTEL_SERVICE_NAME in batch.py and kubernetes.py (the K8s job and jobset paths), wherever METAFLOW_OTEL_ENDPOINT is already forwarded, so remote spans carry the same service name as the client. Argo Workflows and Step Functions are intentionally skipped, as tracing config is not wired through those orchestrators today (would be a larger follow-up).

  • Resolution:

    1. METAFLOW_OTEL_SERVICE_NAME if set
    2. "metaflow" otherwise (unchanged default)

    Per review discussion, auto-inheriting the bare OTEL_SERVICE_NAME env var was intentionally dropped to avoid silently relabeling spans for users who already set OTEL_SERVICE_NAME process-wide but rely on "metaflow" in their dashboards/alerts. To inherit a surrounding application's service name, set METAFLOW_OTEL_SERVICE_NAME=$OTEL_SERVICE_NAME in the runtime environment.

Tests

  • Unit tests added/updated
  • Reproduction script provided (required for Core Runtime)
  • CI passes
  • If tests are impractical: explain why below and provide manual evidence above

AI Tool Usage

  • No AI tools were used in this contribution
  • AI tools were used (describe below)

@greptile-apps

greptile-apps Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes Metaflow's OpenTelemetry service.name configurable via a new OTEL_SERVICE_NAME config entry, replacing the hardcoded "metaflow" string, and propagates the resolved value to AWS Batch and Kubernetes remote environments.

  • Core change: tracing_modules.py now reads OTEL_SERVICE_NAME from metaflow_config instead of using a literal string; Batch and Kubernetes both forward the value as METAFLOW_OTEL_SERVICE_NAME.
  • Gap between description and implementation: from_conf("OTEL_SERVICE_NAME", "metaflow") only checks METAFLOW_OTEL_SERVICE_NAME in the environment — the standard OTEL_SERVICE_NAME OTel env var (listed as step 2 in the documented precedence) is never read, and the tests confirm this by asserting that setting OTEL_SERVICE_NAME="from-otel" still returns "metaflow".

Confidence Score: 4/5

Safe to merge as a partial improvement — the METAFLOW_OTEL_SERVICE_NAME override works correctly — but the standard OTEL_SERVICE_NAME env var advertised in the PR description is silently ignored.

The config lookup uses from_conf("OTEL_SERVICE_NAME", "metaflow"), which internally looks for METAFLOW_OTEL_SERVICE_NAME. The bare OTEL_SERVICE_NAME key — documented as step 2 of the resolution order — is never consulted, so any application that already sets OTEL_SERVICE_NAME to identify itself will not see that value picked up by Metaflow spans. The tests explicitly verify this no-op behavior, confirming it is a real gap rather than a test oversight.

metaflow/metaflow_config.py — the from_conf call needs to check os.environ.get("OTEL_SERVICE_NAME") as the default before falling back to "metaflow".

Important Files Changed

Filename Overview
metaflow/metaflow_config.py Adds OTEL_SERVICE_NAME config via from_conf, which only reads METAFLOW_OTEL_SERVICE_NAME — the standard OTEL_SERVICE_NAME env var (documented step 2 of the precedence) is never checked.
metaflow/tracing/tracing_modules.py Replaces hardcoded "metaflow" with OTEL_SERVICE_NAME from config; straightforward change with no logic issues in this file.
metaflow/plugins/aws/batch/batch.py Forwards the resolved OTEL_SERVICE_NAME as METAFLOW_OTEL_SERVICE_NAME to the remote Batch environment; correct propagation pattern consistent with OTEL_ENDPOINT.
metaflow/plugins/kubernetes/kubernetes.py Adds METAFLOW_OTEL_SERVICE_NAME to both Kubernetes execution paths; mirrors the Batch pattern correctly.
test/unit/test_otel_service_name.py New unit tests cover default, METAFLOW_OTEL_SERVICE_NAME override, and bare OTEL_SERVICE_NAME; the OTEL_SERVICE_NAME case asserts "metaflow" (no-op), contradicting the documented precedence.

Reviews (5): Last reviewed commit: "Merge branch 'master' into vivek/otel-se..." | Re-trigger Greptile

Comment thread test/unit/test_otel_service_name.py Outdated
Comment thread metaflow/metaflow_config.py Outdated
# Opt-in to inheriting the standard OTEL_SERVICE_NAME env var of the surrounding
# application. Off by default so upgrades never silently relabel spans for users
# who already have OTEL_SERVICE_NAME set process-wide.
OTEL_INHERIT_SERVICE_NAME = from_conf("OTEL_INHERIT_SERVICE_NAME", False)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@talsperre -- this is the main area of contention that I'd love your thoughts on! The simpler/cleaner thing here IMO is to just start respecting the OTEL_SERVICE_NAME env var but as Ian rightly pointed out in his issue, that might cause a "breaking change" for existing consumers who might have this variable set in their env but have their o11y/dashboards listening on metaflow. We are in fact, currently relying on metaflow as our service name.

The current approach, explicitly gives them a flag to override the existing behavior and start respecting OTEL_SERVICE_NAME. What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been mulling over this for a bit now, and I'm wondering whether the env-fallback is a common use case or not. Would love some more insight on peoples use-cases.

The main concern I have here is adding possibly unnecessary/unused options to the Metaflow config. I think we could do without the flag for otel-inheritance as

  1. If a user/org wants to use an already configured OTEL_SERVICE_NAME in their environment, then they still need to add a new entry to their Metaflow profile to enable this. The edit could just as well be to change the service name through the config at that point.

  2. If the org wants the ability to set/swap service names as part of their infra instead of Metaflow profiles, and they are managing environment variables separately, then this should only require an additional METAFLOW_OTEL_SERVICE_NAME=$OTEL_SERVICE_NAME to the runtime environments in order to override the defaults.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be addressed in c8683d9!

Comment thread metaflow/tracing/tracing_modules.py
@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@5cdcc70). Learn more about missing BASE report.

Files with missing lines Patch % Lines
metaflow/tracing/tracing_modules.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3231   +/-   ##
=========================================
  Coverage          ?   29.88%           
=========================================
  Files             ?      381           
  Lines             ?    52553           
  Branches          ?     9273           
=========================================
  Hits              ?    15704           
  Misses            ?    35673           
  Partials          ?     1176           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread metaflow/metaflow_config.py
@vivekkhimani
vivekkhimani requested a review from saikonen June 18, 2026 21:49

@talsperre talsperre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I reviewed the config resolution, tracer resource wiring, Batch/Kubernetes propagation, and focused unit coverage. The opt-in METAFLOW_OTEL_SERVICE_NAME behavior matches the latest discussion and preserves the default service.name.

@saikonen
saikonen merged commit 332fbb6 into Netflix:master Jun 22, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hardcoded OTel service.name prevents runtime service name detection

3 participants