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

Remove grpc class options from OTLPExporter. Make Endpoint Uri for all frameworks #1789

Merged
merged 3 commits into from
Feb 5, 2021
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
2 changes: 1 addition & 1 deletion examples/AspNetCore/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
},
"Otlp": {
"ServiceName": "otlp-test",
"Endpoint": "localhost:4317"
"Endpoint": "http://localhost:4317"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ OpenTelemetry.Exporter.OtlpTraceExporter.OtlpTraceExporter(OpenTelemetry.Exporte
OpenTelemetry.Exporter.OtlpExporterOptions
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.get -> OpenTelemetry.BatchExportProcessorOptions<System.Diagnostics.Activity>
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ChannelOptions.get -> System.Collections.Generic.IEnumerable<Grpc.Core.ChannelOption>
OpenTelemetry.Exporter.OtlpExporterOptions.ChannelOptions.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Credentials.get -> Grpc.Core.ChannelCredentials
OpenTelemetry.Exporter.OtlpExporterOptions.Credentials.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> System.Uri
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.set -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ OpenTelemetry.Exporter.OtlpTraceExporter.OtlpTraceExporter(OpenTelemetry.Exporte
OpenTelemetry.Exporter.OtlpExporterOptions
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.get -> OpenTelemetry.BatchExportProcessorOptions<System.Diagnostics.Activity>
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ChannelOptions.get -> System.Collections.Generic.IEnumerable<Grpc.Core.ChannelOption>
OpenTelemetry.Exporter.OtlpExporterOptions.ChannelOptions.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Credentials.get -> Grpc.Core.ChannelCredentials
OpenTelemetry.Exporter.OtlpExporterOptions.Credentials.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> System.Uri
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.set -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ OpenTelemetry.Exporter.OtlpTraceExporter.OtlpTraceExporter(OpenTelemetry.Exporte
OpenTelemetry.Exporter.OtlpExporterOptions
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.get -> OpenTelemetry.BatchExportProcessorOptions<System.Diagnostics.Activity>
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ChannelOptions.get -> System.Collections.Generic.IEnumerable<Grpc.Core.ChannelOption>
OpenTelemetry.Exporter.OtlpExporterOptions.ChannelOptions.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Credentials.get -> Grpc.Core.ChannelCredentials
OpenTelemetry.Exporter.OtlpExporterOptions.Credentials.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> System.Uri
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.set -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ OpenTelemetry.Exporter.OtlpTraceExporter.OtlpTraceExporter(OpenTelemetry.Exporte
OpenTelemetry.Exporter.OtlpExporterOptions
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.get -> OpenTelemetry.BatchExportProcessorOptions<System.Diagnostics.Activity>
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.GrpcChannelOptions.get -> Grpc.Net.Client.GrpcChannelOptions
OpenTelemetry.Exporter.OtlpExporterOptions.GrpcChannelOptions.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> System.Uri
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Grpc.Core;
#if NETSTANDARD2_1
using Grpc.Net.Client;
#endif

namespace OpenTelemetry.Exporter
{
Expand All @@ -29,37 +24,10 @@ namespace OpenTelemetry.Exporter
/// </summary>
public class OtlpExporterOptions
{
#if NETSTANDARD2_1
/// <summary>
/// Gets or sets the target to which the exporter is going to send traces or metrics.
/// The valid syntax is described at https://github.com/grpc/grpc/blob/master/doc/naming.md.
/// </summary>
public Uri Endpoint { get; set; } = new Uri("http://localhost:4317");
#else
/// <summary>
/// Gets or sets the target to which the exporter is going to send traces or metrics.
/// The valid syntax is described at https://github.com/grpc/grpc/blob/master/doc/naming.md.
/// </summary>
public string Endpoint { get; set; } = "localhost:4317";
#endif

#if NETSTANDARD2_1
/// <summary>
/// Gets or sets the gRPC channel options.
/// </summary>
public GrpcChannelOptions GrpcChannelOptions { get; set; }
#else
/// <summary>
/// Gets or sets the client-side channel credentials. Used for creation of a secure channel.
/// The default is "insecure". See detais at https://grpc.io/docs/guides/auth/#credential-types.
/// </summary>
public ChannelCredentials Credentials { get; set; } = ChannelCredentials.Insecure;

/// <summary>
/// Gets or sets the gRPC channel options.
/// </summary>
public IEnumerable<ChannelOption> ChannelOptions { get; set; }
#endif

/// <summary>
/// Gets or sets optional headers for the connection. Refer to the <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class OtlpTraceExporter : BaseExporter<Activity>
#endif
private readonly OtlpCollector.TraceService.ITraceServiceClient traceClient;
private readonly Metadata headers;
private DateTime deadline;

/// <summary>
/// Initializes a new instance of the <see cref="OtlpTraceExporter"/> class.
Expand Down Expand Up @@ -76,12 +75,15 @@ internal OtlpTraceExporter(OtlpExporterOptions options, OtlpCollector.TraceServi
}
else
{
if (options.Endpoint.Scheme == Uri.UriSchemeHttps)
{
throw new ArgumentException("Https Endpoint is not supported.");
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
}

#if NETSTANDARD2_1
this.channel = options.GrpcChannelOptions == default
? GrpcChannel.ForAddress(options.Endpoint)
: GrpcChannel.ForAddress(options.Endpoint, options.GrpcChannelOptions);
this.channel = GrpcChannel.ForAddress(options.Endpoint);
#else
this.channel = new Channel(options.Endpoint, options.Credentials, options.ChannelOptions);
this.channel = new Channel(options.Endpoint.Authority, ChannelCredentials.Insecure);
#endif
this.traceClient = new OtlpCollector.TraceService.TraceServiceClient(this.channel);
}
Expand All @@ -103,11 +105,11 @@ public override ExportResult Export(in Batch<Activity> activityBatch)
OtlpCollector.ExportTraceServiceRequest request = new OtlpCollector.ExportTraceServiceRequest();

request.AddBatch(this.ProcessResource, activityBatch);
this.deadline = DateTime.UtcNow.AddMilliseconds(this.options.TimeoutMilliseconds);
var deadline = DateTime.UtcNow.AddMilliseconds(this.options.TimeoutMilliseconds);

try
{
this.traceClient.Export(request, headers: this.headers, deadline: this.deadline);
this.traceClient.Export(request, headers: this.headers, deadline: deadline);
}
catch (RpcException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public void ExportResultIsSuccess()

var exporterOptions = new OtlpExporterOptions
{
#if NETCOREAPP3_1 || NET5_0
Endpoint = new System.Uri($"http://{CollectorEndpoint}"),
#else
Endpoint = CollectorEndpoint,
#endif
};

var otlpExporter = new OtlpTraceExporter(exporterOptions);
Expand Down