-
Notifications
You must be signed in to change notification settings - Fork 824
[bug] Exporting logs with OtlpExporter and grpc not working. #6143
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
Comments
To make it your example working I need to change Results (same for .NET8 and .NET9):
Could you please prepare more detailed steps to reproduce? docker compose file could be beneficial to reproduce it. |
@Kielek Thanks a lot for responding quickly.
Sorry, These are my local setup method and need to change it accordingly. The output above shows from console exporter, which work fine for me as well with docker a image. These logs are not actually reaching the grpc receiver. The same code when I use it with 1.10.0 open telemetry SDK, it works fine and logs are reaching the grpc receiver. |
It is debug log from the collector with grpc receiver |
ok, it it a bit strange that this code works with 1.10.0 but not with 1.11.1. |
As you see, it is working with 1.11.1 for me. Can you share Minimal, Reproducible Example? |
@pravinpushkar This could be related to #6138. Can you validate this? |
@pravinpushkar did you check you are running .NET8 and not .NET6? I had the same issue and it was regarding .NET6.. |
Can you check how you're ending the application? The OTLP exporter runs on a batch interval, so if you end your application too soon, then it may cause an issue that you're finishing before it's exported. Also check out the self diagnostics to see if there's a failure connecting to your backend. |
I'm getting these exceptions using .NET6 |
@pravinpushkar Could you please try with the latest version 1.11.2 and check if it works now? |
It doesn't work with 1.11.2 as well (tested using .Net 9 runtime). Exporting works (and is visible, e.g., in Aspire Dashboard) when you use the web stack, meaning when you start building the stack using It does not work when you try to build the stack manually, starting the definition with |
Minimal example: using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
namespace OtelTests;
class Program
{
static void Main(string[] args)
{
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddOpenTelemetry()
.ConfigureResource(builder => builder.AddService("as-app"))
.WithLogging(loggingBuilder =>
{
//loggingBuilder
//.AddConsoleExporter()
//.AddOtlpExporter(); // Default endpoint is http://localhost:4317
})
.UseOtlpExporter();
})
.Build();
ILogger<Program> logger = host.Services.GetRequiredService<ILogger<Program>>();
for (int logIndex = 0; logIndex < 10; logIndex++)
{
logger.LogInformation("This is log entry nr {NR}", logIndex);
}
host.Run();
}
} Project def (used libs/nugets/deps): <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.3" />
<PackageReference Include="OpenTelemetry" Version="1.11.2" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.11.2" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.2" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />
</ItemGroup>
</Project> The command to run Aspire Dashboard:
The Dashboard is available here: Console screenshot: Aspire log screenshot |
?? |
You need to call a flush on the tracerprovider to cause the batch to be sent. |
Still nothing. Maybe I'm just doing something wrong? class Program
{
static void Main(string[] args)
{
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddOpenTelemetry()
.ConfigureResource(builder => builder.AddService("as-app"))
.WithLogging(loggingBuilder =>
{
//loggingBuilder
//.AddConsoleExporter()
//.AddOtlpExporter(); // Defaukt endpoint is http://localhost:4317
})
.UseOtlpExporter();
})
.Build();
ILogger<Program> logger = host.Services.GetRequiredService<ILogger<Program>>();
for (int logIndex = 0; logIndex < 10; logIndex++)
{
logger.LogInformation("This is log entry nr {NR}", logIndex);
}
var tracerProvider = host.Services.GetRequiredService<TracerProvider>();
tracerProvider.ForceFlush();
host.Run();
}
} |
Do you have the logging level set to include information? Maybe try logging an error? |
I have the default settings, so as far as I remember, it's the Information level. |
Note that You can refer to this demo app in the Azure SDK repo for guidance: |
This code doesn't work as well of course... using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
namespace OtelTests;
public class SomeHostedService : IHostedService
{
private readonly ILogger<SomeHostedService> _logger;
private readonly TracerProvider _tracerProvider;
public SomeHostedService(ILogger<SomeHostedService> logger, TracerProvider tracerProvider)
{
_logger = logger;
_tracerProvider = tracerProvider;
}
public Task StartAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Hosted service started.");
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Hosted service stopped.");
return Task.CompletedTask;
}
}
class Program
{
static void Main(string[] args)
{
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddOpenTelemetry()
.ConfigureResource(builder => builder.AddService("as-app"))
.WithLogging(loggingBuilder =>
{
//loggingBuilder
//.AddConsoleExporter()
//.AddOtlpExporter(); // Defaukt endpoint is http://localhost:4317
})
.UseOtlpExporter();
services.AddSingleton<IHostedService, SomeHostedService>();
})
.Build();
ILogger<Program> logger = host.Services.GetRequiredService<ILogger<Program>>();
for (int logIndex = 0; logIndex < 10; logIndex++)
{
logger.LogError("This is log entry nr {NR}", logIndex);
}
var tracerProvider = host.Services.GetRequiredService<TracerProvider>();
tracerProvider.ForceFlush();
host.Run();
}
} |
It looks like this was my mistake (or rather an issue with my computer). When I start the Docker image and run the test program, it tries to establish a connection over IPv6, but for some reason, the Docker image doesn’t map that protocol and only allows connections over IPv4. That is, when I use I still need to investigate why this is happening, because I haven’t blocked IPv6 in Docker Desktop, and explicitly enabling it in the config followed by a restart doesn’t help — communication over IPv6 still doesn’t work. |
I just found such info: |
Package
OpenTelemetry
Package Version
Runtime Version
8
Description
This seems still reproducible with 1.11.1.
Related issue - #6067
#6083
Steps to Reproduce
Here is samle code -
Expected Result
Logs successfully exported
Actual Result
Logs not able to get exported. No errors.
Additional Context
No response
The text was updated successfully, but these errors were encountered: