I'm trying to export metrics, traces and logs to NewRelic by using OtlpExporter, however I'm not having any success. I setup my Program.cs as follows on a simple .Net 7 API and the sympton is that nothing shows on NewRelic. My license key is correct. If I enable console logging I don't see any kind of error or warning. I don't have any environment variable configured apart from what we see here on the code. Am I missing anything that would make this work?
using OpenTelemetry;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var endpoint = new Uri("https://otlp.eu01.nr-data.net");
var exportProcessorType = ExportProcessorType.Batch;
var protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
var headers = $"api-key=aaaaaaa";
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeScopes = true;
var resourceBuilder = ResourceBuilder
.CreateDefault()
.AddService("WeatherForecast");
logging.SetResourceBuilder(resourceBuilder)
//.AddConsoleExporter()
.AddOtlpExporter(configure =>
{
configure.Endpoint = endpoint;
configure.ExportProcessorType = exportProcessorType;
configure.Protocol = protocol;
configure.Headers = headers;
});
});
// Exporter
// URL: https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/get-started/opentelemetry-set-up-your-app/#review-settings
// Link: https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol
builder.Services.AddOpenTelemetry()
.WithMetrics(builder => builder
.AddAspNetCoreInstrumentation()
//.AddConsoleExporter()
.AddOtlpExporter(configure =>
{
configure.Endpoint = endpoint;
configure.ExportProcessorType = exportProcessorType;
configure.Protocol = protocol;
configure.Headers = headers;
}))
.WithTracing(builder => builder
.AddAspNetCoreInstrumentation()
//.AddConsoleExporter()
.AddOtlpExporter(configure =>
{
configure.Endpoint = endpoint;
configure.ExportProcessorType = exportProcessorType;
configure.Protocol = protocol;
configure.Headers = headers;
}));
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();