Remove SpanExporter from otlp (#794)

renaming class/file

renaming to exporterRequest

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
Eddy Nakamura 2020-07-10 03:54:36 -03:00 committed by GitHub
parent b7b0b2cd92
commit d237438115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 226 deletions

View File

@ -47,7 +47,7 @@ namespace Samples
(RedisOptions options) => TestRedis.Run(options.Uri),
(ZPagesOptions options) => TestZPages.Run(),
(ConsoleOptions options) => TestConsoleExporter.Run(options),
(OtlpOptions options) => TestOtlp.Run(options.Endpoint),
(OtlpOptions options) => TestOtlpExporter.Run(options.Endpoint),
errs => 1);
Console.ReadLine();

View File

@ -1,4 +1,4 @@
// <copyright file="TestOtlp.cs" company="OpenTelemetry Authors">
// <copyright file="TestOtlpExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -15,15 +15,13 @@
// </copyright>
using System;
using Grpc.Core;
using OpenTelemetry.Exporter.OpenTelemetryProtocol;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Configuration;
namespace Samples
{
internal static class TestOtlp
internal static class TestOtlpExporter
{
internal static object Run(string endpoint)
{
@ -38,7 +36,7 @@ namespace Samples
builder => builder
.AddActivitySource("Samples.SampleServer")
.AddActivitySource("Samples.SampleClient")
.UseOpenTelemetryProtocolActivityExporter(opt => opt.Endpoint = endpoint));
.UseOtlpExporter(opt => opt.Endpoint = endpoint));
// The above line is required only in Applications
// which decide to use OT.

View File

@ -31,7 +31,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
/// <param name="configure">Exporter configuration options.</param>
/// <param name="processorConfigure">Activity processor configuration.</param>
/// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
public static OpenTelemetryBuilder UseOpenTelemetryProtocolActivityExporter(this OpenTelemetryBuilder builder, Action<ExporterOptions> configure = null, Action<ActivityProcessorPipelineBuilder> processorConfigure = null)
public static OpenTelemetryBuilder UseOtlpExporter(this OpenTelemetryBuilder builder, Action<OtlpExporterOptions> configure = null, Action<ActivityProcessorPipelineBuilder> processorConfigure = null)
{
if (builder == null)
{
@ -40,10 +40,10 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
return builder.AddProcessorPipeline(pipeline =>
{
var exporterOptions = new ExporterOptions();
var exporterOptions = new OtlpExporterOptions();
configure?.Invoke(exporterOptions);
var activityExporter = new OtlpActivityExporter(exporterOptions);
var activityExporter = new OtlpExporter(exporterOptions);
processorConfigure?.Invoke(pipeline);
pipeline.SetExporter(activityExporter);
});

View File

@ -1,58 +0,0 @@
// <copyright file="OtlpActivityExporter.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.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Trace.Export;
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
{
/// <summary>
/// Exporter consuming <see cref="Activity"/> and exporting the data using
/// the OpenTelemetry protocol (OTLP).
/// </summary>
public class OtlpActivityExporter : ActivityExporter
{
private readonly TraceExporter traceExporter;
/// <summary>
/// Initializes a new instance of the <see cref="OtlpActivityExporter"/> class.
/// </summary>
/// <param name="options">Configuration options for the exporter.</param>
public OtlpActivityExporter(ExporterOptions options)
{
this.traceExporter = new TraceExporter(options);
}
/// <inheritdoc/>
public override Task<ExportResult> ExportAsync(
IEnumerable<Activity> activityBatch,
CancellationToken cancellationToken)
{
return this.traceExporter.ExportAsync(activityBatch.ToOtlpResourceSpans(), cancellationToken);
}
/// <inheritdoc/>
public override Task ShutdownAsync(CancellationToken cancellationToken)
{
return this.traceExporter.ShutdownAsync(cancellationToken);
}
}
}

View File

@ -1,4 +1,4 @@
// <copyright file="TraceExporter.cs" company="OpenTelemetry Authors">
// <copyright file="OtlpExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -15,6 +15,7 @@
// </copyright>
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
@ -24,40 +25,41 @@ using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Trace.Export;
using OtlpCollector = Opentelemetry.Proto.Collector.Trace.V1;
using OtlpTrace = Opentelemetry.Proto.Trace.V1;
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
{
/// <summary>
/// The trace exporter using the OpenTelemetry protocol (OTLP).
/// Exporter consuming <see cref="Activity"/> and exporting the data using
/// the OpenTelemetry protocol (OTLP).
/// </summary>
internal class TraceExporter
public class OtlpExporter : ActivityExporter
{
private readonly Channel channel;
private readonly OtlpCollector.TraceService.TraceServiceClient traceClient;
private readonly Metadata headers;
/// <summary>
/// Initializes a new instance of the <see cref="TraceExporter"/> class.
/// Initializes a new instance of the <see cref="OtlpExporter"/> class.
/// </summary>
/// <param name="options">Configuration options for the exporter.</param>
internal TraceExporter(ExporterOptions options)
public OtlpExporter(OtlpExporterOptions options)
{
this.headers = options.Headers;
this.channel = new Channel(options.Endpoint, options.Credentials);
this.traceClient = new OtlpCollector.TraceService.TraceServiceClient(this.channel);
}
internal async Task<ExportResult> ExportAsync(
IEnumerable<OtlpTrace.ResourceSpans> resourceSpansList,
/// <inheritdoc/>
public override async Task<ExportResult> ExportAsync(
IEnumerable<Activity> activityBatch,
CancellationToken cancellationToken)
{
var spanExportRequest = new OtlpCollector.ExportTraceServiceRequest();
spanExportRequest.ResourceSpans.AddRange(resourceSpansList);
var exporterRequest = new OtlpCollector.ExportTraceServiceRequest();
exporterRequest.ResourceSpans.AddRange(activityBatch.ToOtlpResourceSpans());
try
{
await this.traceClient.ExportAsync(spanExportRequest, headers: this.headers, cancellationToken: cancellationToken);
await this.traceClient.ExportAsync(exporterRequest, headers: this.headers, cancellationToken: cancellationToken);
}
catch (RpcException ex)
{
@ -69,7 +71,8 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
return ExportResult.Success;
}
internal async Task ShutdownAsync(CancellationToken cancellationToken)
/// <inheritdoc/>
public override async Task ShutdownAsync(CancellationToken cancellationToken)
{
await this.channel.ShutdownAsync().ConfigureAwait(false);
}

View File

@ -1,4 +1,4 @@
// <copyright file="ExporterOptions.cs" company="OpenTelemetry Authors">
// <copyright file="OtlpExporterOptions.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -21,7 +21,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
/// <summary>
/// Configuration options for the OpenTelemetry Protocol (OTLP) exporter.
/// </summary>
public class ExporterOptions
public class OtlpExporterOptions
{
/// <summary>
/// Gets or sets the target to which the exporter is going to send traces or metrics.

View File

@ -1,56 +0,0 @@
// <copyright file="SpanDataExporter.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.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Trace.Export;
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
{
/// <summary>
/// The trace exporter using the OpenTelemetry protocol (OTLP).
/// </summary>
public class SpanDataExporter : SpanExporter
{
private readonly TraceExporter traceExporter;
/// <summary>
/// Initializes a new instance of the <see cref="SpanDataExporter"/> class.
/// </summary>
/// <param name="options">Configuration options for the exporter.</param>
public SpanDataExporter(ExporterOptions options)
{
this.traceExporter = new TraceExporter(options);
}
/// <inheritdoc/>
public override Task<ExportResult> ExportAsync(
IEnumerable<SpanData> spanDataList,
CancellationToken cancellationToken)
{
return this.traceExporter.ExportAsync(spanDataList.ToOtlpResourceSpans(), cancellationToken);
}
/// <inheritdoc/>
public override Task ShutdownAsync(CancellationToken cancellationToken)
{
return this.traceExporter.ShutdownAsync(cancellationToken);
}
}
}

View File

@ -1,87 +0,0 @@
// <copyright file="TracerBuilderExtensions.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 OpenTelemetry.Trace.Configuration;
using OpenTelemetry.Trace.Export;
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
{
/// <summary>
/// Extension methods to simplify registering of the OpenTelemetry Protocol (OTLP) exporter.
/// </summary>
public static class TracerBuilderExtensions
{
/// <summary>
/// Enables OpenTelemetry Protocol (OTLP) exporter.
/// </summary>
/// <param name="builder">Trace builder to use.</param>
/// <param name="configure">Configuration action.</param>
/// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
public static TracerBuilder UseOpenTelemetryProtocolExporter(this TracerBuilder builder, Action<ExporterOptions> configure)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}
var configuration = new ExporterOptions();
configure(configuration);
return builder.AddProcessorPipeline(b => b
.SetExporter(new SpanDataExporter(configuration))
.SetExportingProcessor(e => new BatchingSpanProcessor(e)));
}
/// <summary>
/// Enables OpenTelemetry Protocol (OTLP) exporter.
/// </summary>
/// <param name="builder">Trace builder to use.</param>
/// <param name="configure">Configuration action.</param>
/// <param name="processorConfigure">Span processor configuration action.</param>
/// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
public static TracerBuilder UseOpenTelemetryProtocolExporter(
this TracerBuilder builder, Action<ExporterOptions> configure, Action<SpanProcessorPipelineBuilder> processorConfigure)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}
if (processorConfigure == null)
{
throw new ArgumentNullException(nameof(processorConfigure));
}
var configuration = new ExporterOptions();
configure(configuration);
return builder.AddProcessorPipeline(b =>
{
b.SetExporter(new SpanDataExporter(configuration));
processorConfigure.Invoke(b);
});
}
}
}

View File

@ -232,7 +232,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
.AddActivitySource(ActivitySourceName)
.UseOpenTelemetryProtocolActivityExporter(
.UseOtlpExporter(
null, p => p.AddProcessor((next) => testActivityProcessor)));
var source = new ActivitySource(ActivitySourceName);