Skip to content

Commit

Permalink
[Otlp] Bump Google.Protobuf to 3.22.0 and remove reflection emit code (
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Feb 25, 2023
1 parent a3ec494 commit f7f5358
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 55 deletions.
2 changes: 1 addition & 1 deletion build/Common.nonprod.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<BenchmarkDotNetPkgVer>[0.13.3,0.14)</BenchmarkDotNetPkgVer>
<CommandLineParserPkgVer>[2.9.1,3.0)</CommandLineParserPkgVer>
<DotNetXUnitCliVer>[2.3.1,3.0)</DotNetXUnitCliVer>
<GoogleProtobufPkgVer>[3.19.4,4.0)</GoogleProtobufPkgVer>
<GoogleProtobufPkgVer>[3.22.0,4.0)</GoogleProtobufPkgVer>
<GrpcAspNetCorePkgVer>[2.50.0,3.0)</GrpcAspNetCorePkgVer>
<GrpcAspNetCoreServerPkgVer>[2.48.0, 3.0)</GrpcAspNetCoreServerPkgVer>
<GrpcToolsPkgVer>[2.48.0,3.0)</GrpcToolsPkgVer>
Expand Down
3 changes: 1 addition & 2 deletions build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Refer to https://docs.microsoft.com/nuget/concepts/package-versioning for semver syntax.
-->
<MinVerPkgVer>[4.2.0,5.0)</MinVerPkgVer>
<GoogleProtobufPkgVer>[3.19.4,4.0)</GoogleProtobufPkgVer>
<GoogleProtobufPkgVer>[3.22.0,4.0)</GoogleProtobufPkgVer>
<GrpcPkgVer>[2.44.0,3.0)</GrpcPkgVer>
<GrpcNetClientPkgVer>[2.43.0,3.0)</GrpcNetClientPkgVer>
<GrpcToolsPkgVer>[2.44.0,3.0)</GrpcToolsPkgVer>
Expand All @@ -49,7 +49,6 @@
<StyleCopAnalyzersPkgVer>[1.2.0-beta.435,2.0)</StyleCopAnalyzersPkgVer>
<SystemCollectionsImmutablePkgVer>1.4.0</SystemCollectionsImmutablePkgVer>
<SystemDiagnosticSourcePkgVer>7.0.0</SystemDiagnosticSourcePkgVer>
<SystemReflectionEmitLightweightPkgVer>4.7.0</SystemReflectionEmitLightweightPkgVer>
<SystemTextJsonPkgVer>4.7.2</SystemTextJsonPkgVer>
<SystemThreadingTasksExtensionsPkgVer>4.5.4</SystemThreadingTasksExtensionsPkgVer>
</PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Bumped the version of `Google.Protobuf` used by the project to `3.22.0` so
that a new performance feature can be used instead of reflection. Removed the
dependency on `System.Reflection.Emit.Lightweight`.
([#4201](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4201))

## 1.4.0

Released 2023-Feb-24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@

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;
Expand All @@ -34,7 +31,6 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
internal static class ActivityExtensions
{
private static readonly ConcurrentBag<ScopeSpans> SpanListPool = new();
private static readonly Action<RepeatedField<Span>, int> RepeatedFieldOfSpanSetCountAction = CreateRepeatedFieldOfSpanSetCountAction();

internal static void AddBatch(
this ExportTraceServiceRequest request,
Expand Down Expand Up @@ -84,7 +80,7 @@ internal static void Return(this ExportTraceServiceRequest request)

foreach (var scope in resourceSpans.ScopeSpans)
{
RepeatedFieldOfSpanSetCountAction(scope.Spans, 0);
scope.Spans.Clear();
SpanListPool.Add(scope);
}
}
Expand Down Expand Up @@ -297,27 +293,6 @@ private static Span.Types.Event ToOtlpEvent(in ActivityEvent activityEvent, SdkL
return otlpEvent;
}

private static Action<RepeatedField<Span>, int> CreateRepeatedFieldOfSpanSetCountAction()
{
FieldInfo repeatedFieldOfSpanCountField = typeof(RepeatedField<Span>).GetField("count", BindingFlags.NonPublic | BindingFlags.Instance);

DynamicMethod dynamicMethod = new DynamicMethod(
"CreateSetCountAction",
null,
new[] { typeof(RepeatedField<Span>), 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<RepeatedField<Span>, int>)dynamicMethod.CreateDelegate(typeof(Action<RepeatedField<Span>, int>));
}

private struct TagEnumerationState : PeerServiceResolver.IPeerServiceState
{
public SdkLimitOptions SdkLimitOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// </copyright>

using System.Collections.Concurrent;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using Google.Protobuf.Collections;
using OpenTelemetry.Metrics;
Expand All @@ -30,7 +28,6 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
internal static class MetricItemExtensions
{
private static readonly ConcurrentBag<OtlpMetrics.ScopeMetrics> MetricListPool = new();
private static readonly Action<RepeatedField<OtlpMetrics.Metric>, int> RepeatedFieldOfMetricSetCountAction = CreateRepeatedFieldOfMetricSetCountAction();

internal static void AddMetrics(
this OtlpCollector.ExportMetricsServiceRequest request,
Expand Down Expand Up @@ -81,7 +78,7 @@ internal static void Return(this OtlpCollector.ExportMetricsServiceRequest reque

foreach (var scope in resourceMetrics.ScopeMetrics)
{
RepeatedFieldOfMetricSetCountAction(scope.Metrics, 0);
scope.Metrics.Clear();
MetricListPool.Add(scope);
}
}
Expand Down Expand Up @@ -338,26 +335,5 @@ private static OtlpMetrics.Exemplar ToOtlpExemplar(this IExemplar exemplar)
return otlpExemplar;
}
*/

private static Action<RepeatedField<OtlpMetrics.Metric>, int> CreateRepeatedFieldOfMetricSetCountAction()
{
FieldInfo repeatedFieldOfMetricCountField = typeof(RepeatedField<OtlpMetrics.Metric>).GetField("count", BindingFlags.NonPublic | BindingFlags.Instance);

DynamicMethod dynamicMethod = new DynamicMethod(
"CreateSetCountAction",
null,
new[] { typeof(RepeatedField<OtlpMetrics.Metric>), 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<RepeatedField<OtlpMetrics.Metric>, int>)dynamicMethod.CreateDelegate(typeof(Action<RepeatedField<OtlpMetrics.Metric>, int>));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<PackageReference Include="Grpc" Version="$(GrpcPkgVer)" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net462'" />
<PackageReference Include="Google.Protobuf" Version="$(GoogleProtobufPkgVer)" />
<PackageReference Include="Grpc.Tools" Version="$(GrpcToolsPkgVer)" PrivateAssets="all" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="$(SystemReflectionEmitLightweightPkgVer)" Condition="'$(TargetFramework)' != 'net6.0'" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit f7f5358

Please sign in to comment.