Skip to content

Add team_name tag to OpenLineage metrics#69109

Open
SameerMesiah97 wants to merge 3 commits into
apache:mainfrom
SameerMesiah97:68996-OpenLineage-Team-Name-Metrics
Open

Add team_name tag to OpenLineage metrics#69109
SameerMesiah97 wants to merge 3 commits into
apache:mainfrom
SameerMesiah97:68996-OpenLineage-Team-Name-Metrics

Conversation

@SameerMesiah97

@SameerMesiah97 SameerMesiah97 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Description

This change adds a team_name tag to OpenLineage metrics to improve observability in multi-team deployments.

The following metrics now include the team_name tag when available:

  • ol.emit.attempts
  • ol.emit.failed
  • ol.extract
  • ol.event.size

A new DagRunInfo.team_name() helper has been added to resolve the team associated with a DagRun from its DAG bundle.

For listener metrics (ol.extract and ol.event.size), the team_name is resolved directly from the DagRun. For adapter metrics (ol.emit.attempts and ol.emit.failed), the value is propagated through the Airflow run facet attached to the emitted OpenLineage event.

Rationale

The OpenLineage integration emits metrics for lineage extraction and event publication, but these metrics could not previously be attributed to individual teams in multi-team deployments.

Adding the team_name tag enables per-team dashboards, alerting, and troubleshooting while remaining backwards compatible for deployments that do not use multi-team scheduling.

Tests

Added unit tests for the new DagRunInfo.team_name() helper, including multi-team configuration handling.

Updated the existing OpenLineage listener and adapter unit tests to verify metric emission both with and without the team_name tag. Test cases covering the presence of team_name are skipped when running against Airflow versions earlier than 3.3.0.

Notes

A typographical error ('deg') in the docstring for dag_version_info has been corrected.

Backwards Compatibility

This change is additive only. Existing metric names remain unchanged, and the team_name tag is emitted only when running on Airflow 3.3+ with multi-team enabled. Existing dashboards and integrations that do not use the new tag continue to function unchanged.

Related: #68996

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [GPT 5.5] following the guidelines

@SameerMesiah97 SameerMesiah97 force-pushed the 68996-OpenLineage-Team-Name-Metrics branch 4 times, most recently from 588db94 to e3f59ba Compare June 29, 2026 20:21
@SameerMesiah97 SameerMesiah97 marked this pull request as ready for review June 29, 2026 22:28
"deadlines": lambda dagrun: DagRunInfo.deadlines(dagrun),
}

_team_name_cache: ClassVar[dict[str, str | None]] = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it fine that there is no TTL on this cached value? If a dag changes the bundle it wont be reflected as this cache never expires. The Core already caches this lookup here: DagModel.get_team_name(dag_id) uses a TTLCache.

This PR calls the uncached DagBundleModel.get_team_name(bundle_name) instead, so it had to add its own cache. I am not sure if they are interchangeable but something to think about.

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.

I think using a regular cache is acceptable for the following reasons:

  1. Bundles per team are expected to change very rarely and most certainly not during the DAG run.
  2. This is provider-layer code that runs in the worker in a short-lived process bounded by the lifetime of the task, so the cache will likely not remain stale for very long.
  3. Is it expected for OpenLineage events to pick up bundle-to-team relationships that change mid-flight? I don't believe so.

Also, if we were to switch to DagModel.get_team_name(dag_id), there would be a slight performance hit as we'd have to go through the DagModel table to get the DAG bundle, whereas with DagBundleModel.get_team_name(bundle_name), we can use the bundle name directly to fetch the team name.

But if you insist on a TTL cache, I think the best option would be to use DagModel.get_team_name(dag_id). However, I am not sure if it worth it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point about short lived processes as this code will run in the provider layer. I think we are good with keeping the cache.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need the cache in that case honestly? If we're counting on this only executing in a temporary fork where only one or two calls will be cached, is it providing that much value? Or just more surface for something to go wrong in other code paths/code reuse? I'd vote to simplify where we can.

@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 2, 2026
@SameerMesiah97

Copy link
Copy Markdown
Contributor Author

@ferruzzi

This is just a reminder for review.

Comment thread providers/openlineage/src/airflow/providers/openlineage/plugins/listener.py Outdated
Comment thread providers/openlineage/src/airflow/providers/openlineage/plugins/listener.py Outdated
Comment thread providers/openlineage/tests/unit/openlineage/utils/test_utils.py Outdated
@SameerMesiah97 SameerMesiah97 force-pushed the 68996-OpenLineage-Team-Name-Metrics branch from e3f59ba to 240ab79 Compare July 6, 2026 21:44
@SameerMesiah97 SameerMesiah97 requested a review from ferruzzi July 6, 2026 23:23
Sameer Mesiah added 3 commits July 8, 2026 21:02
when multi-team is enabled on Airflow 3.1+.

The team name is propagated through the Airflow run facet and included in
ol.emit.attempts, ol.emit.failed, ol.extract, and ol.event.size.
Tests are updated accordingly.
…nd reuse the existing team_name value when emitting metrics.
…ssociated unit tests by removing unnecessary database markers and simplifying the test cases.
@SameerMesiah97 SameerMesiah97 force-pushed the 68996-OpenLineage-Team-Name-Metrics branch from 240ab79 to 3de74a8 Compare July 8, 2026 20:03

@kacpermuda kacpermuda 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.

One small but important change needed.

team_name = None

facets = event.run.facets or {}
airflow_facet = cast("AirflowRunFacet | None", facets.get("airflow"))

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.

We need to fallback to "airflowDagRun" facet here, for DAG events. "airflow" is the facet name only used in task events. Let's also add a test for that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:openlineage AIP-53 ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants