Skip to content

Fix otel context propagation in a few more places missed previsouly#4274

Merged
alco merged 5 commits intomainfrom
fix-otel-context-effects-move-in
May 6, 2026
Merged

Fix otel context propagation in a few more places missed previsouly#4274
alco merged 5 commits intomainfrom
fix-otel-context-effects-move-in

Conversation

@alco
Copy link
Copy Markdown
Member

@alco alco commented May 5, 2026

Summary

Follow-up to #4149 which fixed OTel context propagation in three spawn sites. While auditing the rest of the codebase, three additional places were found where with_child_span calls were silently dropping spans due to missing parent context.

1. Effects.query_move_in_async/4 (spawned task)

The same pattern as the sites fixed in #4149: a Task.Supervisor.start_child call wrapping SnapshotQuery.execute_for_shape, but without propagating the OTel context into the spawned task. Fixed by capturing the context before the spawn and attaching it inside the task closure.

2. ShapeCache.handle_call({:create_or_wait_shape_handle, shape, otel_ctx})

The otel_ctx was already being passed in the GenServer call message (from Electric.Shapes.get_or_create_shape_handle/3), but the handler was only forwarding it to the Snapshotter — it never set the context on the ShapeCache GenServer process itself. As a result, the with_child_span calls inside ShapeStatus.fetch_handle_by_shape_critical and ShapeStatus.add_shape were silently dropped.

3. ShapeCache.handle_call({:start_consumer_for_handle, ...})

This handler had a # TODO: otel ctx from shape log collector? comment acknowledging the gap. The caller, ConsumerRegistry.start_consumer!/2, wraps the GenServer call in OpenTelemetry.with_span(...) but the context wasn't crossing the GenServer call boundary. The public function signature was changed to take an opts keyword list (matching get_or_create_shape_handle/3), with ConsumerRegistry capturing the current context inside its span and passing it through.

Test plan

  • mix compile clean
  • mix test test/electric/telemetry/open_telemetry_test.exs — 8 passing
  • After deploy: verify name = shape_status.add_shape and name = shape_status.fetch_handle_by_shape_critical rows show up in Honeycomb under shape-creation traces (previously dropped).

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.06%. Comparing base (093449a) to head (2d990f2).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4274   +/-   ##
=======================================
  Coverage   63.06%   63.06%           
=======================================
  Files         184      184           
  Lines       19932    19932           
  Branches     4955     4959    +4     
=======================================
  Hits        12571    12571           
  Misses       7358     7358           
  Partials        3        3           
Flag Coverage Δ
packages/agents 61.19% <ø> (ø)
packages/agents-runtime 79.23% <ø> (ø)
packages/agents-server 66.03% <ø> (ø)
packages/agents-server-ui 1.64% <ø> (ø)
packages/electric-ax 38.59% <ø> (ø)
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/typescript-client 94.27% <ø> (ø)
packages/y-electric 56.05% <ø> (ø)
typescript 63.06% <ø> (ø)
unit-tests 63.06% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@robacourt robacourt left a comment

Choose a reason for hiding this comment

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

Nice!

alco and others added 5 commits May 6, 2026 13:01
This is a follow-up to #4149 which fixed OTel context propagation in
PartialModes and Snapshotter. The Effects.query_move_in_async function
has the same pattern: it spawns a task that calls
SnapshotQuery.execute_for_shape, but without OTel context propagation
the child spans inside would be silently dropped.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Two handlers receive calls that should have OTel context but weren't
setting it before calling ShapeStatus functions that use with_child_span:

1. handle_call({:create_or_wait_shape_handle, shape, otel_ctx}) - the
   otel_ctx was passed to opts but not set in the process context before
   calling ShapeStatus.fetch_handle_by_shape_critical and add_shape.

2. handle_call({:start_consumer_for_handle, ...}) - previously had a
   TODO comment acknowledging the missing context. Now accepts an opts
   keyword list (matching get_or_create_shape_handle/3) and ConsumerRegistry
   passes the context from within its span.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The OTel context propagation change added an opts argument to
ShapeCache.start_consumer_for_handle. Update Repatch stubs in the
ConsumerRegistry and ShapeLogCollector tests to accept the new arity.
Move @default_config inside the with_telemetry Sentry.LoggerHandler do
branch so it is only defined when actually referenced. Fixes the
"module attribute @default_config was set but never used" warning
introduced by #4146 (4176bd2), where the attribute lives at the
module top level but is only used inside the do branch — the else
branch (compiled when Sentry.LoggerHandler is unavailable) never
references it.
@alco alco force-pushed the fix-otel-context-effects-move-in branch from e6fb6fa to 2d990f2 Compare May 6, 2026 12:11
@alco alco merged commit 686ebdb into main May 6, 2026
68 of 69 checks passed
@alco alco deleted the fix-otel-context-effects-move-in branch May 6, 2026 12:24
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.

2 participants