Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Elastic.OpenTelemetry.Core/Diagnostics/LoggerMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,20 @@ internal static partial class LoggerMessages



// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 50, EventName = "FoundTag", Level = LogLevel.Trace, Message = "{ProcessorName} found `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
[LoggerMessage(EventId = 50, EventName = "FoundTag", Level = LogLevel.Trace, Message = "{ProcessorName} found '{AttributeName}' attribute with value '{AttributeValue}' on the span.")]
internal static partial void LogFoundTag(this ILogger logger, string processorName, string attributeName, object attributeValue);

// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 51, EventName = "SetTag", Level = LogLevel.Trace, Message = "{ProcessorName} set `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
[LoggerMessage(EventId = 51, EventName = "SetTag", Level = LogLevel.Trace, Message = "{ProcessorName} set '{AttributeName}' attribute with value '{AttributeValue}' on the span.")]
internal static partial void LogSetTag(this ILogger logger, string processorName, string attributeName, object attributeValue);




[LoggerMessage(EventId = 60, EventName = "DetectedIncludeScopes", Level = LogLevel.Warning, Message = "IncludeScopes is enabled and may cause export issues. See https://elastic.github.io/opentelemetry/edot-sdks/dotnet/troubleshooting.html#missing-log-records")]
internal static partial void LogDetectedIncludeScopesWarning(this ILogger logger);



public static void LogDistroPreamble(this ILogger logger, SdkActivationMethod activationMethod, ElasticOpenTelemetryComponents components)
{
// This occurs once per initialisation, so we don't use `LoggerMessage`s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public static void WithElasticDefaults(this OpenTelemetryLoggerOptions options,
#endif

options.IncludeFormattedMessage = true;
options.IncludeScopes = true;

// IncludeScopes is disabled until we have a resolution to duplicate attributes
// See:
// - https://github.com/open-telemetry/opentelemetry-dotnet/issues/4324
// - https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/39304
// options.IncludeScopes = true;

logger.LogConfiguredSignalProvider(nameof(Signals.Logs), nameof(OpenTelemetryLoggerOptions), "<n/a>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Elastic.OpenTelemetry.Exporters;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
Expand Down Expand Up @@ -41,7 +42,7 @@ public static class LoggingProviderBuilderExtensions
public static LoggerProviderBuilder WithElasticDefaults(this LoggerProviderBuilder builder)
{
#if NET
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(builder);
#else
if (builder is null)
throw new ArgumentNullException(nameof(builder));
Expand Down Expand Up @@ -139,6 +140,24 @@ static void ConfigureBuilder(LoggerProviderBuilder builder, BuilderState builder

builder.ConfigureServices(sc => sc.Configure<OpenTelemetryLoggerOptions>(o => o.WithElasticDefaults(logger)));

if (builder is IDeferredLoggerProviderBuilder deferredBuilder)
{
var httpContextType = Type.GetType("Microsoft.AspNetCore.Http.HttpContext, Microsoft.AspNetCore.Http.Abstractions");

if (httpContextType is not null)
{
var options = deferredBuilder.Configure((sp, _) =>
{
var options = sp.GetService<IOptions<OpenTelemetryLoggerOptions>>();

if (options is not null && options.Value.IncludeScopes == true)
{
logger.LogDetectedIncludeScopesWarning();
}
});
}
}

if (components.Options.SkipOtlpExporter)
{
logger.LogSkippingOtlpExporter(nameof(Signals.Logs), loggingProviderName, builderState.InstanceIdentifier);
Expand Down