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/trace root #3453

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Fixes

- The SDK no longer fails to create a trace root ([#3453](https://github.com/getsentry/sentry-dotnet/pull/3453))
- Debug logs are now visible for MAUI apps in Visual Studio when using Sentry's default DiagnosticLogger ([#3373](https://github.com/getsentry/sentry-dotnet/pull/3373))
- Fixed Monitor duration calculation ([#3420]https://github.com/getsentry/sentry-dotnet/pull/3420)
- Fixed null IServiceProvider in anonymous routes with OpenTelemetry ([#3401](https://github.com/getsentry/sentry-dotnet/pull/3401))
Expand Down
12 changes: 7 additions & 5 deletions src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,14 @@ public TransactionContext ContinueTrace(
var propagationContext = SentryPropagationContext.CreateFromHeaders(_options.DiagnosticLogger, traceHeader, baggageHeader);
ConfigureScope(scope => scope.PropagationContext = propagationContext);

// If we have to create a new SentryTraceHeader we don't make a sampling decision
traceHeader ??= new SentryTraceHeader(propagationContext.TraceId, propagationContext.SpanId, null);
return new TransactionContext(
name ?? string.Empty,
operation ?? string.Empty,
traceHeader);
name: name ?? string.Empty,
operation: operation ?? string.Empty,
spanId: propagationContext.SpanId,
parentSpanId: propagationContext.ParentSpanId,
traceId: propagationContext.TraceId,
isSampled: traceHeader?.IsSampled,
isParentSampled: traceHeader?.IsSampled);
}

public void StartSession()
Expand Down
18 changes: 18 additions & 0 deletions test/Sentry.Tests/HubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,24 @@ public void ContinueTrace_ReceivesHeadersAsStrings_SetsPropagationContextAndRetu
transactionContext.ParentSpanId.Should().Be(SpanId.Parse("2000000000000000"));
}

[Fact]
public void ContinueTrace_DoesNotReceiveHeaders_CreatesRootTrace()
{
// Arrange
var hub = _fixture.GetSut();

// Act
var transactionContext = hub.ContinueTrace((string)null, null, "test-name");

// Assert
transactionContext.Name.Should().Be("test-name");
transactionContext.SpanId.Should().NotBe(null);
transactionContext.ParentSpanId.Should().Be(null);
transactionContext.TraceId.Should().NotBe(null);
transactionContext.IsSampled.Should().Be(null);
transactionContext.IsParentSampled.Should().Be(null);
}

[Fact]
public void CaptureTransaction_AfterTransactionFinishes_ResetsTransactionOnScope()
{
Expand Down
Loading