Skip to content
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
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
31 changes: 31 additions & 0 deletions test/Sentry.OpenTelemetry.Tests/SentrySpanProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,4 +1012,35 @@ 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.
{
// Arrange
_fixture.Options.Instrumenter = Instrumenter.OpenTelemetry;
var sut = _fixture.GetSut();

var parentContext = new TransactionContext("Program", "Main")
{
Instrumenter = Instrumenter.OpenTelemetry,
};
var parent = _fixture.Hub.StartTransaction(parentContext);
_fixture.Hub.ConfigureScope(scope => scope.Transaction = parent);

using var data = Tracer.StartActivity("TestActivity");

// Act
sut.OnStart(data!);

// Assert
data.ParentSpanId.Should().Be(default(ActivitySpanId), $"{nameof(data)} should be a new root Activity, not a child Activity");
Assert.True(sut._map.TryGetValue(data.SpanId, out var span));
span.Should().BeOfType<TransactionTracer>($"{nameof(data)} should be a new root Transaction, not a child Span");

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

scopeTransaction.Should().BeSameAs(parent,
"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