Skip to content

Commit

Permalink
Introduce BatchSpanExportProcessorOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Aug 11, 2021
1 parent 4625407 commit 092ddea
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 99 deletions.
8 changes: 8 additions & 0 deletions src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

* `JaegerExporterOptions.BatchExportProcessorOptions` is initalized with
`BatchSpanExportProcessorOptions` which supports field value overriding
using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`,
`OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`
envionmental variables as defined in the
[specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/sdk-environment-variables.md#batch-span-processor).
([#2219](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2219))

## 1.2.0-alpha1

Released 2021-Jul-23
Expand Down
3 changes: 2 additions & 1 deletion src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Diagnostics;
using System.Security;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Exporter
{
Expand Down Expand Up @@ -82,6 +83,6 @@ public JaegerExporterOptions()
/// <summary>
/// Gets or sets the BatchExportProcessor options. Ignored unless ExportProcessorType is BatchExporter.
/// </summary>
public BatchExportProcessorOptions<Activity> BatchExportProcessorOptions { get; set; } = new BatchExportProcessorOptions<Activity>();
public BatchExportProcessorOptions<Activity> BatchExportProcessorOptions { get; set; } = new BatchSpanExportProcessorOptions();
}
}
8 changes: 8 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

* `OtlpExporterOptions.BatchExportProcessorOptions` is initalized with
`BatchSpanExportProcessorOptions` which supports field value overriding
using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`,
`OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`
envionmental variables as defined in the
[specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/sdk-environment-variables.md#batch-span-processor).
([#2219](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2219))

* The `OtlpExporterOptions` defaults can be overridden using
`OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_HEADERS` and `OTEL_EXPORTER_OTLP_TIMEOUT`
envionmental variables as defined in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Diagnostics;
using System.Security;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Exporter
{
Expand Down Expand Up @@ -104,7 +105,7 @@ public OtlpExporterOptions()
/// <summary>
/// Gets or sets the BatchExportProcessor options. Ignored unless ExportProcessorType is Batch.
/// </summary>
public BatchExportProcessorOptions<Activity> BatchExportProcessorOptions { get; set; } = new BatchExportProcessorOptions<Activity>();
public BatchExportProcessorOptions<Activity> BatchExportProcessorOptions { get; set; } = new BatchSpanExportProcessorOptions();

/// <summary>
/// Gets or sets the metric export interval in milliseconds. The default value is 1000 milliseconds.
Expand Down
8 changes: 8 additions & 0 deletions src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

* `ZipkinExporterOptions.BatchExportProcessorOptions` is initalized with
`BatchSpanExportProcessorOptions` which supports field value overriding
using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`,
`OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`
envionmental variables as defined in the
[specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/sdk-environment-variables.md#batch-span-processor).
([#2219](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2219))

* Enabling endpoint configuration in ZipkinExporterOptions via
`OTEL_EXPORTER_ZIPKIN_ENDPOINT` environment variable.
([#1453](https://github.com/open-telemetry/opentelemetry-dotnet/issues/1453))
Expand Down
3 changes: 2 additions & 1 deletion src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using System.Diagnostics;
using OpenTelemetry.Exporter.Zipkin.Implementation;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Exporter
{
Expand Down Expand Up @@ -70,6 +71,6 @@ public ZipkinExporterOptions()
/// <summary>
/// Gets or sets the BatchExportProcessor options. Ignored unless ExportProcessorType is BatchExporter.
/// </summary>
public BatchExportProcessorOptions<Activity> BatchExportProcessorOptions { get; set; } = new BatchExportProcessorOptions<Activity>();
public BatchExportProcessorOptions<Activity> BatchExportProcessorOptions { get; set; } = new BatchSpanExportProcessorOptions();
}
}
69 changes: 0 additions & 69 deletions src/OpenTelemetry/BatchExportProcessorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,11 @@
// limitations under the License.
// </copyright>

using System;
using System.Security;
using OpenTelemetry.Internal;

namespace OpenTelemetry
{
public class BatchExportProcessorOptions<T>
where T : class
{
internal const string MaxQueueSizeEnvVarKey = "OTEL_BSP_MAX_QUEUE_SIZE";

internal const string MaxExportBatchSizeEnvVarKey = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE";

internal const string ExporterTimeoutEnvVarKey = "OTEL_BSP_EXPORT_TIMEOUT";

internal const string ScheduledDelayEnvVarKey = "OTEL_BSP_SCHEDULE_DELAY";

public BatchExportProcessorOptions()
{
int value;

if (TryLoadEnvVarInt(ExporterTimeoutEnvVarKey, out value))
{
this.ExporterTimeoutMilliseconds = value;
}

if (TryLoadEnvVarInt(MaxExportBatchSizeEnvVarKey, out value))
{
this.MaxExportBatchSize = value;
}

if (TryLoadEnvVarInt(MaxQueueSizeEnvVarKey, out value))
{
this.MaxQueueSize = value;
}

if (TryLoadEnvVarInt(ScheduledDelayEnvVarKey, out value))
{
this.ScheduledDelayMilliseconds = value;
}
}

/// <summary>
/// Gets or sets the maximum queue size. The queue drops the data if the maximum size is reached. The default value is 2048.
/// </summary>
Expand All @@ -75,37 +38,5 @@ public BatchExportProcessorOptions()
/// Gets or sets the maximum batch size of every export. It must be smaller or equal to MaxQueueLength. The default value is 512.
/// </summary>
public int MaxExportBatchSize { get; set; } = BatchExportProcessor<T>.DefaultMaxExportBatchSize;

private static bool TryLoadEnvVarInt(string envVarKey, out int result)
{
result = 0;

string value;
try
{
value = Environment.GetEnvironmentVariable(envVarKey);
}
catch (SecurityException ex)
{
// The caller does not have the required permission to
// retrieve the value of an environment variable from the current process.
OpenTelemetrySdkEventSource.Log.MissingPermissionsToReadEnvironmentVariable(ex);
return false;
}

if (string.IsNullOrEmpty(value))
{
return false;
}

if (!int.TryParse(value, out var parsedValue))
{
OpenTelemetrySdkEventSource.Log.FailedToParseEnvironmentVariable(envVarKey, value);
return false;
}

result = parsedValue;
return true;
}
}
}
4 changes: 2 additions & 2 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Unreleased

* The `BatchExportProcessorOptions` defaults can be overridden using
`OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`,
* Add `BatchSpanExportProcessorOptions` which supports field value overriding
using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`,
`OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`
envionmental variables as defined in the
[specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/sdk-environment-variables.md#batch-span-processor).
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ purposes, the SDK provides the following built-in processors:
the configured exporter.

The following environment variables can be used to override the default
values of the `BatchExportProcessorOptions<T>`.
values of the `BatchSpanExportProcessorOptions`.

<!-- markdownlint-disable MD013 -->
| Environment variable | `BatchExportProcessorOptions<T>` property |
| Environment variable | `BatchSpanExportProcessorOptions` property |
| -------------------------------- | ---------------------------------------------- |
| `OTEL_BSP_SCHEDULE_DELAY` | `ScheduledDelayMilliseconds` |
| `OTEL_BSP_EXPORT_TIMEOUT` | `ExporterTimeoutMilliseconds` |
Expand Down
91 changes: 91 additions & 0 deletions src/OpenTelemetry/Trace/BatchSpanExportProcessorOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// <copyright file="BatchSpanExportProcessorOptions.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 System.Diagnostics;
using System.Security;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Trace
{
public class BatchSpanExportProcessorOptions : BatchExportProcessorOptions<Activity>
{
internal const string MaxQueueSizeEnvVarKey = "OTEL_BSP_MAX_QUEUE_SIZE";

internal const string MaxExportBatchSizeEnvVarKey = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE";

internal const string ExporterTimeoutEnvVarKey = "OTEL_BSP_EXPORT_TIMEOUT";

internal const string ScheduledDelayEnvVarKey = "OTEL_BSP_SCHEDULE_DELAY";

public BatchSpanExportProcessorOptions()
{
int value;

if (TryLoadEnvVarInt(ExporterTimeoutEnvVarKey, out value))
{
this.ExporterTimeoutMilliseconds = value;
}

if (TryLoadEnvVarInt(MaxExportBatchSizeEnvVarKey, out value))
{
this.MaxExportBatchSize = value;
}

if (TryLoadEnvVarInt(MaxQueueSizeEnvVarKey, out value))
{
this.MaxQueueSize = value;
}

if (TryLoadEnvVarInt(ScheduledDelayEnvVarKey, out value))
{
this.ScheduledDelayMilliseconds = value;
}
}

private static bool TryLoadEnvVarInt(string envVarKey, out int result)
{
result = 0;

string value;
try
{
value = Environment.GetEnvironmentVariable(envVarKey);
}
catch (SecurityException ex)
{
// The caller does not have the required permission to
// retrieve the value of an environment variable from the current process.
OpenTelemetrySdkEventSource.Log.MissingPermissionsToReadEnvironmentVariable(ex);
return false;
}

if (string.IsNullOrEmpty(value))
{
return false;
}

if (!int.TryParse(value, out var parsedValue))
{
OpenTelemetrySdkEventSource.Log.FailedToParseEnvironmentVariable(envVarKey, value);
return false;
}

result = parsedValue;
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="BatchExportProcessorOptionsTest.cs" company="OpenTelemetry Authors">
// <copyright file="BatchSpanExportProcessorOptionsTest.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,13 +17,11 @@
using System;
using Xunit;

using Options = OpenTelemetry.BatchExportProcessorOptions<object>;

namespace OpenTelemetry.Trace.Tests
{
public class BatchExportProcessorOptionsTest : IDisposable
public class BatchSpanExportProcessorOptionsTest : IDisposable
{
public BatchExportProcessorOptionsTest()
public BatchSpanExportProcessorOptionsTest()
{
this.ClearEnvVars();
}
Expand All @@ -36,7 +34,7 @@ public void Dispose()
[Fact]
public void BatchExportProcessorOptions_Defaults()
{
var options = new Options();
var options = new BatchSpanExportProcessorOptions();

Assert.Equal(30000, options.ExporterTimeoutMilliseconds);
Assert.Equal(512, options.MaxExportBatchSize);
Expand All @@ -47,12 +45,12 @@ public void BatchExportProcessorOptions_Defaults()
[Fact]
public void BatchExportProcessorOptions_EnvironmentVariableOverride()
{
Environment.SetEnvironmentVariable(Options.ExporterTimeoutEnvVarKey, "1");
Environment.SetEnvironmentVariable(Options.MaxExportBatchSizeEnvVarKey, "2");
Environment.SetEnvironmentVariable(Options.MaxQueueSizeEnvVarKey, "3");
Environment.SetEnvironmentVariable(Options.ScheduledDelayEnvVarKey, "4");
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey, "1");
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.MaxExportBatchSizeEnvVarKey, "2");
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.MaxQueueSizeEnvVarKey, "3");
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ScheduledDelayEnvVarKey, "4");

var options = new BatchExportProcessorOptions<object>();
var options = new BatchSpanExportProcessorOptions();

Assert.Equal(1, options.ExporterTimeoutMilliseconds);
Assert.Equal(2, options.MaxExportBatchSize);
Expand All @@ -63,19 +61,19 @@ public void BatchExportProcessorOptions_EnvironmentVariableOverride()
[Fact]
public void BatchExportProcessorOptions_InvalidPortEnvironmentVariableOverride()
{
Environment.SetEnvironmentVariable(BatchExportProcessorOptions<object>.ExporterTimeoutEnvVarKey, "invalid");
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey, "invalid");

var options = new Options();
var options = new BatchSpanExportProcessorOptions();

Assert.Equal(30000, options.ExporterTimeoutMilliseconds); // use default
}

[Fact]
public void BatchExportProcessorOptions_SetterOverridesEnvironmentVariable()
{
Environment.SetEnvironmentVariable(BatchExportProcessorOptions<object>.ExporterTimeoutEnvVarKey, "123");
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey, "123");

var options = new Options
var options = new BatchSpanExportProcessorOptions
{
ExporterTimeoutMilliseconds = 89000,
};
Expand All @@ -86,18 +84,18 @@ public void BatchExportProcessorOptions_SetterOverridesEnvironmentVariable()
[Fact]
public void BatchExportProcessorOptions_EnvironmentVariableNames()
{
Assert.Equal("OTEL_BSP_EXPORT_TIMEOUT", Options.ExporterTimeoutEnvVarKey);
Assert.Equal("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", Options.MaxExportBatchSizeEnvVarKey);
Assert.Equal("OTEL_BSP_MAX_QUEUE_SIZE", Options.MaxQueueSizeEnvVarKey);
Assert.Equal("OTEL_BSP_SCHEDULE_DELAY", Options.ScheduledDelayEnvVarKey);
Assert.Equal("OTEL_BSP_EXPORT_TIMEOUT", BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey);
Assert.Equal("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", BatchSpanExportProcessorOptions.MaxExportBatchSizeEnvVarKey);
Assert.Equal("OTEL_BSP_MAX_QUEUE_SIZE", BatchSpanExportProcessorOptions.MaxQueueSizeEnvVarKey);
Assert.Equal("OTEL_BSP_SCHEDULE_DELAY", BatchSpanExportProcessorOptions.ScheduledDelayEnvVarKey);
}

private void ClearEnvVars()
{
Environment.SetEnvironmentVariable(Options.ExporterTimeoutEnvVarKey, null);
Environment.SetEnvironmentVariable(Options.MaxExportBatchSizeEnvVarKey, null);
Environment.SetEnvironmentVariable(Options.MaxQueueSizeEnvVarKey, null);
Environment.SetEnvironmentVariable(Options.ScheduledDelayEnvVarKey, null);
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey, null);
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.MaxExportBatchSizeEnvVarKey, null);
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.MaxQueueSizeEnvVarKey, null);
Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ScheduledDelayEnvVarKey, null);
}
}
}

0 comments on commit 092ddea

Please sign in to comment.