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 all commits
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 @@ -12,6 +12,10 @@
TimeoutMilliseconds for computing the `deadline` to be used by gRPC client for
`Export`
([#1781](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1781))
* Removes Grpc specific options from OTLPExporterOptions, which removes support
for secure connections. See [1778](https://github.com/open-telemetry/opentelemetry-dotnet/issues/1778)
for details.
* Endpoint is made Uri for all target frameworks.

## 1.0.0-rc2

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,13 @@ 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.
/// Gets or sets the target to which the exporter is going to send traces.
/// Must be a valid Uri with scheme (http) and host, and
/// may contain a port and path. Secure connection(https) is not
/// supported.
/// </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 NotSupportedException("Https Endpoint is not supported.");
}

#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
6 changes: 4 additions & 2 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
You can configure the `OtlpExporter` through `OtlpExporterOptions` properties:

* `Endpoint`: Target to which the exporter is going to send traces or metrics.
* `Credentials`: Client-side channel credentials.
The endpoint must be a valid Uri with scheme (http) and host, and
MAY contain a port and path. In 1.0, secure connection(https) is *NOT*
supported.
* `Headers`: Optional headers for the connection.
* `ChannelOptions`: gRPC channel options.
* `TimeoutMilliseconds` : Max waiting time for the backend to process a batch.
* `ExportProcessorType`: Whether the exporter should use
[Batch or Simple exporting processor](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#built-in-span-processors)
.
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