Skip to content

Profiling - No spans except for Program.cs Main method in ASP.NET Core application #4820

@tvardero

Description

@tvardero

Package

Sentry.Profiling

.NET Flavor

.NET Core

.NET Version

9.0.? from mcr.microsoft.com/dotnet/sdk:9.0

OS

Linux

OS Version

Linux x64 from mcr.microsoft.com/dotnet/aspnet:9.0

Development Environment

Other

SDK Version

5.16.2

Self-Hosted Sentry Version

25.11.0

Workload Versions

not related

UseSentry or SentrySdk.Init call

appsettings.json:

"Logging": {
  "LogLevel": {
    "Default": "Information",
    "System": "Warning",
    "Microsoft": "Warning",
    "Microsoft.Hosting.Lifetime": "Information",
    "Microsoft.EntityFrameworkCore": "Information",
    "Microsoft.EntityFrameworkCore.Database.Command": "Warning",
    "Microsoft.AspNetCore.Hosting.Diagnostics": "None",
    "ZiggyCreatures.Caching.Fusion": "None",
    "Polly": "None"
  }
},
"Sentry": {
  "Dsn": "https://[email protected]/2",
  "MinimumEventLevel": "Warning",
  "MinimumBreadcrumbLevel": "Information",
  "ProfilesSampleRate": 0.3
},
"OpenTelemetryOptions":  {
  "Endpoint": "https://alloy.xxxxxxxxxxxxxx",
  "Protocol": "HttpProtobuf"
}

Program.cs:

static void ConfigureTelemetry(WebApplicationBuilder builder)
{
    OpenTelemetryBuilder openTelemetryBuilder = builder.Services.AddOpenTelemetry()
        .ConfigureResource(r =>
        {
            r.AddService("gl-backend");
            r.AddAttributes([new KeyValuePair<string, object>("environment", builder.Environment.EnvironmentName)]);
        })
        .WithTracing(t =>
        {
            t.AddAspNetCoreInstrumentation();
            t.AddHttpClientInstrumentation();
            t.AddSentry();
        })
        .WithMetrics(m =>
        {
            m.AddAspNetCoreInstrumentation();
            m.AddHttpClientInstrumentation();
            m.AddRuntimeInstrumentation();
        })
        .WithLogging(_ => { },
            l =>
            {
                l.IncludeFormattedMessage = true;
                l.IncludeScopes = true;
            });

    var sentryDsn = builder.Configuration.GetValue<string?>("Sentry:Dsn");
    if (!string.IsNullOrWhiteSpace(sentryDsn))
        builder.WebHost.UseSentry((SentryAspNetCoreOptions s) =>
        {
            s.AdjustStandardEnvironmentNameCasing = false;
            s.UseOpenTelemetry();
            s.DisableSentryHttpMessageHandler = true;
            s.AddProfilingIntegration();

            // Remove nugets from in-app frames. This way nugets won't be considered "App" frames and will be considered "Library" frames.
            Array.ForEach(Program._excludeNugetsFromSentryAppFrames, s.AddInAppExclude);
        });

    var otelOptions = builder.Configuration.GetSection("OpenTelemetryOptions").Get<OpenTelemetryOptions>();
    if (otelOptions?.Endpoint != null) { openTelemetryBuilder.UseOtlpExporter(otelOptions.Protocol, otelOptions.Endpoint); }
}

public partial class Program
{
    private static readonly string[] _excludeNugetsFromSentryAppFrames =
    [
        "MySqlConnector", "Pomelo.EntityFrameworkCore.MySql", "ShipEngine", "Yarp", "Rebus", "Amazon", "AWSSDK", "ZiggyCreatures.FusionCache",
        "OpenTelemetry", "EntityFramework.Exceptions.Common", "object InvokeStub_TaskAwaiter", "TickerQ", "Duende.IdentityModel",
        "Duende.AccessTokenManagement", "Xero", "Scriban", "BarcodeStandard"
    ];
}

Steps to Reproduce

  1. Use application
  2. Inspect profiling page on Sentry

Expected Result

Profiles of application code.

Actual Result

No profiles, except Program.cs main function.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeBugSomething isn't working

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions