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

UseOtlpExporter doesn't seem to work with just a logging configuration #5652

Open
davidfowl opened this issue May 25, 2024 · 2 comments
Open
Assignees

Comments

@davidfowl
Copy link
Contributor

<Project Sdk="Microsoft.NET.Sdk.Web">

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

  <ItemGroup>
    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
    <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
    <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
  </ItemGroup>

</Project>
using OpenTelemetry;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

builder.Logging.AddOpenTelemetry();

builder.Services.AddOpenTelemetry().UseOtlpExporter();

var app = builder.Build();

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

app.Run();

cc @CodeBlanch

@dario-griffo-paytently
Copy link

dario-griffo-paytently commented May 27, 2024

@davidfowl your code works for me image
What I think is a problem that you don't need
builder.Logging.AddOpenTelemetry();
if you do
builder.Services.AddOpenTelemetry().UseOtlpExporter(); since it enables the logging.

I have created an issue here because I want to use serilog as provider but seeing duplicated logs in my otel

The following code exports logs, dotnet 8.0.300, OTEL 1.8.1

using OpenTelemetry;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry().UseOtlpExporter();

var app = builder.Build();

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

app.Run();

@CodeBlanch
Copy link
Member

@davidfowl

I just tested it, this seems to work fine:

builder.Logging.AddOpenTelemetry();

builder.Services.AddOpenTelemetry().UseOtlpExporter();

Which is what I would expect.

When using UseOtlpExporter you can just call:

builder.Services.AddOpenTelemetry().UseOtlpExporter();

Because UseOtlpExporter does the work of Logging.AddOpenTelemetry().

But this alone though wouldn't work:

builder.Logging.AddOpenTelemetry();

That would need to be:

builder.Logging.AddOpenTelemetry(options => options.AddOtlpExporter());

Can you clarify what you are trying to do and seeing?

@CodeBlanch CodeBlanch self-assigned this May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants