Skip to content
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

Fix ParentSampledId being reset on Transaction #1130

Merged
merged 4 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Fix `ParentSampledId` being reset on `Transaction` ([#1130](https://github.com/getsentry/sentry-dotnet/pull/1130))

## 3.8.1

### Fixes
Expand Down
7 changes: 5 additions & 2 deletions src/Sentry/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,15 @@ public Transaction(string name, string operation)
/// Initializes an instance of <see cref="Transaction"/>.
/// </summary>
public Transaction(ITransaction tracer)
: this(tracer.Name, tracer.Operation)
: this(tracer.Name)
{
// Contexts have to be set first because other fields use that
Contexts = tracer.Contexts;

ParentSpanId = tracer.ParentSpanId;
SpanId = tracer.SpanId;
TraceId = tracer.TraceId;
Operation = tracer.Operation;
Platform = tracer.Platform;
Release = tracer.Release;
StartTimestamp = tracer.StartTimestamp;
Expand All @@ -211,7 +215,6 @@ public Transaction(ITransaction tracer)
IsSampled = tracer.IsSampled;
Level = tracer.Level;
Request = tracer.Request;
Contexts = tracer.Contexts;
User = tracer.User;
Environment = tracer.Environment;
Sdk = tracer.Sdk;
Expand Down
19 changes: 7 additions & 12 deletions test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ public async Task Transaction_is_bound_on_the_scope_automatically()
public async Task Transaction_is_started_automatically_from_incoming_trace_header()
{
// Arrange
ITransactionData transaction = null;

var sentryClient = Substitute.For<ISentryClient>();

var hub = new Internal.Hub(sentryClient, new SentryOptions
Expand All @@ -149,11 +147,7 @@ public async Task Transaction_is_started_automatically_from_incoming_trace_heade

app.UseEndpoints(routes =>
{
routes.Map("/person/{id}", _ =>
{
transaction = hub.GetSpan() as ITransactionData;
return Task.CompletedTask;
});
routes.Map("/person/{id}", _ => Task.CompletedTask);
});
})
);
Expand All @@ -169,11 +163,12 @@ public async Task Transaction_is_started_automatically_from_incoming_trace_heade
await client.SendAsync(request);

// Assert
transaction.Should().NotBeNull();
transaction?.Name.Should().Be("GET /person/{id}");
transaction.TraceId.Should().Be(SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"));
transaction.ParentSpanId.Should().Be(SpanId.Parse("1000000000000000"));
transaction.IsSampled.Should().BeFalse();
sentryClient.Received(1).CaptureTransaction(Arg.Is<Transaction>(t =>
t.Name == "GET /person/{id}" &&
Copy link
Member

Choose a reason for hiding this comment

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

The issue was trasnaction?. and transaction was null so assert wasn't being called?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it was fine. The problem is that the transaction was created correctly, it was not sent correctly. So I widened the test scope to cover that (by testing against ISentryClient).

t.TraceId == SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8") &&
t.ParentSpanId == SpanId.Parse("1000000000000000") &&
t.IsSampled == false
));
}

[Fact]
Expand Down