Skip to content

Commit f13d2e2

Browse files
authored
No longer default to IncludeScopes (#265)
Due to spec non-compliance in the upstream SDK, this can cause issues when sent through the EDOT collector and the managed OTLP endpoint. We'll reenable it in a future release once upstream is fixed. Lessens the impact of #263. The main fix needs to occur upstream.
1 parent 8956548 commit f13d2e2

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src/Elastic.OpenTelemetry.Core/Diagnostics/LoggerMessages.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,20 @@ internal static partial class LoggerMessages
133133

134134

135135

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

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

144142

145143

144+
145+
[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")]
146+
internal static partial void LogDetectedIncludeScopesWarning(this ILogger logger);
147+
148+
149+
146150
public static void LogDistroPreamble(this ILogger logger, SdkActivationMethod activationMethod, ElasticOpenTelemetryComponents components)
147151
{
148152
// This occurs once per initialisation, so we don't use `LoggerMessage`s.

src/Elastic.OpenTelemetry.Core/Extensions/OpenTelemetryLoggerOptionsExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ public static void WithElasticDefaults(this OpenTelemetryLoggerOptions options,
3838
#endif
3939

4040
options.IncludeFormattedMessage = true;
41-
options.IncludeScopes = true;
41+
42+
// IncludeScopes is disabled until we have a resolution to duplicate attributes
43+
// See:
44+
// - https://github.com/open-telemetry/opentelemetry-dotnet/issues/4324
45+
// - https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/39304
46+
// options.IncludeScopes = true;
4247

4348
logger.LogConfiguredSignalProvider(nameof(Signals.Logs), nameof(OpenTelemetryLoggerOptions), "<n/a>");
4449
}

src/Elastic.OpenTelemetry/Extensions/LoggingProviderBuilderExtensions.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Elastic.OpenTelemetry.Exporters;
1111
using Microsoft.Extensions.Configuration;
1212
using Microsoft.Extensions.DependencyInjection;
13+
using Microsoft.Extensions.Options;
1314
using OpenTelemetry.Exporter;
1415
using OpenTelemetry.Logs;
1516
using OpenTelemetry.Resources;
@@ -41,7 +42,7 @@ public static class LoggingProviderBuilderExtensions
4142
public static LoggerProviderBuilder WithElasticDefaults(this LoggerProviderBuilder builder)
4243
{
4344
#if NET
44-
ArgumentNullException.ThrowIfNull(builder);
45+
ArgumentNullException.ThrowIfNull(builder);
4546
#else
4647
if (builder is null)
4748
throw new ArgumentNullException(nameof(builder));
@@ -139,6 +140,24 @@ static void ConfigureBuilder(LoggerProviderBuilder builder, BuilderState builder
139140

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

143+
if (builder is IDeferredLoggerProviderBuilder deferredBuilder)
144+
{
145+
var httpContextType = Type.GetType("Microsoft.AspNetCore.Http.HttpContext, Microsoft.AspNetCore.Http.Abstractions");
146+
147+
if (httpContextType is not null)
148+
{
149+
var options = deferredBuilder.Configure((sp, _) =>
150+
{
151+
var options = sp.GetService<IOptions<OpenTelemetryLoggerOptions>>();
152+
153+
if (options is not null && options.Value.IncludeScopes == true)
154+
{
155+
logger.LogDetectedIncludeScopesWarning();
156+
}
157+
});
158+
}
159+
}
160+
142161
if (components.Options.SkipOtlpExporter)
143162
{
144163
logger.LogSkippingOtlpExporter(nameof(Signals.Logs), loggingProviderName, builderState.InstanceIdentifier);

0 commit comments

Comments
 (0)