From c3312a6d5bf3f060ab676e903c6f00ca3acd0646 Mon Sep 17 00:00:00 2001
From: Alan West <3676547+alanwest@users.noreply.github.com>
Date: Wed, 19 Apr 2023 10:44:41 -0700
Subject: [PATCH 1/3] Revert "[Otlp] Bump Google.Protobuf to 3.22.0 and remove
reflection emit code (#4201)"
This reverts commit f7f535866b3c4cfef19661c4e97b41cf3a2091df.
---
build/Common.nonprod.props | 2 +-
build/Common.props | 3 ++-
.../Implementation/ActivityExtensions.cs | 27 ++++++++++++++++++-
.../Implementation/MetricItemExtensions.cs | 26 +++++++++++++++++-
...etry.Exporter.OpenTelemetryProtocol.csproj | 1 +
5 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props
index 2f550fb8ff0..4a4f0d36ae7 100644
--- a/build/Common.nonprod.props
+++ b/build/Common.nonprod.props
@@ -33,7 +33,7 @@
[0.13.3,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/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 @@
+
From 8608f2554c82de84da4429d7bd2dc5982361c09d Mon Sep 17 00:00:00 2001
From: Alan West <3676547+alanwest@users.noreply.github.com>
Date: Wed, 19 Apr 2023 10:48:44 -0700
Subject: [PATCH 2/3] Update changelog
---
.../CHANGELOG.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
index 7152d0ca418..c614f6fd1be 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.
+ ([#TBD](https://github.com/open-telemetry/opentelemetry-dotnet/pull/TBD))
+
## 1.5.0-alpha.2
Released 2023-Mar-31
From 9f03e705dbcd4262dd66863d617e8c3f41f5426b Mon Sep 17 00:00:00 2001
From: Alan West <3676547+alanwest@users.noreply.github.com>
Date: Wed, 19 Apr 2023 10:52:26 -0700
Subject: [PATCH 3/3] Update changelog
---
src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
index c614f6fd1be..724f86e094e 100644
--- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
+++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
@@ -5,7 +5,7 @@
* 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.
- ([#TBD](https://github.com/open-telemetry/opentelemetry-dotnet/pull/TBD))
+ ([#4407](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4407))
## 1.5.0-alpha.2