feat(logs): Add Hint to beforeSend for logs, metrics, and spans#3847
feat(logs): Add Hint to beforeSend for logs, metrics, and spans#3847buenaflor wants to merge 1 commit into
Conversation
beforeSendLog, beforeSendMetric, and beforeSendSpan now receive a Hint as their second argument, matching beforeSend and beforeSendTransaction. Each capture pipeline creates one Hint and threads that same instance through the OnProcessLog/Metric/Span lifecycle event and into the callback, so SDK-side lifecycle callbacks can enrich the hint before beforeSend reads it. Public capture APIs are unchanged. Also migrate the metric pipeline's callback-error log from the deprecated options.log to internalLogger. BREAKING CHANGE: user-defined beforeSendLog/beforeSendMetric/ beforeSendSpan callbacks must add the Hint parameter. Fixes GH-3836 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Features
Fixes
DependenciesDeps
Internal Changes
🤖 This preview updates automatically when you update the PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v10-branch #3847 +/- ##
=============================================
Coverage ? 87.30%
=============================================
Files ? 337
Lines ? 12260
Branches ? 0
=============================================
Hits ? 10704
Misses ? 1556
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Pull request overview
This PR updates the Sentry Dart/Flutter telemetry pipelines so beforeSendLog, beforeSendMetric, and beforeSendSpan receive a Hint (as their second parameter), matching the beforeSend / beforeSendTransaction pattern and enabling lifecycle callbacks to enrich the hint before user callbacks run.
Changes:
- Add
Hintto theBeforeSendLogCallback,BeforeSendMetricCallback, andBeforeSendSpanCallbacktypedefs. - Thread a single
Hintinstance through each capture pipeline:OnProcess*lifecycle event →beforeSend*callback; add tests asserting the same instance is observed. - Update metric callback error logging to use
internalLoggerinstead of the deprecatedoptions.log.
Standards
- 1 finding:
BeforeSendMetricCallbackdoc comment contradicts the actual return type/behavior (it describestrue/false, but the callback returnsSentryMetric?, wherenulldrops the metric).
Spec
- 0 findings: matches the issue/PR description (adds
Hintparam, constructs/passesHintin pipelines, adds regression tests for “same instance” threading, updates call sites).
Correctness
- 0 findings: updated call sites appear consistent;
internalLogger.error(..., error: ..., stackTrace: ...)matches the logger API; tests cover the new hint-threading invariant.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/dart/lib/src/sentry_options.dart | Update beforeSend* callback typedefs to include Hint (public API change). |
| packages/dart/lib/src/sdk_lifecycle_hooks.dart | Add Hint to OnProcessLog / OnProcessMetric / OnProcessSpan lifecycle events. |
| packages/dart/lib/src/telemetry/log/log_capture_pipeline.dart | Create one Hint per log capture and pass it through lifecycle + beforeSendLog. |
| packages/dart/lib/src/telemetry/metric/metric_capture_pipeline.dart | Create one Hint per metric capture, pass it through lifecycle + beforeSendMetric, and log callback errors via internalLogger. |
| packages/dart/lib/src/telemetry/span/span_capture_pipeline.dart | Create one Hint per span capture and pass it through lifecycle + beforeSendSpan. |
| packages/dart/test/telemetry/log/log_capture_pipeline_test.dart | Update callback signatures and add test asserting lifecycle/callback see the same Hint instance. |
| packages/dart/test/telemetry/metric/metric_capture_pipeline_test.dart | Update callback signatures and add test asserting lifecycle/callback see the same Hint instance. |
| packages/dart/test/telemetry/span/span_capture_pipeline_test.dart | Update callback signatures and add test asserting lifecycle/callback see the same Hint instance. |
| packages/dart/test/track_before_send_usage_integration_test.dart | Update callback signatures used for feature tracking. |
| packages/dart/test/event_processor/enricher/enricher_integration_test.dart | Update lifecycle dispatch call sites to pass Hint(). |
| packages/flutter/test/integrations/replay_telemetry_integration_test.dart | Update lifecycle dispatch call sites to pass Hint(). |
| packages/flutter/test/integrations/load_contexts_integration_test.dart | Update lifecycle dispatch call sites to pass Hint(). |
| packages/flutter/example/lib/main.dart | Update example beforeSendMetric / beforeSendSpan callback signatures to include Hint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// This function is called right before a metric is about to be emitted. | ||
| /// Can return true to emit the metric, or false to drop it. |
beforeSendLog,beforeSendMetric, andbeforeSendSpannow receive aHintas their second argument, matchingbeforeSendandbeforeSendTransaction. This is a breaking change: user-defined callbacks must add the parameter.Each capture pipeline creates a single
Hintand threads that same instance through theOnProcessLog/OnProcessMetric/OnProcessSpanlifecycle event and then into the callback. That's the mechanism that makes the hint useful: an SDK-side lifecycle callback can enrich the hint beforebeforeSend*reads it, since both hold the same instance.Scope notes for reviewers:
captureLog/captureMetric/captureSpanonHub/Client) are intentionally unchanged — nobody emits through them directly, so ahintparameter there would have no caller. The hint is created in the pipeline.Sentry.logger.info(hint:), or a hint carried on a live span) is deliberately deferred. It's a non-breaking addition and there's no populator today; the breaking signature change is what has to land in v10.options.logtointernalLogger.Each pipeline gains a test asserting the callback receives the same
Hintinstance dispatched to itsOnProcess*event, so the threading can't silently regress.Fixes #3836