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

Migrate OtlpExporter to BatchExportActivityProcessor #1104

Merged
merged 5 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

* Allow configurable gRPC channel options
([#1033](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1033))

* Renamed extension method from `UseOtlpExporter` to `AddOtlpExporter`.
* Renamed extension method from `UseOtlpExporter` to `AddOtlpExporter`
* Changed `OtlpExporter` to use `BatchExportActivityProcessor` by default
([#1104](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1104))

## 0.4.0-beta.2

Expand Down
32 changes: 13 additions & 19 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

using Grpc.Core;

using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Trace;

using OtlpCollector = Opentelemetry.Proto.Collector.Trace.V1;

namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
Expand All @@ -32,7 +27,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
/// Exporter consuming <see cref="Activity"/> and exporting the data using
/// the OpenTelemetry protocol (OTLP).
/// </summary>
public class OtlpExporter : ActivityExporter
public class OtlpExporter : ActivityExporterSync
{
private readonly Channel channel;
private readonly OtlpCollector.TraceService.TraceServiceClient traceClient;
Expand All @@ -50,31 +45,30 @@ public OtlpExporter(OtlpExporterOptions options)
}

/// <inheritdoc/>
public override async Task<ExportResult> ExportAsync(
IEnumerable<Activity> activityBatch,
CancellationToken cancellationToken)
public override ExportResultSync Export(in Batch<Activity> activityBatch)
{
var exporterRequest = new OtlpCollector.ExportTraceServiceRequest();
exporterRequest.ResourceSpans.AddRange(activityBatch.ToOtlpResourceSpans());

var activities = new List<Activity>();
foreach (var activity in activityBatch)
{
activities.Add(activity);
}

exporterRequest.ResourceSpans.AddRange(activities.ToOtlpResourceSpans());

try
{
await this.traceClient.ExportAsync(exporterRequest, headers: this.headers, cancellationToken: cancellationToken);
this.traceClient.Export(exporterRequest, headers: this.headers);
}
catch (RpcException ex)
{
OpenTelemetryProtocolExporterEventSource.Log.FailedToReachCollector(ex);

return ExportResult.FailedRetryable;
return ExportResultSync.Failure;
}

return ExportResult.Success;
}

/// <inheritdoc/>
public override async Task ShutdownAsync(CancellationToken cancellationToken)
{
await this.channel.ShutdownAsync().ConfigureAwait(false);
return ExportResultSync.Success;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b
var otlpExporter = new OtlpExporter(exporterOptions);

// TODO: Pick Simple vs Batching based on OtlpExporterOptions
return builder.AddProcessor(new SimpleActivityProcessor(otlpExporter));
return builder.AddProcessor(new BatchExportActivityProcessor(otlpExporter));
}
}
}