Skip to content

Commit

Permalink
Add support for console in exporter selection env vars (#3528)
Browse files Browse the repository at this point in the history

Co-authored-by: Piotr Kiełkowicz <pkiekowicz@splunk.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
  • Loading branch information
3 people authored Jul 26, 2024
1 parent a170b74 commit 1b4a9ab
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 49 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
- Support for Operating System resource detector.
- Added support for OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_LOGS_EXPORTER
to handle comma-separated list.
- The environment variables `OTEL_TRACES_EXPORTER`, `OTEL_METRICS_EXPORTER`,
and `OTEL_LOGS_EXPORTER` now support configuring console exporters for traces,
metrics, and logs, respectively.
- Environment variables `OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED`,
`OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED`, and
`OTEL_DOTNET_AUTO_LOGS_CONSOLE_EXPORTER_ENABLED` are now marked as deprecated.

### Changed

Expand Down
12 changes: 6 additions & 6 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ Exporters output the telemetry.

| Environment variable | Description | Default value | Status |
|-------------------------|---------------------------------------------------------------------------------------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------|
| `OTEL_TRACES_EXPORTER` | Comma-separated list of propagators. Supported options: `otlp`, `zipkin`, `none`. See [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.35.0/specification/configuration/sdk-environment-variables.md#exporter-selection) for more details.| `otlp` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_METRICS_EXPORTER` | Comma-separated list of propagators. Supported options: `otlp`, `prometheus`, `none`. See [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.35.0/specification/configuration/sdk-environment-variables.md#exporter-selection) for more details. | `otlp` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_LOGS_EXPORTER` | Comma-separated list of propagators. Supported options: `otlp`, `none`. See [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.35.0/specification/configuration/sdk-environment-variables.md#exporter-selection) for more details.| `otlp` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_TRACES_EXPORTER` | Comma-separated list of propagators. Supported options: `otlp`, `zipkin`, `console`, `none`. See [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.35.0/specification/configuration/sdk-environment-variables.md#exporter-selection) for more details.| `otlp` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_METRICS_EXPORTER` | Comma-separated list of propagators. Supported options: `otlp`, `prometheus`, `console`, `none`. See [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.35.0/specification/configuration/sdk-environment-variables.md#exporter-selection) for more details. | `otlp` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_LOGS_EXPORTER` | Comma-separated list of propagators. Supported options: `otlp`, `console`, `none`. See [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.35.0/specification/configuration/sdk-environment-variables.md#exporter-selection) for more details.| `otlp` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |

### Traces exporter

Expand Down Expand Up @@ -460,7 +460,7 @@ instead.
|-----------------------------------------------------|-------------------------------------------------------------------------|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| `OTEL_DOTNET_AUTO_LOG_DIRECTORY` | Directory of the .NET Tracer logs. | _See the previous note on default paths_ | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_LOG_LEVEL` | SDK log level. (supported values: `none`,`error`,`warn`,`info`,`debug`) | `info` | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED` | Whether the traces console exporter is enabled or not. | `false` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED` | Whether the metrics console exporter is enabled or not. | `false` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_DOTNET_AUTO_LOGS_CONSOLE_EXPORTER_ENABLED` | Whether the logs console exporter is enabled or not. | `false` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED` | Whether the traces console exporter is enabled or not. | `false` | [Deprecated](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED` | Whether the metrics console exporter is enabled or not. | `false` | [Deprecated](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_DOTNET_AUTO_LOGS_CONSOLE_EXPORTER_ENABLED` | Whether the logs console exporter is enabled or not. | `false` | [Deprecated](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE` | Whether the log state should be formatted. | `false` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ public static MeterProviderBuilder UseEnvironmentVariables(

private static MeterProviderBuilder SetExporter(this MeterProviderBuilder builder, MetricSettings settings, PluginManager pluginManager)
{
if (settings.ConsoleExporterEnabled)
{
Wrappers.AddConsoleExporter(builder, pluginManager);
}

foreach (var metricExporter in settings.MetricExporters)
{
builder = metricExporter switch
{
MetricsExporter.Prometheus => Wrappers.AddPrometheusHttpListener(builder, pluginManager),
MetricsExporter.Otlp => Wrappers.AddOtlpExporter(builder, settings, pluginManager),
MetricsExporter.Console => Wrappers.AddConsoleExporter(builder, pluginManager),
_ => throw new ArgumentOutOfRangeException($"Metrics exporter '{metricExporter}' is incorrect")
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,13 @@ private static TracerProviderBuilder AddWcfIfNeeded(

private static TracerProviderBuilder SetExporter(this TracerProviderBuilder builder, TracerSettings settings, PluginManager pluginManager)
{
if (settings.ConsoleExporterEnabled)
{
Wrappers.AddConsoleExporter(builder, pluginManager);
}

foreach (var traceExporter in settings.TracesExporters)
{
builder = traceExporter switch
{
TracesExporter.Zipkin => Wrappers.AddZipkinExporter(builder, pluginManager),
TracesExporter.Otlp => Wrappers.AddOtlpExporter(builder, settings, pluginManager),
TracesExporter.Console => Wrappers.AddConsoleExporter(builder, pluginManager),
_ => throw new ArgumentOutOfRangeException($"Traces exporter '{traceExporter}' is incorrect")
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ internal enum LogExporter
/// OTLP exporter.
/// </summary>
Otlp,

/// <summary>
/// Console exporter.
/// </summary>
Console,
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ internal class LogSettings : Settings
public bool IncludeFormattedMessage { get; private set; }

/// <summary>
/// Gets a value indicating whether the console exporter is enabled.
/// Gets the list of enabled instrumentations.
/// </summary>
public bool ConsoleExporterEnabled { get; private set; }
public IReadOnlyList<LogInstrumentation> EnabledInstrumentations { get; private set; } = new List<LogInstrumentation>();

/// <summary>
/// Gets the list of enabled instrumentations.
/// Gets or sets a value indicating whether the console exporter is enabled.
/// </summary>
public IReadOnlyList<LogInstrumentation> EnabledInstrumentations { get; private set; } = new List<LogInstrumentation>();
private bool ConsoleExporterEnabled { get; set; }

protected override void OnLoad(Configuration configuration)
{
LogsEnabled = configuration.GetBool(ConfigurationKeys.Logs.LogsEnabled) ?? true;
LogExporters = ParseLogExporter(configuration);
ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Logs.ConsoleExporterEnabled) ?? false;
LogExporters = ParseLogExporter(configuration);
IncludeFormattedMessage = configuration.GetBool(ConfigurationKeys.Logs.IncludeFormattedMessage) ?? false;

var instrumentationEnabledByDefault =
Expand All @@ -53,7 +53,7 @@ protected override void OnLoad(Configuration configuration)
enabledConfigurationTemplate: ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate);
}

private static IReadOnlyList<LogExporter> ParseLogExporter(Configuration configuration)
private IReadOnlyList<LogExporter> ParseLogExporter(Configuration configuration)
{
var logExporterEnvVar = configuration.GetString(ConfigurationKeys.Logs.Exporter);

Expand All @@ -72,6 +72,9 @@ private static IReadOnlyList<LogExporter> ParseLogExporter(Configuration configu
case Constants.ConfigurationValues.Exporters.Otlp:
exporters.Add(LogExporter.Otlp);
break;
case Constants.ConfigurationValues.Exporters.Console:
exporters.Add(LogExporter.Console);
break;
case Constants.ConfigurationValues.None:
break;
default:
Expand All @@ -87,6 +90,16 @@ private static IReadOnlyList<LogExporter> ParseLogExporter(Configuration configu
}
}

if (ConsoleExporterEnabled)
{
Logger.Warning($"The '{ConfigurationKeys.Logs.ConsoleExporterEnabled}' environment variable is deprecated and " +
"will be removed in the next minor release. " +
"Please set the console exporter using OTEL_LOGS_EXPORTER environmental variable. " +
"Refer to the updated documentation for details.");

exporters.Add(LogExporter.Console);
}

return exporters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ internal class MetricSettings : Settings
/// </summary>
public IReadOnlyList<MetricsExporter> MetricExporters { get; private set; } = new List<MetricsExporter>();

/// <summary>
/// Gets a value indicating whether the console exporter is enabled.
/// </summary>
public bool ConsoleExporterEnabled { get; private set; }

/// <summary>
/// Gets the list of enabled meters.
/// </summary>
Expand All @@ -37,6 +32,11 @@ internal class MetricSettings : Settings
/// </summary>
public IList<string> Meters { get; } = new List<string>();

/// <summary>
/// Gets or sets a value indicating whether the console exporter is enabled.
/// </summary>
private bool ConsoleExporterEnabled { get; set; }

protected override void OnLoad(Configuration configuration)
{
MetricExporters = ParseMetricExporter(configuration);
Expand All @@ -62,7 +62,7 @@ protected override void OnLoad(Configuration configuration)
MetricsEnabled = configuration.GetBool(ConfigurationKeys.Metrics.MetricsEnabled) ?? true;
}

private static IReadOnlyList<MetricsExporter> ParseMetricExporter(Configuration configuration)
private IReadOnlyList<MetricsExporter> ParseMetricExporter(Configuration configuration)
{
var metricsExporterEnvVar = configuration.GetString(ConfigurationKeys.Metrics.Exporter);

Expand All @@ -84,9 +84,11 @@ private static IReadOnlyList<MetricsExporter> ParseMetricExporter(Configuration
case Constants.ConfigurationValues.Exporters.Prometheus:
exporters.Add(MetricsExporter.Prometheus);
break;
case Constants.ConfigurationValues.Exporters.Console:
exporters.Add(MetricsExporter.Console);
break;
case Constants.ConfigurationValues.None:
break;

default:
if (configuration.FailFast)
{
Expand All @@ -100,6 +102,16 @@ private static IReadOnlyList<MetricsExporter> ParseMetricExporter(Configuration
}
}

if (ConsoleExporterEnabled)
{
Logger.Warning($"The '{ConfigurationKeys.Metrics.ConsoleExporterEnabled}' environment variable is deprecated and " +
"will be removed in the next minor release. " +
"Please set the console exporter using OTEL_METRICS_EXPORTER environmental variable. " +
"Refer to the updated documentation for details.");

exporters.Add(MetricsExporter.Console);
}

return exporters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ internal enum MetricsExporter
/// Prometheus exporter.
/// </summary>
Prometheus,

/// <summary>
/// Console exporter.
/// </summary>
Console,
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ internal class TracerSettings : Settings
/// </summary>
public IReadOnlyList<TracesExporter> TracesExporters { get; private set; } = new List<TracesExporter>();

/// <summary>
/// Gets a value indicating whether the console exporter is enabled.
/// </summary>
public bool ConsoleExporterEnabled { get; private set; }

/// <summary>
/// Gets the list of enabled instrumentations.
/// </summary>
Expand All @@ -52,10 +47,15 @@ internal class TracerSettings : Settings
/// </summary>
public InstrumentationOptions InstrumentationOptions { get; private set; } = new(new Configuration(failFast: false));

/// <summary>
/// Gets or sets a value indicating whether the console exporter is enabled.
/// </summary>
private bool ConsoleExporterEnabled { get; set; }

protected override void OnLoad(Configuration configuration)
{
TracesExporters = ParseTracesExporter(configuration);
ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Traces.ConsoleExporterEnabled) ?? false;
TracesExporters = ParseTracesExporter(configuration);

var instrumentationEnabledByDefault =
configuration.GetBool(ConfigurationKeys.Traces.TracesInstrumentationEnabled) ??
Expand Down Expand Up @@ -89,7 +89,7 @@ protected override void OnLoad(Configuration configuration)
InstrumentationOptions = new InstrumentationOptions(configuration);
}

private static IReadOnlyList<TracesExporter> ParseTracesExporter(Configuration configuration)
private IReadOnlyList<TracesExporter> ParseTracesExporter(Configuration configuration)
{
var tracesExporterEnvVar = configuration.GetString(ConfigurationKeys.Traces.Exporter);

Expand All @@ -114,6 +114,9 @@ private static IReadOnlyList<TracesExporter> ParseTracesExporter(Configuration c
break;
case Constants.ConfigurationValues.None:
break;
case Constants.ConfigurationValues.Exporters.Console:
exporters.Add(TracesExporter.Console);
break;
default:
if (configuration.FailFast)
{
Expand All @@ -127,6 +130,16 @@ private static IReadOnlyList<TracesExporter> ParseTracesExporter(Configuration c
}
}

if (ConsoleExporterEnabled)
{
Logger.Warning($"The '{ConfigurationKeys.Traces.ConsoleExporterEnabled}' environment variable is deprecated and " +
"will be removed in the next minor release. " +
"Please set the console exporter using OTEL_TRACES_EXPORTER environmental variable. " +
"Refer to the updated documentation for details.");

exporters.Add(TracesExporter.Console);
}

return exporters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ internal enum TracesExporter
/// Zipkin exporter.
/// </summary>
Zipkin,

/// <summary>
/// Console exporter.
/// </summary>
Console,
}
1 change: 1 addition & 0 deletions src/OpenTelemetry.AutoInstrumentation/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static class Exporters
public const string Otlp = "otlp";
public const string Prometheus = "prometheus";
public const string Zipkin = "zipkin";
public const string Console = "console";
}

public static class Propagators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ private static void AddOpenTelemetryLogs(ILoggingBuilder builder)
pluginManager?.ConfigureLogsOptions(options);
if (settings.ConsoleExporterEnabled)
{
if (pluginManager != null)
{
options.AddConsoleExporter(pluginManager.ConfigureLogsOptions);
}
}
foreach (var logExporter in settings.LogExporters)
{
switch (logExporter)
Expand All @@ -94,6 +86,13 @@ private static void AddOpenTelemetryLogs(ILoggingBuilder builder)
pluginManager?.ConfigureLogsOptions(otlpOptions);
});
break;
case LogExporter.Console:
if (pluginManager != null)
{
options.AddConsoleExporter(pluginManager.ConfigureLogsOptions);
}
break;
default:
throw new ArgumentOutOfRangeException($"Logs exporter '{logExporter}' is incorrect");
Expand Down
Loading

0 comments on commit 1b4a9ab

Please sign in to comment.