diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index b4845a9dfbc..71a6ff7afec 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -4,8 +4,10 @@ * 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` + ([#1066](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1066)) +* Changed `OtlpExporter` to use `BatchExportActivityProcessor` by default + ([#1104](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1104)) ## 0.4.0-beta.2 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs index fca8ad968bf..8f6abf4b564 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs @@ -201,12 +201,15 @@ private static OtlpTrace.Span.Types.Link ToOtlpLink(ActivityLink activityLink) SpanId = ByteString.CopyFrom(spanIdBytes.ToArray()), }; - foreach (var attribute in from tag in activityLink.Tags - let attribute = ToOtlpAttributes(tag) - where attribute != null && attribute.Any() - select attribute) + if (activityLink.Tags != null) { - otlpLink.Attributes.AddRange(attribute); + foreach (var attribute in from tag in activityLink.Tags + let attribute = ToOtlpAttributes(tag) + where attribute != null && attribute.Any() + select attribute) + { + otlpLink.Attributes.AddRange(attribute); + } } return otlpLink; diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs index 0c48d793702..32e955b807e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs @@ -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 @@ -32,7 +27,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol /// Exporter consuming and exporting the data using /// the OpenTelemetry protocol (OTLP). /// - public class OtlpExporter : ActivityExporter + public class OtlpExporter : ActivityExporterSync { private readonly Channel channel; private readonly OtlpCollector.TraceService.TraceServiceClient traceClient; @@ -50,31 +45,30 @@ public OtlpExporter(OtlpExporterOptions options) } /// - public override async Task ExportAsync( - IEnumerable activityBatch, - CancellationToken cancellationToken) + public override ExportResultSync Export(in Batch activityBatch) { var exporterRequest = new OtlpCollector.ExportTraceServiceRequest(); - exporterRequest.ResourceSpans.AddRange(activityBatch.ToOtlpResourceSpans()); + + var activities = new List(); + 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; - } - - /// - public override async Task ShutdownAsync(CancellationToken cancellationToken) - { - await this.channel.ShutdownAsync().ConfigureAwait(false); + return ExportResultSync.Success; } } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterHelperExtensions.cs index bc71ebc89bc..260a256be62 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterHelperExtensions.cs @@ -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)); } } }