Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Exceptions are not registered as errors in bridge mode #2472

Open
NikiforovAll opened this issue Oct 23, 2024 · 0 comments
Open

[BUG] Exceptions are not registered as errors in bridge mode #2472

NikiforovAll opened this issue Oct 23, 2024 · 0 comments
Labels
bug Something isn't working community triage

Comments

@NikiforovAll
Copy link

APM Agent version

Elastic Cloud / APM

Environment

windows, net8

Describe the bug

When I use Elastic.Apm in bridge mode the exceptions are recorded on Activity.RecordExceptions, I don't see them on "Errors" tab

Image
Image
Image

To Reproduce

using System.Diagnostics;
using Elastic.Apm.AspNetCore;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

builder.Logging.AddOpenTelemetry(logging =>
{
    logging.IncludeFormattedMessage = true;
    logging.IncludeScopes = true;
});

builder
    .Services.AddOpenTelemetry()
    .WithTracing(tracing =>
    {
        if (builder.Environment.IsDevelopment())
        {
            // We want to view all traces in development
            tracing.SetSampler(new AlwaysOnSampler());
        }

        tracing
            .AddSource("Worker")
            .AddHttpClientInstrumentation()
            .AddAspNetCoreInstrumentation()
            .AddConsoleExporter();
    });

builder.Services.AddHostedService<Worker>();

var app = builder.Build();

app.UseElasticApm(app.Configuration);

app.MapGet("/", () => "Hello World!");

app.Run();

public class Worker : BackgroundService
{
    public static readonly ActivitySource ActivitySource = new("Worker");

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            using var activity = ActivitySource.StartActivity("Worker.ExecuteAsync");

            try
            {
                throw new Exception("Something went wrong");
            }
            catch (Exception ex)
            {
                activity?.SetStatus(Status.Error.WithDescription(ex.Message));
                activity?.RecordException(ex);
            }
            await Task.Delay(TimeSpan.FromSeconds(15), stoppingToken);
        }
    }
}
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <RootNamespace>elastic_apm_otel_bridnge_errors</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
      <PackageReference Include="Elastic.Apm.AspNetCore" Version="1.30.0" />
      <PackageReference Include="Elastic.Apm" Version="1.30.0" />
      <PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
      <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
      <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
      <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
      <PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
      <PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
  </ItemGroup>

</Project>

Steps to reproduce the behavior:

Run the code above.

Expected behavior

I can find errors on the "Errors" tab.

Actual behavior

No errors are registered

@NikiforovAll NikiforovAll added the bug Something isn't working label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community triage
Projects
None yet
Development

No branches or pull requests

1 participant