Skip to content

SENTRY_ALLOW_FAILURE=true still fails the build #4849

@DanielMcAssey

Description

@DanielMcAssey

Package

Sentry

.NET Flavor

.NET

.NET Version

9.0.10

OS

Linux

OS Version

Ubuntu 24.04.3 LTS

Development Environment

Visual Studio v18.x

SDK Version

5.16.2

Self-Hosted Sentry Version

25.12.1

Workload Versions

None

UseSentry or SentrySdk.Init call

                .UseSentry(options =>
                {
                    var appOpts = configuration.GetSection("App").Get<AppOptions>();
                    var sentryOpts = configuration.GetSection("Sentry").Get<SentryConfigOptions>();
                    if (!appOpts.EnableSentry || string.IsNullOrWhiteSpace(sentryOpts.Dsn.Backend) ||
                        sentryOpts.SampleRate <= 0)
                    {
                        // Still need to pass in an empty DSN
                        options.Dsn = string.Empty;
                        return;
                    }

                    var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
                    var isDevelopment = env != null && env.Equals("Development", StringComparison.OrdinalIgnoreCase);
                    var instanceId = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME") ?? "unknown";

                    options.Dsn = sentryOpts.Dsn.Backend;
                    options.Release = "backend@" + appOpts.Version;
                    options.Environment = appOpts.Deployment;
                    options.SampleRate = sentryOpts.SampleRate;
                    options.TracesSampleRate = sentryOpts.PerformanceSampleRate;
                    options.ProfilesSampleRate = sentryOpts.PerformanceSampleRate;

                    // Config options
                    options.CaptureBlockingCalls = false;
                    options.CaptureFailedRequests = true;
                    options.IncludeActivityData = true;
                    options.EnableBackpressureHandling = true;
                    options.SendDefaultPii = true; // Scrubbed on the BeforeSend
                    options.MaxRequestBodySize = RequestSize.None; // Disable request body from being sent
                    options.FailedRequestStatusCodes.Add((400, 499)); // 500 to 599 already captured, add bad requests
#pragma warning disable SENTRY0001
                    options.Experimental.EnableLogs = true;
                    options.Experimental.SetBeforeSendLog(log =>
                    {
                        if (log.Level < SentryLogLevel.Info)
                        {
                            return null;
                        }

                        log.SetAttribute("instance_id", instanceId);

                        return log;
                    });
#pragma warning restore SENTRY0001

                    options.SetBeforeSend(sentryEvent =>
                    {
                        // Scrub PII
                        sentryEvent.User = new SentryUser { Id = sentryEvent.User.Id };
                        return sentryEvent;
                    });

                    options.AddProfilingIntegration();
                    options.DefaultTags.Add("instance_id", instanceId);

                    if (isDevelopment)
                    {
                        options.AutoRegisterTracing = false;
                    }
                })

Steps to Reproduce

  1. Set SENTRY_ALLOW_FAILURE to true
  2. Point to an instance that has an issue (SSL cert expired, is down, etc)
  3. Run the dotnet publish command
  4. Build fails

Build command:

      dotnet clean
      dotnet restore --force-evaluate --use-lock-file
      dotnet publish -c Release -o ${{ parameters.publishPath }} /p:SentryUpload=true

Property Group

    <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <DebugSymbols>true</DebugSymbols>
        <DebugType>portable</DebugType>
    </PropertyGroup>
    <PropertyGroup Condition="'$(SentryUpload)'=='true'">
        <SentryOrg>my-org</SentryOrg>
        <SentryProject>backend</SentryProject>
        <SentryUrl>https://sentry-url</SentryUrl>
        <SentryCreateRelease>true</SentryCreateRelease>
        <SentrySetCommits>true</SentrySetCommits>
        <SentryReleaseOptions>--finalize</SentryReleaseOptions>
        <SentryUploadSymbols>true</SentryUploadSymbols>
        <SentryUploadSources>true</SentryUploadSources>
    </PropertyGroup>

Expected Result

The build should not fail

Actual Result

The build fails with the following:

/agent/_work/1/.nuget/packages/sentry/5.16.2/buildTransitive/Sentry.targets(152,5): warning : Sentry API request failed.  Either the authentication info is invalid, or the Sentry server could not be reached. [/agent/_work/1/s/src/Backend.Core/Backend.Core.csproj]
  Backend -> /agent/_work/1/s/src/Backend/bin/Release/net9.0/Backend.dll
EXEC : error : API request failed [/agent/_work/1/s/src/Backend/Backend.csproj]
  
  Caused by:
      0: API request failed
      1: [60] SSL peer certificate or SSH remote key was not OK (SSL certificate problem: certificate has expired)
  
  Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
  Please attach the full debug log to all bug reports.
  
  Command failed, however, "SENTRY_ALLOW_FAILURE" variable or "allow-failure" flag was set. Exiting with 0 exit code.
/agent/_work/1/.nuget/packages/sentry/5.16.2/buildTransitive/Sentry.targets(152,5): warning : Sentry API request failed.  Either the authentication info is invalid, or the Sentry server could not be reached. [/agent/_work/1/s/src/Backend/Backend.csproj]
  Backend-> /agent/_work/1/s/dist/

##[error]Bash exited with code '1'.

Metadata

Metadata

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