Skip to content

Commit

Permalink
Set the scope transaction for Otel transactions (#3072)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrosswell authored Jan 23, 2024
1 parent 0536535 commit 947dac4
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ If you have conflicts, you can opt-out by adding the following to your `csproj`:

- Moved the binding to MAUI events for breadcrumb creation from `WillFinishLaunching` to `FinishedLaunching`. This delays the initial instantiation of `app`. ([#3057](https://github.com/getsentry/sentry-dotnet/pull/3057))
- The SDK no longer adds the `WinUIUnhandledExceptionIntegration` on non Windows platforms ([#3055](https://github.com/getsentry/sentry-dotnet/pull/3055))
- The scope transaction is now correctly set for Otel transactions ([#3072](https://github.com/getsentry/sentry-dotnet/pull/3072))

### Dependencies

Expand Down
1 change: 1 addition & 0 deletions src/Sentry.OpenTelemetry/SentrySpanProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public override void OnStart(Activity data)
transactionContext, new Dictionary<string, object?>(), dynamicSamplingContext
);
transaction.StartTimestamp = data.StartTimeUtc;
_hub.ConfigureScope(scope => scope.Transaction = transaction);
_map[data.SpanId] = transaction;
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/Sentry/TransactionTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,6 @@ internal TransactionTracer(IHub hub, ITransactionContext context, TimeSpan? idle
internal ISpan StartChild(SpanId? spanId, SpanId parentSpanId, string operation,
Instrumenter instrumenter = Instrumenter.Sentry)
{
if (instrumenter != _instrumenter)
{
_options?.LogWarning(
"Attempted to create a span via {0} instrumentation to a span or transaction" +
" originating from {1} instrumentation. The span will not be created.", instrumenter, _instrumenter);
return NoOpSpan.Instance;
}

var span = new SpanTracer(_hub, this, parentSpanId, TraceId, operation);
if (spanId is { } id)
{
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.OpenTelemetry.Tests/SentrySpanProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public void OnStart_WithoutParentSpanId_StartsNewTransaction()
{
// Arrange
_fixture.Options.Instrumenter = Instrumenter.OpenTelemetry;
_fixture.ScopeManager = Substitute.For<IInternalScopeManager>();
var sut = _fixture.GetSut();

var data = Tracer.StartActivity("test op");
Expand All @@ -212,6 +213,7 @@ public void OnStart_WithoutParentSpanId_StartsNewTransaction()
transaction.Description.Should().Be(data.DisplayName);
transaction.Status.Should().BeNull();
transaction.StartTimestamp.Should().Be(data.StartTimeUtc);
_fixture.ScopeManager.Received(1).ConfigureScope(Arg.Any<Action<Scope>>());
}
}

Expand Down

0 comments on commit 947dac4

Please sign in to comment.