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

Update OtlpExporter options #1781

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> Grpc.Core.Metadata
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.OtlpExporterOptions() -> void
OpenTelemetry.Exporter.OtlpExporterOptions.TimeoutMilliseconds.get -> int?
OpenTelemetry.Exporter.OtlpExporterOptions.TimeoutMilliseconds.set -> void
OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions
override OpenTelemetry.Exporter.OtlpTraceExporter.Export(in OpenTelemetry.Batch<System.Diagnostics.Activity> activityBatch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.OtlpTraceExporter.OnShutdown(int timeoutMilliseconds) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> Grpc.Core.Metadata
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.OtlpExporterOptions() -> void
OpenTelemetry.Exporter.OtlpExporterOptions.TimeoutMilliseconds.get -> int?
OpenTelemetry.Exporter.OtlpExporterOptions.TimeoutMilliseconds.set -> void
OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions
override OpenTelemetry.Exporter.OtlpTraceExporter.Export(in OpenTelemetry.Batch<System.Diagnostics.Activity> activityBatch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.OtlpTraceExporter.OnShutdown(int timeoutMilliseconds) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
OpenTelemetry.Exporter.OtlpExporterOptions.ExportProcessorType.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> Grpc.Core.Metadata
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.OtlpExporterOptions() -> void
OpenTelemetry.Exporter.OtlpExporterOptions.TimeoutMilliseconds.get -> int?
OpenTelemetry.Exporter.OtlpExporterOptions.TimeoutMilliseconds.set -> void
OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions
override OpenTelemetry.Exporter.OtlpTraceExporter.Export(in OpenTelemetry.Batch<System.Diagnostics.Activity> activityBatch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.OtlpTraceExporter.OnShutdown(int timeoutMilliseconds) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ 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
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> Grpc.Core.Metadata
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> string
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.set -> void
OpenTelemetry.Exporter.OtlpExporterOptions.OtlpExporterOptions() -> void
OpenTelemetry.Exporter.OtlpExporterOptions.TimeoutMilliseconds.get -> int?
OpenTelemetry.Exporter.OtlpExporterOptions.TimeoutMilliseconds.set -> void
OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions
override OpenTelemetry.Exporter.OtlpTraceExporter.Export(in OpenTelemetry.Batch<System.Diagnostics.Activity> activityBatch) -> OpenTelemetry.ExportResult
override OpenTelemetry.Exporter.OtlpTraceExporter.OnShutdown(int timeoutMilliseconds) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
`OpenTelemetry.Exporter` namespace.
([#1770](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1770))
* Changed default port for OTLP Exporter from 55680 to 4317
* Default ServiceName, if not found in Resource, is obtained from SDK
using GetDefaultResource().
* Default ServiceName, if not found in Resource, is obtained from SDK using
GetDefaultResource().
* Modified the data type of Headers option to string; Added a private method
utpilla marked this conversation as resolved.
Show resolved Hide resolved
GetMetadataFromHeaders to create a metadata object from the headers passed as
a string in the options; Added a new option called TimeoutMilliseconds for
computing the `deadline` to be used by gRPC client for `Export`
([#1781](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1781))

## 1.0.0-rc2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ public class OtlpExporterOptions
#endif

/// <summary>
/// Gets or sets optional headers for the connection.
/// 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">
/// specification</a> for information on the expected format for Headers.
/// </summary>
public Metadata Headers { get; set; } = new Metadata();
public string Headers { get; set; }
utpilla marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets the max waiting time (in milliseconds) for the backend to process each span.
/// </summary>
public int? TimeoutMilliseconds { get; set; }
utpilla marked this conversation as resolved.
Show resolved Hide resolved
cijothomas marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets the export processor type to be used with the OpenTelemetry Protocol Exporter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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 All @@ -63,7 +64,7 @@ public OtlpTraceExporter(OtlpExporterOptions options)
internal OtlpTraceExporter(OtlpExporterOptions options, OtlpCollector.TraceService.ITraceServiceClient traceServiceClient = null)
{
this.options = options ?? throw new ArgumentNullException(nameof(options));
this.headers = options.Headers ?? throw new ArgumentException("Headers were not provided on options.", nameof(options));
this.headers = GetMetadataFromHeaders(options.Headers);
if (traceServiceClient != null)
{
this.traceClient = traceServiceClient;
Expand Down Expand Up @@ -98,9 +99,21 @@ public override ExportResult Export(in Batch<Activity> activityBatch)

request.AddBatch(this.ProcessResource, activityBatch);

if (this.options.TimeoutMilliseconds.HasValue)
{
if (this.options.TimeoutMilliseconds.Value <= 0)
{
throw new ArgumentException("Timeout value provided is not a positive number.", nameof(this.options.TimeoutMilliseconds));
utpilla marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
this.deadline = DateTime.UtcNow.AddMilliseconds(this.options.TimeoutMilliseconds.Value);
}
}

try
{
this.traceClient.Export(request, headers: this.headers);
this.traceClient.Export(request, headers: this.headers, deadline: this.deadline);
utpilla marked this conversation as resolved.
Show resolved Hide resolved
}
catch (RpcException ex)
{
Expand Down Expand Up @@ -159,5 +172,29 @@ protected override bool OnShutdown(int timeoutMilliseconds)

return Task.WaitAny(new Task[] { this.channel.ShutdownAsync(), Task.Delay(timeoutMilliseconds) }) == 0;
}

private static Metadata GetMetadataFromHeaders(string headers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need unit test for this. (okay to add in separate PR)

{
var metadata = new Metadata();
if (!string.IsNullOrEmpty(headers))
{
Array.ForEach(
headers.Split(','),
(pair) =>
{
var keyValueData = pair.Split('=');
if (keyValueData.Length != 2)
{
throw new ArgumentException("Headers provided in an invalid format.");
}

var key = keyValueData[0].Trim();
var value = keyValueData[1].Trim();
metadata.Add(key, value);
});
}

return metadata;
}
}
}