Skip to content

Emit OpenTelemetry spans around listener hook calls#67347

Draft
dstandish wants to merge 1 commit into
apache:mainfrom
astronomer:push-listener-span-down
Draft

Emit OpenTelemetry spans around listener hook calls#67347
dstandish wants to merge 1 commit into
apache:mainfrom
astronomer:push-listener-span-down

Conversation

@dstandish
Copy link
Copy Markdown
Contributor

Pushes span creation down into ListenerManager so every pluggy hook call automatically gets a listener.<hook_name> span (gated on task span detail level > 1). Callers no longer need to wrap individual lm.hook.foo(...) invocations.

Done via pluggy's add_hookcall_monitoring before/after pair, paired with a per-thread span stack so concurrent and nested calls stay isolated.

Also fixes a latent bug in the existing _after_hookcall: it called outcome.get_result() unconditionally, which re-raises on listener exceptions and would have skipped span teardown. It now checks outcome.excinfo first and records the exception on the span before exiting the context.

The detail-level threshold constants are inlined (with a comment) rather than imported from airflow_shared.observability.traces, to avoid adding a cross-shared-library dependency that destabilised the deps-propagation prek hook.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.7)

Generated-by: Claude Code (Opus 4.7) following the guidelines

Push span creation down into ListenerManager via pluggy's
add_hookcall_monitoring so every hook call gets a
`listener.<hook_name>` span automatically, gated on task span detail
level > 1. Callers no longer need to wrap individual hook invocations.

Also makes the existing _after_hookcall safe against listener
exceptions: previously `outcome.get_result()` was called
unconditionally and would re-raise, skipping the rest of the callback.
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.

1 participant