Skip to content

feat(sync-service): populate num_bytes and subset_result span attributes#4143

Open
alco wants to merge 3 commits intomainfrom
sv1465-telemetry-columns
Open

feat(sync-service): populate num_bytes and subset_result span attributes#4143
alco wants to merge 3 commits intomainfrom
sv1465-telemetry-columns

Conversation

@alco
Copy link
Copy Markdown
Member

@alco alco commented Apr 21, 2026

Summary

  • Add num_bytes span attribute on the ServeShapePlug root span, mirroring the existing bytes telemetry measurement emitted alongside http.response_size.
  • Add electric.subqueries.subset_result.{bytes,rows,duration_µs} span attributes at the end of PartialModes.record_subset_metrics/4 so the subset-materialisation metrics become queryable Honeycomb columns.
  • chunk_size is already wired on the shape_get.plug.stream_chunk child span — no change required.
  • shape_snapshot.query.duration_µs landed in chore(sync-service): instrument snapshot query timing #4110 — no change required.

Refs electric-sql/stratovolt#1465.

Test plan

  • mix compile (sync-service)
  • mix test test/electric/plug/serve_shape_plug_test.exs — 38 passing
  • Verify in Honeycomb once deployed that the num_bytes and electric.subqueries.subset_result.* columns are populated for new spans.

Generated with Claude Code.

alco added 2 commits April 21, 2026 13:05
Expose previously-empty telemetry span attributes so the corresponding
Honeycomb columns can be queried:

- `num_bytes` on the ServeShapePlug root span, mirroring the existing
  `bytes` telemetry measurement emitted alongside `http.response_size`.
- `electric.subqueries.subset_result.{bytes,rows,duration_µs}` on the
  subset materialisation path in `PartialModes.record_subset_metrics/4`.

`chunk_size` is already emitted as a span attribute on the
`shape_get.plug.stream_chunk` child span; no change required.
`shape_snapshot.query.duration_µs` landed in #4110.

Refs electric-sql/stratovolt#1465
@alco alco added the claude label Apr 21, 2026
@claude
Copy link
Copy Markdown

claude Bot commented Apr 21, 2026

Claude Code Review

Summary

This PR adds two previously-missing OpenTelemetry span attributes: num_bytes on the root ServeShapePlug span, and electric.subqueries.subset_result.{bytes,rows,duration_µs} on the span active during subset materialisation. The changes are small, additive, and technically correct.

What's Working Well

  • Clean variable extraction: Extracting bytes_sent and duration into named variables avoids double-evaluating the expressions — a nice refactor bundled into the change.
  • Correct API usage: OpenTelemetry.add_span_attributes/1 (no span context arg) correctly uses the current process span context, which is active in both call sites.
  • Purely additive: Existing :telemetry.execute / OpenTelemetry.execute calls are untouched — no regression risk for downstream telemetry subscribers.
  • Changeset present: @core/sync-service: patch is correctly formatted and matches the repo conventions.

Issues Found

Suggestions (Nice to Have)

1. Inaccurate comment in partial_modes.ex:83

File: packages/sync-service/lib/electric/shapes/partial_modes.ex:83–85

The comment says the attributes are added "on the enclosing shape request span", but at the point Enum.to_list() materialises the stream (and therefore when the Stream.transform finalizer runs), the active process span context is shape_snapshot.query_fn — a child span of shape_snapshot.execute_for_shape, itself a child of the root shape-get span. The attributes land on shape_snapshot.query_fn, not the root span.

This is arguably the right place for them (the metrics are about the query execution), but the comment will mislead anyone debugging why the values don't appear on the root span. Suggested fix:

# Expose subset materialisation metrics as span attributes on the
# shape_snapshot.query_fn child span so they become queryable
# Honeycomb columns. Mirrors the telemetry event measurements above.

2. No automated verification of the new attributes

The test plan defers verification to a live Honeycomb deployment. The existing serve_shape_plug_test.exs (38 tests) already exercises the streaming path, so adding an assertion that num_bytes is set on the span would give future regressions a fast feedback loop. This is low-priority given that the changes are observability-only and the risk of regression is low, but it would be a nice addition.

Issue Conformance

The PR references electric-sql/stratovolt#1465 (a private repo), so the linked issue isn't externally visible. The PR description and task files in .agent-tasks/ provide sufficient context: four Honeycomb columns were identified as unpopulated, and this PR fixes two of them (confirming chunk_size and shape_snapshot.query.duration_µs were already wired correctly). No scope concerns.


Review iteration: 1 | 2026-04-21

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.20%. Comparing base (365dd17) to head (4e75fdc).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4143   +/-   ##
=======================================
  Coverage   89.20%   89.20%           
=======================================
  Files          25       25           
  Lines        2520     2520           
  Branches      636      639    +3     
=======================================
  Hits         2248     2248           
  Misses        270      270           
  Partials        2        2           
Flag Coverage Δ
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/typescript-client 94.30% <ø> (ø)
packages/y-electric 56.05% <ø> (ø)
typescript 89.20% <ø> (ø)
unit-tests 89.20% <ø> (ø)

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.

- Clarify that the span attributes added in PartialModes.record_subset_metrics/4
  land on the active shape_snapshot.query_fn child span (not the enclosing
  shape request span), addressing review feedback on PR #4143.
- Stop tracking .agent-tasks/ in Git and add it to .gitignore.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant