Skip to content
Merged
20 changes: 20 additions & 0 deletions src/OpenTelemetry.Exporter.InMemory/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if !EXPOSE_EXPERIMENTAL_FEATURES
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests" + AssemblyInfo.PublicKey)]
#endif

#if SIGNED
file static class AssemblyInfo
{
public const string PublicKey = ", PublicKey=002400000480000094000000060200000024000052534131000400000100010051C1562A090FB0C9F391012A32198B5E5D9A60E9B80FA2D7B434C9E5CCB7259BD606E66F9660676AFC6692B8CDC6793D190904551D2103B7B22FA636DCBB8208839785BA402EA08FC00C8F1500CCEF28BBF599AA64FFB1E1D5DC1BF3420A3777BADFE697856E9D52070A50C3EA5821C80BEF17CA3ACFFA28F89DD413F096F898";
}
#else
file static class AssemblyInfo
{
public const string PublicKey = "";
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
will be automatically included in exports.
([#5258](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5258))

* **Experimental (pre-release builds only):** Added
support for `Body` set directly on `LogRecord` via the Logs Bridge API.
[#5268](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5268)

## 1.7.0

Released 2023-Dec-08
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ internal OtlpLogs.LogRecord ToOtlpLog(LogRecord logRecord)
AddAttribute(otlpLogRecord, result, attributeCountLimit);
}
}

// Supports Body set directly on LogRecord for the Logs Bridge API.
if (otlpLogRecord.Body == null && logRecord.Body != null)
{
// If {OriginalFormat} is not present in the attributes,
// use logRecord.Body if it is set.
otlpLogRecord.Body = new OtlpCommon.AnyValue { StringValue = logRecord.Body };
}
}

if (logRecord.TraceId != default && logRecord.SpanId != default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,32 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage)
Assert.Equal("state", otlpLogRecord.Body.StringValue);
}

[Fact]
public void LogRecordBodyIsExportedWhenUsingBridgeApi()
{
var logRecords = new List<LogRecord>();

using (var loggerProvider = Sdk.CreateLoggerProviderBuilder()
.AddInMemoryExporter(logRecords)
.Build())
{
var logger = loggerProvider.GetLogger();

logger.EmitLog(new LogRecordData()
{
Body = "Hello world",
});
}

Assert.Single(logRecords);

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

var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecords[0]);

Assert.Equal("Hello world", otlpLogRecord.Body?.StringValue);
}

[Fact]
public void CheckToOtlpLogRecordExceptionAttributes()
{
Expand Down