Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenevaTraceExporter bug fix to not export activities not sampled in #352

Merged
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Throw exception when `TableNameMappings` contains a `null` value.
[322](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/322)

* TraceExporter bug fix to not export non-recorded Activities.
[352](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/352)

## 1.2.6 [2022-Apr-21]

* Set GenevaMetricExporter temporality preference back to Delta.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System;
using System.Diagnostics;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;

Expand Down Expand Up @@ -48,7 +47,7 @@ private static TracerProviderBuilder AddGenevaTraceExporter(this TracerProviderB
}
else
{
return builder.AddProcessor(new ReentrantExportProcessor<Activity>(exporter));
return builder.AddProcessor(new ReentrantActivityExportProcessor(exporter));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// <copyright file="ReentrantActivityExportProcessor.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;

namespace OpenTelemetry.Exporter.Geneva;

// This export processor exports without synchronization.
// Once OpenTelemetry .NET officially support this,
// we can get rid of this class.
// This is currently only used in ETW export, where we know
// that the underlying system is safe under concurrent calls.
internal class ReentrantActivityExportProcessor : BaseExportProcessor<Activity>
{
static ReentrantActivityExportProcessor()
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
{
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
var ctor = typeof(Batch<Activity>).GetConstructor(flags, null, new Type[] { typeof(Activity) }, null);
var value = Expression.Parameter(typeof(Activity), null);
var lambda = Expression.Lambda<Func<Activity, Batch<Activity>>>(Expression.New(ctor, value), value);
CreateBatch = lambda.Compile();
}

public ReentrantActivityExportProcessor(BaseExporter<Activity> exporter)
: base(exporter)
{
}

protected override void OnExport(Activity data)
{
if (data.Recorded)
{
this.exporter.Export(CreateBatch(data));
}
}

private static readonly Func<Activity, Batch<Activity>> CreateBatch;
}