Skip to content
Closed
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
2 changes: 2 additions & 0 deletions sentry-dotnet/5718/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
obj/
83 changes: 83 additions & 0 deletions sentry-dotnet/5718/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Reproduction for getsentry/sentry-dotnet#5718
//
// If SentryAspNetCoreOptions.TransactionNameProvider throws, the transaction is dropped
// (never finished/captured) and the exception escapes the Sentry tracing middleware.
//
// Expected: the transaction is still captured, named "<unlabeled transaction>"
// (and not the raw URL path, which may contain PII).
// Actual: no transaction is captured.

using System.Collections.Concurrent;
using Microsoft.AspNetCore.TestHost;
using Sentry;

var captured = new ConcurrentBag<SentryTransaction>();

var host = new WebHostBuilder()
.UseSentry(o =>
{
// Dummy DSN: the SDK is enabled, but the hooks below drop everything, so nothing is sent.
o.Dsn = "https://public@example.com/1";
o.TracesSampleRate = 1.0;
o.TransactionNameProvider = _ => throw new InvalidOperationException("TransactionNameProvider failed");
o.SetBeforeSendTransaction(t =>
{
captured.Add(t);
return null;
});
o.SetBeforeSend(_ => null);
})
.Configure(app =>
{
app.UseSentryTracing();
// No routing: the SDK falls back to the TransactionNameProvider for the transaction name.
app.Run(ctx => ctx.Response.WriteAsync("ok"));
});

using var server = new TestServer(host);
var client = server.CreateClient();

var sentryAssembly = typeof(SentrySdk).Assembly;
Console.WriteLine($"Sentry loaded from: {sentryAssembly.Location}");
Console.WriteLine($"Sentry.AspNetCore loaded from: {typeof(Sentry.AspNetCore.SentryAspNetCoreOptions).Assembly.Location}");

const string path = "/users/jane.doe@example.com";
try
{
var response = await client.GetAsync(path);
Console.WriteLine($"GET {path} -> {(int)response.StatusCode}");
}
catch (Exception e)
{
Console.WriteLine($"GET {path} threw: {e.GetType().Name}: {e.Message}");
}

await SentrySdk.FlushAsync(TimeSpan.FromSeconds(2));

Console.WriteLine($"Captured transactions: {captured.Count}");
foreach (var t in captured)
{
Console.WriteLine($" name='{t.Name}' source={t.NameSource}");
}

var transaction = captured.SingleOrDefault();
if (transaction is null)
{
Console.WriteLine("BUG REPRODUCED: the transaction was dropped because TransactionNameProvider threw.");
return 1;
}

if (transaction.Name.Contains(path))
{
Console.WriteLine("BUG REPRODUCED: the transaction name contains the raw request path (possible PII).");
return 1;
}

if (transaction.Name != "<unlabeled transaction>")
{
Console.WriteLine($"UNEXPECTED: expected '<unlabeled transaction>', got '{transaction.Name}'.");
return 1;
}

Console.WriteLine("OK: the transaction was kept and named '<unlabeled transaction>'.");
return 0;
48 changes: 48 additions & 0 deletions sentry-dotnet/5718/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Reproduction for sentry-dotnet#5718

**Issue:** https://github.com/getsentry/sentry-dotnet/issues/5718

## Description

When `SentryAspNetCoreOptions.TransactionNameProvider` throws, the Sentry tracing middleware
never finishes the transaction, so it is dropped. The exception also escapes the middleware
and fails the request.

The repro runs an ASP.NET Core app on `TestServer` with no routing (so the SDK falls back to the
`TransactionNameProvider`), a provider that throws, and a dummy DSN. `BeforeSendTransaction`
records transactions and drops them, so nothing is sent.

## Steps to Reproduce

Requires the .NET 8 SDK.

```bash
dotnet run
```

Exits 1 and prints `BUG REPRODUCED` when the transaction is dropped (or named after the raw URL path).

To run against a local `sentry-dotnet` checkout instead of the NuGet package:

```bash
dotnet run -p:SentryAspNetCoreProject=/path/to/sentry-dotnet/src/Sentry.AspNetCore/Sentry.AspNetCore.csproj
```

## Expected Behavior

The transaction is still captured, named `<unlabeled transaction>` rather than the request URL
(which may contain PII).

## Actual Behavior

```
GET /users/jane.doe@example.com threw: HttpRequestException: Error while copying content to a stream.
Captured transactions: 0
BUG REPRODUCED: the transaction was dropped because TransactionNameProvider threw.
```

## Environment

- .NET: 8.0
- Sentry.AspNetCore: 7.0.0
- OS: Linux
23 changes: 23 additions & 0 deletions sentry-dotnet/5718/Repro.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Override the version with -p:SentryVersion=..., or test a local checkout with -p:SentryAspNetCoreProject=/path/to/src/Sentry.AspNetCore/Sentry.AspNetCore.csproj -->
<SentryVersion Condition="'$(SentryVersion)' == ''">7.0.0</SentryVersion>
</PropertyGroup>

<ItemGroup Condition="'$(SentryAspNetCoreProject)' == ''">
<PackageReference Include="Sentry.AspNetCore" Version="$(SentryVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(SentryAspNetCoreProject)' != ''">
<ProjectReference Include="$(SentryAspNetCoreProject)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.11" />
</ItemGroup>

</Project>
Loading