diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props index 766e1247f7f..f73620c7058 100644 --- a/build/Common.nonprod.props +++ b/build/Common.nonprod.props @@ -33,7 +33,7 @@ [0.13.5,0.14) [2.9.1,3.0) [2.3.1,3.0) - [3.22.0,4.0) + [3.19.4,4.0) [2.50.0,3.0) [2.48.0, 3.0) [2.48.0,3.0) diff --git a/build/Common.props b/build/Common.props index a3c3e048d32..6a782db69a8 100644 --- a/build/Common.props +++ b/build/Common.props @@ -27,7 +27,7 @@ Refer to https://docs.microsoft.com/nuget/concepts/package-versioning for semver syntax. --> [4.2.0,5.0) - [3.22.0,4.0) + [3.19.4,4.0) [2.44.0,3.0) [2.43.0,3.0) [2.44.0,3.0) @@ -49,6 +49,7 @@ [1.2.0-beta.435,2.0) 1.4.0 7.0.0 + 4.7.0 4.7.2 4.7.2 4.5.4 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index 7152d0ca418..724f86e094e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* Revert version of `Google.Protobuf` to `3.19.4` (see + [#4201](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4201)). + This also reintroduces the `System.Reflection.Emit.Lightweight` dependency. + ([#4407](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4407)) + ## 1.5.0-alpha.2 Released 2023-Mar-31 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs index 23bf82cb24a..10896a2d50d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs @@ -16,8 +16,11 @@ using System.Collections.Concurrent; using System.Diagnostics; +using System.Reflection; +using System.Reflection.Emit; using System.Runtime.CompilerServices; using Google.Protobuf; +using Google.Protobuf.Collections; using OpenTelemetry.Internal; using OpenTelemetry.Proto.Collector.Trace.V1; using OpenTelemetry.Proto.Common.V1; @@ -31,6 +34,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation internal static class ActivityExtensions { private static readonly ConcurrentBag SpanListPool = new(); + private static readonly Action, int> RepeatedFieldOfSpanSetCountAction = CreateRepeatedFieldOfSpanSetCountAction(); internal static void AddBatch( this ExportTraceServiceRequest request, @@ -80,7 +84,7 @@ internal static void Return(this ExportTraceServiceRequest request) foreach (var scope in resourceSpans.ScopeSpans) { - scope.Spans.Clear(); + RepeatedFieldOfSpanSetCountAction(scope.Spans, 0); SpanListPool.Add(scope); } } @@ -294,6 +298,27 @@ private static Span.Types.Event ToOtlpEvent(in ActivityEvent activityEvent, SdkL return otlpEvent; } + private static Action, int> CreateRepeatedFieldOfSpanSetCountAction() + { + FieldInfo repeatedFieldOfSpanCountField = typeof(RepeatedField).GetField("count", BindingFlags.NonPublic | BindingFlags.Instance); + + DynamicMethod dynamicMethod = new DynamicMethod( + "CreateSetCountAction", + null, + new[] { typeof(RepeatedField), typeof(int) }, + typeof(ActivityExtensions).Module, + skipVisibility: true); + + var generator = dynamicMethod.GetILGenerator(); + + generator.Emit(OpCodes.Ldarg_0); + generator.Emit(OpCodes.Ldarg_1); + generator.Emit(OpCodes.Stfld, repeatedFieldOfSpanCountField); + generator.Emit(OpCodes.Ret); + + return (Action, int>)dynamicMethod.CreateDelegate(typeof(Action, int>)); + } + private struct TagEnumerationState : PeerServiceResolver.IPeerServiceState { public SdkLimitOptions SdkLimitOptions; diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs index c839a771f1e..44f096c22f2 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs @@ -15,6 +15,8 @@ // using System.Collections.Concurrent; +using System.Reflection; +using System.Reflection.Emit; using System.Runtime.CompilerServices; using Google.Protobuf; using Google.Protobuf.Collections; @@ -29,6 +31,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation internal static class MetricItemExtensions { private static readonly ConcurrentBag MetricListPool = new(); + private static readonly Action, int> RepeatedFieldOfMetricSetCountAction = CreateRepeatedFieldOfMetricSetCountAction(); internal static void AddMetrics( this OtlpCollector.ExportMetricsServiceRequest request, @@ -79,7 +82,7 @@ internal static void Return(this OtlpCollector.ExportMetricsServiceRequest reque foreach (var scope in resourceMetrics.ScopeMetrics) { - scope.Metrics.Clear(); + RepeatedFieldOfMetricSetCountAction(scope.Metrics, 0); MetricListPool.Add(scope); } } @@ -422,5 +425,26 @@ private static OtlpMetrics.Exemplar ToOtlpExemplar(this IExemplar exemplar) return otlpExemplar; } */ + + private static Action, int> CreateRepeatedFieldOfMetricSetCountAction() + { + FieldInfo repeatedFieldOfMetricCountField = typeof(RepeatedField).GetField("count", BindingFlags.NonPublic | BindingFlags.Instance); + + DynamicMethod dynamicMethod = new DynamicMethod( + "CreateSetCountAction", + null, + new[] { typeof(RepeatedField), typeof(int) }, + typeof(MetricItemExtensions).Module, + skipVisibility: true); + + var generator = dynamicMethod.GetILGenerator(); + + generator.Emit(OpCodes.Ldarg_0); + generator.Emit(OpCodes.Ldarg_1); + generator.Emit(OpCodes.Stfld, repeatedFieldOfMetricCountField); + generator.Emit(OpCodes.Ret); + + return (Action, int>)dynamicMethod.CreateDelegate(typeof(Action, int>)); + } } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj index a73abbb7f77..fd1754cc455 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj @@ -19,6 +19,7 @@ +