Context: #7307 (comment)
|
<AllowUnsafeBlocks Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'">true</AllowUnsafeBlocks> |
|
=> ref (span.Length != 0) ? ref Unsafe.AsRef(in MemoryMarshal.GetReference(span)) : ref Unsafe.AsRef<T>((void*)1); |
The OTLP exporter uses unsafe for .NET Standard and .NET Framework for performance reasons.
We also use MemoryMarshal and Unsafe in two places in OpenTelemetry for netX.0 targets:
|
ref var ours = ref MemoryMarshal.GetArrayDataReference(ourKvps); |
|
ref var theirs = ref MemoryMarshal.GetArrayDataReference(theirKvps); |
|
ours = ref Unsafe.Add(ref ours, 1); |
|
theirs = ref Unsafe.Add(ref theirs, 1); |
C# 15 16 in the .NET 11 12 timeframe is looking to make changes to unsafe code to reduce its usage for security reasons, see Unsafe Evolution for further context.
To improve the security posture of the OTLP exporter, we should remove the remaining usages of unsafe code even in the face of potential performance degradation.
A similar attempt was made previously in the core library for the same reason: #6594
This may take a while to achieve as if the degradation is large, we may have to make other changes elsewhere to compensate.
The MemoryMarshal and Unsafe usages may get surfaced in later previews of .NET 11 in #6899.
Context: #7307 (comment)
opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj
Line 21 in b1dd8e8
opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Serializer/ProtobufSerializer.cs
Line 342 in e5efcb6
The OTLP exporter uses
unsafefor .NET Standard and .NET Framework for performance reasons.We also use
MemoryMarshalandUnsafein two places in OpenTelemetry fornetX.0targets:opentelemetry-dotnet/src/OpenTelemetry/Metrics/Tags.cs
Lines 50 to 51 in e5efcb6
opentelemetry-dotnet/src/OpenTelemetry/Metrics/Tags.cs
Lines 69 to 70 in 34dcd84
C#
1516 in the .NET1112 timeframe is looking to make changes to unsafe code to reduce its usage for security reasons, see Unsafe Evolution for further context.To improve the security posture of the OTLP exporter, we should remove the remaining usages of unsafe code even in the face of potential performance degradation.
A similar attempt was made previously in the core library for the same reason: #6594
This may take a while to achieve as if the degradation is large, we may have to make other changes elsewhere to compensate.
The
MemoryMarshalandUnsafeusages may get surfaced in later previews of .NET 11 in #6899.