Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion src/Sentry.OpenTelemetry/SentrySpanProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ private void CreateRootSpan(Activity data)
tracer.Contexts.Trace.Origin = OpenTelemetryOrigin;
tracer.StartTimestamp = data.StartTimeUtc;
}
_hub.ConfigureScope(static (scope, transaction) => scope.Transaction = transaction, transaction);
_hub.ConfigureScope(static (scope, transaction) =>
{
scope.Transaction ??= transaction;
}, transaction);
Comment thread
sentry[bot] marked this conversation as resolved.
transaction.SetFused(data);
_map[data.SpanId] = transaction;
}
Expand Down
21 changes: 21 additions & 0 deletions test/Sentry.OpenTelemetry.Tests/SentrySpanProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,4 +1012,25 @@ public void ParseOtelSpanDescription_HttpClient()
description.Should().Be("POST https://example.com/foo");
source.Should().Be(TransactionNameSource.Custom);
}

[Fact]
public void OnStart_WithExistingTransactionOnScope_DoesNotOverwriteExistingTransaction()
Comment thread
jamescrosswell marked this conversation as resolved.
{
_fixture.Options.Instrumenter = Instrumenter.OpenTelemetry;
_fixture.Options.TracesSampleRate = 1.0;
var sut = _fixture.GetSut();

using var firstActivity = Tracer.StartActivity("Existing");
sut.OnStart(firstActivity!);
Assert.True(sut._map.TryGetValue(firstActivity.SpanId, out var firstTransaction));

using var secondActivity = Tracer.StartActivity("NewRootActivity");
sut.OnStart(secondActivity!);

object scopeTransaction = null;
_fixture.Hub.ConfigureScope(scope => scopeTransaction = scope.Transaction);

scopeTransaction.Should().BeSameAs(firstTransaction,
"CreateRootSpan should not overwrite an already-set Scope.Transaction");
Comment thread
Flash0ver marked this conversation as resolved.
}
Comment thread
cursor[bot] marked this conversation as resolved.
Comment thread
cursor[bot] marked this conversation as resolved.
}
Loading