feat: add IHub.RecordTransaction to record completed transactions and spans#5333
Open
jamescrosswell wants to merge 5 commits into
Open
feat: add IHub.RecordTransaction to record completed transactions and spans#5333jamescrosswell wants to merge 5 commits into
jamescrosswell wants to merge 5 commits into
Conversation
… spans Adds an opt-in API for recording transactions/spans whose timing was measured elsewhere (e.g. work done on another machine and replayed through a proxy), addressing #2683. Rather than exposing mutable start/end setters on ISpan (which invites half-specified timing and pollutes the live-tracing contract), this adds a builder-style recorder: hub.RecordTransaction(name, op, start, duration, configure: tx => { tx.RecordSpan(childOp, childStart, childDuration, configure: c => ...); }); Design notes: - Timing is supplied up-front (start + duration), so a recorded span can never be left half-specified and duration can't be negative. - Origin trace/span/parent ids can be preserved for trace stitching. - The whole tree is materialized and captured once when the callback returns. No stopwatch, idle timer, or sampling roll is involved. - Captured against a clean scope so the current process's live scope (breadcrumbs/user/tags/contexts) doesn't leak onto work that happened elsewhere. Public surface is intentionally minimal: RecordTransaction is an extension method on IHub, so IHub/ISpan/ITransaction are unchanged (no breaking interface changes). New public types: ISpanRecorder, ITransactionRecorder. Closes #2683 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5333 +/- ##
==========================================
+ Coverage 74.15% 74.21% +0.06%
==========================================
Files 508 509 +1
Lines 18353 18412 +59
Branches 3586 3595 +9
==========================================
+ Hits 13610 13665 +55
- Misses 3870 3875 +5
+ Partials 873 872 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jamescrosswell
commented
Jul 1, 2026
jamescrosswell
commented
Jul 1, 2026
jamescrosswell
commented
Jul 1, 2026
…cade, configurable scope - Move RecordTransaction into HubExtensions.cs (drop the separate file). - Add SentrySdk.RecordTransaction facade so callers without an IHub instance can use it. - Expose the fresh capture scope via ITransactionRecorder.ConfigureScope, so data captured alongside the original trace (user/tags/contexts) can be set without inheriting the current live scope. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…n' into feat/2683-record-transaction-span # Conflicts: # src/Sentry/ISpanRecorder.cs
jamescrosswell
commented
Jul 1, 2026
jamescrosswell
commented
Jul 1, 2026
Replace the static SpanRecorderInternals helper with an abstract SpanRecorderBase that holds the owning TransactionTracer and the node (as ISpan), proxying metadata through to it. SpanRecorder becomes a one-line subclass and the duplicated Description/Status/SetTag/SetData proxying is written once. Internal-only; public API unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jamescrosswell
commented
Jul 1, 2026
| /// <summary> | ||
| /// <see cref="ISpanRecorder"/> backed by a <see cref="SpanTracer"/> whose timing has been set explicitly. | ||
| /// </summary> | ||
| internal sealed class SpanRecorder : SpanRecorderBase |
Collaborator
Author
There was a problem hiding this comment.
Note: Arguably we don't need SpanRecorderBase (TransactionRecorder could descend from `SpanRecorder and we just fold all the stuff from the Base class into here). That would give us one less class.
Probably the main reason to do this is so that we can add the sealed keyword to SpanRecorder. Since the cost of doing this is minimal, I've left the base class in for the time being (unless anyone has really strong opinions about this).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Draft to spitball the shape of an API for recording transactions/spans that completed elsewhere — e.g. work measured on another machine or process and replayed through a proxy, which is the use case in #2683.
Closes #2683
Approach
The obvious option is public start/end setters on
ISpan. We discussed a few reasons not to:StartTimestampsetter that doesn't reset the stopwatch baseline lets you produce a span that starts in the past but ends "now" (inflated duration). The start/end pair has an invariant a lone setter can't enforce.ISpan(the most-implemented interface) with mutation that only makes sense for replayed data.Instead this adds a builder-style recorder:
Why this shape
start+duration), so a recorded span can't be half-specified and duration can't be negative — the original footgun is structurally unreachable rather than merely diagnosed.ISpanRecorder.RecordSpan), so a whole tree can be built with plain recursion. Parent is structural; onlyspanIdis overridable per node.traceId/spanId/parentSpanIdcan be preserved.Public surface
Intentionally minimal —
RecordTransactionis an extension method onIHub, soIHub/ISpan/ITransactionare all unchanged (no breaking interface changes needed to ship). New public types:ISpanRecorder,ITransactionRecorder. Internally it reuses the existingTransactionTracer/SpanTracer→SentryTransactionconversion path, so there are no changes to serialization.Open questions for reviewers
durationvsend: went withstart+durationso the value can't express a reversed pair. Alternative is a requiredend(matches the wire protocol and the origin data, which usually carries start+end). Easy to offer both.IHub. Worth mirroring on theSentrySdkstatic facade?Scope(options). Do we want any current-scope data (release/environment/dist) to flow through, or keep it fully isolated and rely on theRelease/Environmentsetters?BeforeSendTransactionstill runs (last-chance scrubbing); only the sampling roll is skipped. Confirm that's the desired split.Tests
HubExtensionsRecordTestscovers name/operation/timing, id preservation, nested span-tree construction with parent pointers + trace-id inheritance, metadata (release/environment/status/tags/data), and negative-duration guards. An end-to-end scope-isolation test against a real hub is a follow-up.