-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit transaction.data inside contexts.trace.data #3936
base: main
Are you sure you want to change the base?
Changes from all commits
4292c46
253239f
9d51787
58e4a1e
590a182
d50a2dd
19bbb62
b396668
eda625a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,7 @@ public void AddBreadcrumb(Breadcrumb breadcrumb) => | |
_breadcrumbs.Add(breadcrumb); | ||
|
||
/// <inheritdoc /> | ||
[Obsolete("Add metadata to Contexts.Trace.SetData")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be doing this? I thought Extra was supposed to stay the way it is... or is this something you've seen it the docs or other SDKs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we were adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what the answer is here? @bruno-garcia There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deprecate extra and add |
||
public void SetExtra(string key, object? value) => | ||
_extra[key] = value; | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||
using System.Text.Json.Nodes; | ||||||
|
||||||
namespace Sentry.Tests; | ||||||
|
||||||
public partial class SerializationTests | ||||||
{ | ||||||
private readonly IDiagnosticLogger _testOutputLogger; | ||||||
|
||||||
public SerializationTests(ITestOutputHelper output) | ||||||
{ | ||||||
_testOutputLogger = new TestOutputDiagnosticLogger(output); | ||||||
} | ||||||
|
||||||
[Fact] | ||||||
public void Serialization_TransactionAndSpanData() | ||||||
{ | ||||||
var hub = Substitute.For<IHub>(); | ||||||
var context = new TransactionContext("name", "operation", new SentryTraceHeader(SentryId.Empty, SpanId.Empty, false)); | ||||||
var transactionTracer = new TransactionTracer(hub, context); | ||||||
var span = transactionTracer.StartChild("childop"); | ||||||
span.SetExtra("span1", "value1"); | ||||||
|
||||||
var transaction = new SentryTransaction(transactionTracer) | ||||||
{ | ||||||
IsSampled = false | ||||||
}; | ||||||
transaction.Contexts.Trace.SetData("transaction1", "transaction_value"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could stay here but my understanding is that we're "replacing" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My original PR redirected SetExtra to Contexts.Trace.Data so this is easy to do. Just not sure what you guys are looking for here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aritchie I think Michi's comment clarifies things. So it looks like this PR is on the right track. I can't see a way to add sentry-dotnet/src/Sentry/SentrySdk.cs Lines 593 to 594 in a421af5
What I'd suggest then:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we simply deprecate Regarding changing where this goes customers may have filtering logic in place, e.g. in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This would be a breaking change... adding a new member to an interface would break any existing classes implementing that interface - and this would involve modifying multiple interfaces (for historical reasons). I think if it was a real showstopper, we could consider doing it. But in this case, changing the names of those methods from SetExtra to SetData doesn't really change anything except how SDK users use our SDK to add arbitrary data to traces and spans. It doesn't enable delivering any features that we want/need for Sentry. So it feels like a lot of work for very little gain. I'd rather we do this in the next major release (v6.0) unless there is any compelling reason to do it now. |
||||||
var json = transaction.ToJsonString(_testOutputLogger); | ||||||
_testOutputLogger.LogDebug(json); | ||||||
|
||||||
var node = JsonNode.Parse(json); | ||||||
var dataNode = node?["contexts"]?["trace"]?["data"]?["transaction1"]?.GetValue<string>(); | ||||||
dataNode.Should().NotBeNull("contexts.trace.data.transaction1 not found"); | ||||||
dataNode.Should().Be("transaction_value"); | ||||||
|
||||||
var spansNode = node?["spans"]?.AsArray(); | ||||||
spansNode.Should().NotBeNull("spans not found"); | ||||||
var spanDataNode = spansNode!.FirstOrDefault()?["data"]?["span1"]?.GetValue<string>(); | ||||||
spanDataNode.Should().NotBeNull("spans.data not found"); | ||||||
spanDataNode.Should().Be("value1"); | ||||||
|
||||||
// verify deserialization | ||||||
var reader = new Utf8JsonReader(Encoding.UTF8.GetBytes(json)); | ||||||
var el = JsonElement.ParseValue(ref reader); | ||||||
var backTransaction = SentryTransaction.FromJson(el); | ||||||
|
||||||
backTransaction.Spans.First().Extra["span1"].Should().Be("value1", "Span value missing"); | ||||||
backTransaction.Contexts.Trace.Data["transaction1"].Should().Be("transaction_value", "Transaction value missing"); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could potentially back this by a
Lazy<T>
to avoid allocations when no Trace.Data is set.We try to do this wherever possible - particularly for the trace classes as there can potentially be thousands of these allocated at any one time in larger applications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So lazy is an allocation on its own and there is no computation here. I can add this. I could also set the initial size of the dictionary to 0 which is likely better. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could initialise the dictionary only if it's accessed... something like: