Convert StateValues (when present) to Attributes. (#2554)
This commit is contained in:
parent
74b01fdf80
commit
8c1c1495d9
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
* Changed `OtlpLogExporter` to convert `ILogger` structured log inputs to
|
||||
`Attributes` in OpenTelemetry (only active when `ParseStateValues` is `true`
|
||||
on `OpenTelemetryLoggerOptions`)
|
||||
|
||||
## Unreleased
|
||||
|
||||
* Added validation that insecure channel is configured correctly when using
|
||||
|
|
|
|||
|
|
@ -76,16 +76,25 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
|
|||
otlpLogRecord.Body = new OtlpCommon.AnyValue { StringValue = logRecord.FormattedMessage };
|
||||
}
|
||||
|
||||
if (logRecord.StateValues != null)
|
||||
{
|
||||
foreach (var stateValue in logRecord.StateValues)
|
||||
{
|
||||
var otlpAttribute = stateValue.ToOtlpAttribute();
|
||||
otlpLogRecord.Attributes.Add(otlpAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
if (logRecord.EventId != 0)
|
||||
{
|
||||
otlpLogRecord.Attributes.AddAttribute(nameof(logRecord.EventId), logRecord.EventId.ToString());
|
||||
otlpLogRecord.Attributes.AddStringAttribute(nameof(logRecord.EventId), logRecord.EventId.ToString());
|
||||
}
|
||||
|
||||
if (logRecord.Exception != null)
|
||||
{
|
||||
otlpLogRecord.Attributes.AddAttribute(SemanticConventions.AttributeExceptionType, logRecord.Exception.GetType().Name);
|
||||
otlpLogRecord.Attributes.AddAttribute(SemanticConventions.AttributeExceptionMessage, logRecord.Exception.Message);
|
||||
otlpLogRecord.Attributes.AddAttribute(SemanticConventions.AttributeExceptionStacktrace, logRecord.Exception.ToInvariantString());
|
||||
otlpLogRecord.Attributes.AddStringAttribute(SemanticConventions.AttributeExceptionType, logRecord.Exception.GetType().Name);
|
||||
otlpLogRecord.Attributes.AddStringAttribute(SemanticConventions.AttributeExceptionMessage, logRecord.Exception.Message);
|
||||
otlpLogRecord.Attributes.AddStringAttribute(SemanticConventions.AttributeExceptionStacktrace, logRecord.Exception.ToInvariantString());
|
||||
}
|
||||
|
||||
if (logRecord.TraceId != default && logRecord.SpanId != default)
|
||||
|
|
@ -107,7 +116,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
|
|||
return otlpLogRecord;
|
||||
}
|
||||
|
||||
private static void AddAttribute(this RepeatedField<OtlpCommon.KeyValue> repeatedField, string key, string value)
|
||||
private static void AddStringAttribute(this RepeatedField<OtlpCommon.KeyValue> repeatedField, string key, string value)
|
||||
{
|
||||
repeatedField.Add(new OtlpCommon.KeyValue
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue