When the ASP.NET application is starting up, some logs are sent and they are visible in NewRelic. But when the application handles an http request, the logs sent through ILogger<T>
never appear in NewRelic.
I have the OTEL_DIAGNOSTICS.json
file, but no errors are written. ConsoleExporter
works flawlessly. I can see traces normally. In NewRelic nothing appears in NrIntegrationError
collection.
What am I doing wrong? It seems NewRelic only shows logs that are not correlated with traces and spans.
builder.Services.AddOpenTelemetry()
.ConfigureResource(builder => builder.AddService(Otel.ServiceName, serviceVersion: Otel.ServiceVersion))
.WithLogging(logging => logging
.AddConsoleExporter()
.AddOtlpExporter(otlp =>
{
otlp.Endpoint = new Uri($"{_otelEndpoint}/v1/logs");
otlp.Headers = $"api-key={_otelApiKey}";
otlp.Protocol = _otelProtocol; // Using Http/Protobuf
}), options =>
{
options.IncludeFormattedMessage = true;
options.IncludeScopes = true;
options.ParseStateValues = true;
})
.WithTracing(tracing => tracing
.AddSource(Otel.ServiceName)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRedisInstrumentation()
.AddAWSInstrumentation()
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri($"{_otelEndpoint}/v1/traces");
options.Headers = $"api-key={_otelApiKey}";
options.Protocol = _otelProtocol;
}))
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri($"{_otelEndpoint}/v1/metrics");
options.Headers = $"api-key={_otelApiKey}";
options.Protocol = _otelProtocol;
}));
2
Answers
It seems like your issue may be related to the correlation between logs and traces in NewRelic. Here are a few things to check:
Context Correlation: Ensure that your OpenTelemetry setup for logs (AddOtlpExporter) includes proper context propagation so that logs are correlated with trace IDs.
Log Level Settings: Make sure the log levels aren’t being filtered out. Set the log level to Debug or Information to verify if logs are appearing.
Endpoint and Protocol: Double-check the OTLP endpoint (_otelEndpoint/v1/logs), headers (api-key), and protocol settings to make sure they’re correct and compatible with NewRelic.
Logs in Context: Use NewRelic’s "Logs in Context" feature to help correlate logs with traces. Consider adding the NewRelic.LogEnrichers package for automatic enrichment.
Logging Processor: Make sure you’re using a BatchLogProcessor to manage log exports, and that Activity.Current is properly propagated to maintain context.
It sounds like you’re experiencing an issue where logs are successfully sent to New Relic during application startup but fail to appear when handling HTTP requests. This discrepancy typically points to differences in how logging is handled in these two phases, possibly related to log correlation with traces and spans.
Here are several steps and considerations to help you identify and resolve the issue:
1- Verify Log Correlation Attributes
Issue: During HTTP request handling, logs are often correlated with traces and spans. If these logs lack the necessary correlation attributes, New Relic might not display them as expected.
Solution:
2- Ensure Proper OpenTelemetry Pipeline Configuration
Issue: Misconfigurations in the OpenTelemetry logging pipeline can prevent logs from being exported correctly during HTTP requests.
Solution:
Although youre using a single AddOpenTelemetry setup, consider separating logging, tracing, and metrics pipelines to isolate and identify issues more effectively.
Consult Documentation: Review New Relic’s OpenTelemetry Logs Documentation to ensure that your logs comply with their ingestion requirements.
Required Attributes: Make sure that logs include attributes like service.name, trace_id, and span_id, which are crucial for correlation.
4 – Validate Exporter Configuration
Issue: Incorrect OTLP exporter settings can prevent logs from being sent correctly to New Relic.
Solution:
Endpoint Verification: Double-check that the OTLP log endpoint (${_otelEndpoint}/v1/logs) is correct and accessible from your application environment.
Headers and Authentication: Ensure that the api-key and any other required headers are correctly set. Incorrect headers can result in silent failures where logs are not ingested.
5 – Increase Diagnostic Logging
Issue: Silent failures can make it challenging to identify why logs aren’t appearing in New Relic.
Solution:
6 – Test with OpenTelemetry Collector
Issue: To isolate whether the issue is with your application or New Relic, you can use an intermediary like the OpenTelemetry Collector.
Solution:
7 – Update OpenTelemetry and New Relic SDKs
Issue: Incompatibilities or bugs in older versions of SDKs can lead to unexpected behavior.
Solution:
Summary
Your configuration appears mostly correct, but the issue likely revolves around how logs are correlated with traces during HTTP request handling. By verifying that logs include necessary correlation attributes, ensuring compatibility with New Relic’s requirements, and isolating the problem through diagnostic logging and possibly the OpenTelemetry Collector, you should be able to identify and resolve why logs aren’t appearing in New Relic during request handling.