Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
`LoggerProviderBuilder.AddOtlpExporter` registration extensions.
[#5103](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5103)

* Removed the `OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES`
environment variable, following the stabilization of the exception attributes
`exception.type`, `exception.message`, and `exception.stacktrace` in the
[OpenTelemetry Semantic
Conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/exceptions/exceptions-logs.md#semantic-conventions-for-exceptions-in-logs).
These attributes, corresponding to `LogRecord.Exception`, are now standard and
will be automatically included in exports. The need for the previously
experimental flag is thus eliminated.

## 1.7.0

Released 2023-Dec-08
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ internal sealed class ExperimentalOptions

public const string LogRecordEventNameAttribute = "logrecord.event.name";

public const string EmitLogExceptionEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES";

public const string EmitLogEventEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES";

public ExperimentalOptions()
Expand All @@ -25,22 +23,12 @@ public ExperimentalOptions()

public ExperimentalOptions(IConfiguration configuration)
{
if (configuration.TryGetBoolValue(EmitLogExceptionEnvVar, out var emitLogExceptionAttributes))
{
this.EmitLogExceptionAttributes = emitLogExceptionAttributes;
}

if (configuration.TryGetBoolValue(EmitLogEventEnvVar, out var emitLogEventAttributes))
{
this.EmitLogEventAttributes = emitLogEventAttributes;
}
}

/// <summary>
/// Gets or sets a value indicating whether log exception attributes should be exported.
/// </summary>
public bool EmitLogExceptionAttributes { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether log event attributes should be exported.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ internal OtlpLogs.LogRecord ToOtlpLog(LogRecord logRecord)
}
}

if (this.experimentalOptions.EmitLogExceptionAttributes && logRecord.Exception != null)
if (logRecord.Exception != null)
{
AddStringAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionType, logRecord.Exception.GetType().Name, attributeValueLengthLimit, attributeCountLimit);
AddStringAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionMessage, logRecord.Exception.Message, attributeValueLengthLimit, attributeCountLimit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,8 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage)
Assert.Equal("state", otlpLogRecord.Body.StringValue);
}

[Theory]
[InlineData("true")]
[InlineData("false")]
[InlineData(null)]
public void CheckToOtlpLogRecordExceptionAttributes(string emitExceptionAttributes)
[Fact]
public void CheckToOtlpLogRecordExceptionAttributes()
{
var logRecords = new List<LogRecord>();
using var loggerFactory = LoggerFactory.Create(builder =>
Expand All @@ -609,39 +606,22 @@ public void CheckToOtlpLogRecordExceptionAttributes(string emitExceptionAttribut

var logRecord = logRecords[0];
var loggedException = logRecord.Exception;
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string> { [ExperimentalOptions.EmitLogExceptionEnvVar] = emitExceptionAttributes })
.Build();

var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new(configuration));
var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new());

var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord);

Assert.NotNull(otlpLogRecord);
var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString();

if (emitExceptionAttributes == "true")
{
Assert.Contains(SemanticConventions.AttributeExceptionType, otlpLogRecordAttributes);
Assert.Contains(logRecord.Exception.GetType().Name, otlpLogRecordAttributes);

Assert.Contains(SemanticConventions.AttributeExceptionMessage, otlpLogRecordAttributes);
Assert.Contains(logRecord.Exception.Message, otlpLogRecordAttributes);

Assert.Contains(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes);
Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes);
}
else
{
Assert.DoesNotContain(SemanticConventions.AttributeExceptionType, otlpLogRecordAttributes);
Assert.DoesNotContain(logRecord.Exception.GetType().Name, otlpLogRecordAttributes);
Assert.Contains(SemanticConventions.AttributeExceptionType, otlpLogRecordAttributes);
Assert.Contains(logRecord.Exception.GetType().Name, otlpLogRecordAttributes);

Assert.DoesNotContain(SemanticConventions.AttributeExceptionMessage, otlpLogRecordAttributes);
Assert.DoesNotContain(logRecord.Exception.Message, otlpLogRecordAttributes);
Assert.Contains(SemanticConventions.AttributeExceptionMessage, otlpLogRecordAttributes);
Assert.Contains(logRecord.Exception.Message, otlpLogRecordAttributes);

Assert.DoesNotContain(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes);
Assert.DoesNotContain(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes);
}
Assert.Contains(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes);
Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes);
}

[Fact]
Expand Down Expand Up @@ -1264,7 +1244,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeIsUsedInLogMethod_C
var allScopeValues = otlpLogRecord.Attributes
.Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2)
.Select(_ => _.Value.StringValue);
Assert.Equal(2, otlpLogRecord.Attributes.Count);
Assert.Equal(5, otlpLogRecord.Attributes.Count);
Assert.Equal(2, allScopeValues.Count());
Assert.Contains(scopeValue1, allScopeValues);
Assert.Contains(scopeValue2, allScopeValues);
Expand Down