Skip to content

fix(sync): wire metrics handler into expand ProgressLog#862

Open
arreyder wants to merge 2 commits into
mainfrom
arreyder/wire-expand-metrics-handler
Open

fix(sync): wire metrics handler into expand ProgressLog#862
arreyder wants to merge 2 commits into
mainfrom
arreyder/wire-expand-metrics-handler

Conversation

@arreyder
Copy link
Copy Markdown
Contributor

@arreyder arreyder commented May 23, 2026

Summary

  • progresslog.NewProgressCounts is constructed in pkg/sync/syncer.go:2849 without WithMetricsHandler, so the four expand OTel instruments added in feat(sync): emit OTel metrics for grant-expansion progress (CE-702) #804 (baton.sync.expand.actions_remaining, .actions_burned, .decompressed_bytes, .decompressed_bytes_delta) emit to the default no-op handler and never reach an exporter. Structured "Expanding grants" logs still fire; only the metric path is dead.
  • Add a WithMetricsHandler SyncOpt so callers can inject a pre-tagged metrics.Handler, and forward it into progressLogOpts before NewProgressCounts.
  • Per the existing doc on progresslog.WithMetricsHandler (pkg/sync/progresslog/progresslog.go:144-158), the caller owns tagging (tenant_id / connector_id); baton-sdk does not see those identifiers, so this PR pipes the handler through without decoration.

Why this matters

During long grant expansions, operators currently have to scrape log timestamps to answer "is this connector burning through actions or wedged?" — the same workflow #804 was meant to obsolete. Once consumers (e.g. the main platform repo) pass their existing sync-scoped handler via sync.WithMetricsHandler(h), the gauges/counters land in Datadog and dashboards/alerts become possible.

Test plan

  • go build ./...
  • go test ./pkg/sync/...
  • golangci-lint run ./pkg/sync/... — no new findings (the 3 pre-existing issues in pkg/sync/expand are untouched by this diff)
  • Consumer side: pass a pre-tagged handler from the main platform repo and confirm baton.sync.expand.actions_remaining shows up in Datadog during a grant-expansion step on a connector with grants

NewProgressCounts is constructed without progresslog.WithMetricsHandler,
so the four expand instruments — baton.sync.expand.actions_remaining,
.actions_burned, .decompressed_bytes, .decompressed_bytes_delta — were
emitted into the default no-op handler and never reached an exporter.
The structured "Expanding grants" logs still fired, but the OTel path
introduced in #804 was dead from the consumer's perspective.

Add a WithMetricsHandler SyncOpt that forwards the caller's pre-tagged
handler into the ProgressLog, and apply it in NewSyncer. Per the
WithMetricsHandler doc on progresslog.go:149-151, the caller owns the
tagging (tenant_id / connector_id) — baton-sdk has no view of those.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@arreyder arreyder requested a review from a team May 23, 2026 01:25
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

General PR Review: fix(sync): wire metrics handler into expand ProgressLog

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Review mode: incremental since dd16481
View review run

Review Summary

The new commits add a nil guard to WithMetricsHandler, fix a doc comment (decompressed_bytes_growthdecompressed_bytes_delta), and add two well-structured tests in syncer_metrics_test.go that cover both the handler-wired and no-handler paths. The previous suggestion requesting test coverage for WithMetricsHandler is now fully addressed. No new issues found.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

No blocking issues found.

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 23, 2026

OPS-1721

… doc

From code review of the previous commit:

1. Add a syncer-level test that constructs a syncer with WithMetricsHandler
   and asserts the caller's handler receives the actions_remaining gauge.
   Without it, dropping the conditional append in NewSyncer would silently
   disable every consumer's baton.sync.expand.* metrics — log assertions
   in existing tests would still pass.

2. Guard nil in the WithMetricsHandler SyncOpt closure to match sibling
   options (WithTransitionHandler, WithProgressHandler) and the wrapped
   progresslog.WithMetricsHandler. Prevents a stray WithMetricsHandler(nil)
   later in the options list from clobbering a previously-set handler.

3. Fix a stale instrument name in the WithMetricsHandler doc on the
   progresslog side: decompressed_bytes_growth → decompressed_bytes_delta
   (matches the actual constant at progresslog.go:31).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

No blocking issues found.

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