Skip to content
Open
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
76 changes: 76 additions & 0 deletions docs/file-based-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ fail_fast: false
# Configure if the Flush On Unhandled Exception is enabled or not.
# If omitted or null, false is used.
flush_on_unhandled_exception: false
# Configure if the Logs Include Formatted Message is enabled or not.
# If omitted or null, false is used.
logs_include_formatted_message: false
```

### Tracer Provider Configuration
Expand Down Expand Up @@ -112,6 +115,79 @@ tracer_provider:
console:
```

### Logger Provider Configuration

``` yaml
logger_provider:
processors:
# Batch processor for OTLP HTTP
- batch:
# Configure delay interval (in milliseconds) between two consecutive exports.
# Value must be non-negative.
# If omitted or null, 5000 is used.
schedule_delay: 5000
# Configure maximum allowed time (in milliseconds) to export data.
# Value must be non-negative. A value of 0 indicates no limit (infinity).
# If omitted or null, 30000 is used.
export_timeout: 30000
# Configure maximum queue size. Value must be positive.
# If omitted or null, 2048 is used.
max_queue_size: 2048
# Configure maximum batch size. Value must be positive.
# If omitted or null, 512 is used.
max_export_batch_size: 512
# Configure exporter.
exporter:
# Configure the OTLP with HTTP transport exporter to enable it.
otlp_http:
# Configure endpoint, including the logs specific path.
# If omitted or null, http://localhost:4318/v1/logs is used.
endpoint: http://localhost:4318/v1/logs
# Configure headers. Entries have higher priority than entries from .headers_list.
# If an entry's .value is null, the entry is ignored.
headers:
- name: api-key
value: "1234"
# Configure headers. Entries have lower priority than entries from .headers.
# The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS.
# If omitted or null, no headers are added.
headers_list: api-key=1234
# Configure compression.
# Values include: gzip, none. Implementations may support other compression algorithms.
# If omitted or null, none is used.
compression: gzip
# Configure max time (in milliseconds) to wait for each export.
# Value must be non-negative. A value of 0 indicates no limit (infinity).
# If omitted or null, 10000 is used.
timeout: 10000

# Batch processor for OTLP gRPC
- batch:
exporter:
otlp_grpc:
# Configure endpoint.
# If omitted or null, http://localhost:4317 is used.
endpoint: http://localhost:4317
# Configure headers. Entries have higher priority than entries from .headers_list.
# If an entry's .value is null, the entry is ignored.
headers:
- name: api-key
value: "1234"
# Configure headers. Entries have lower priority than entries from .headers.
# The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS.
# If omitted or null, no headers are added.
headers_list: api-key=1234
# Configure max time (in milliseconds) to wait for each export.
# Value must be non-negative. A value of 0 indicates no limit (infinity).
# If omitted or null, 10000 is used.
timeout: 10000

# Simple processor for Console
- simple:
exporter:
console:
```

### Resource Configuration

You can configure resource attributes directly in YAML or via the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
// SPDX-License-Identifier: Apache-2.0

using System.Runtime.CompilerServices;
using OpenTelemetry;
using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;
using OpenTelemetry.AutoInstrumentation.Configurations.Otlp;
using OpenTelemetry.AutoInstrumentation.Loading;
using OpenTelemetry.AutoInstrumentation.Logging;
using OpenTelemetry.AutoInstrumentation.Plugins;
using OpenTelemetry.Logs;

namespace OpenTelemetry.AutoInstrumentation.Configurations;

internal static class EnvironmentConfigurationLogHelper
{
private static readonly IOtelLogger Logger = OtelLogging.GetLogger();

public static LoggerProviderBuilder UseEnvironmentVariables(
this LoggerProviderBuilder builder,
LazyInstrumentationLoader lazyInstrumentationLoader,
Expand All @@ -22,6 +28,119 @@ public static LoggerProviderBuilder UseEnvironmentVariables(

private static void SetExporter(LoggerProviderBuilder builder, LogSettings settings, PluginManager pluginManager)
{
if (settings.LogExporters.Count == 0)
{
if (settings.Processors != null)
{
foreach (var processor in settings.Processors)
{
if (processor.Batch != null && processor.Simple != null)
{
Logger.Debug("Both batch and simple processors are configured. It is not supported. Skipping.");
continue;
}

if (processor.Batch == null && processor.Simple == null)
{
Logger.Debug("No valid processor configured, skipping.");
continue;
}

if (processor.Batch != null)
{
var exporter = processor.Batch.Exporter;
if (exporter == null)
{
Logger.Debug("No exporter configured for batch processor. Skipping.");
continue;
}

var exportersCount = 0;

if (exporter.OtlpHttp != null)
{
exportersCount++;
}

if (exporter.OtlpGrpc != null)
{
exportersCount++;
}

switch (exportersCount)
{
case 0:
Logger.Debug("No valid exporter configured for batch processor. Skipping.");
continue;
case > 1:
Logger.Debug("Multiple exporters are configured for batch processor. Only one exporter is supported. Skipping.");
continue;
}

if (exporter.OtlpHttp != null)
{
builder = Wrappers.AddOtlpHttpExporter(builder, pluginManager, processor.Batch, exporter.OtlpHttp);
}
else if (exporter.OtlpGrpc != null)
{
builder = Wrappers.AddOtlpGrpcExporter(builder, pluginManager, processor.Batch, exporter.OtlpGrpc);
}
}
else if (processor.Simple != null)
{
var exporter = processor.Simple.Exporter;
if (exporter == null)
{
Logger.Debug("No exporter configured for simple processor. Skipping.");
continue;
}

var exportersCount = 0;

if (exporter.OtlpHttp != null)
{
exportersCount++;
}

if (exporter.OtlpGrpc != null)
{
exportersCount++;
}

if (exporter.Console != null)
{
exportersCount++;
}

switch (exportersCount)
{
case 0:
Logger.Debug("No valid exporter configured for simple processor. Skipping.");
continue;
case > 1:
Logger.Debug("Multiple exporters are configured for simple processor. Only one exporter is supported. Skipping.");
continue;
}

if (exporter.OtlpHttp != null)
{
builder = Wrappers.AddOtlpHttpExporter(builder, pluginManager, exporter.OtlpHttp);
}
else if (exporter.OtlpGrpc != null)
{
builder = Wrappers.AddOtlpGrpcExporter(builder, pluginManager, exporter.OtlpGrpc);
}
else if (exporter.Console != null)
{
builder = Wrappers.AddConsoleExporter(builder, pluginManager);
}
}
}
}

return;
}

foreach (var logExporter in settings.LogExporters)
{
builder = logExporter switch
Expand Down Expand Up @@ -50,5 +169,53 @@ public static LoggerProviderBuilder AddOtlpExporter(LoggerProviderBuilder builde
pluginManager?.ConfigureLogsOptions(options);
});
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static LoggerProviderBuilder AddOtlpHttpExporter(LoggerProviderBuilder builder, PluginManager pluginManager, LogBatchProcessorConfig batch, OtlpHttpExporterConfig otlpHttp)
{
var otlpSettings = new OtlpSettings(OtlpSignalType.Logs, otlpHttp);
return builder.AddOtlpExporter(options =>
{
batch?.CopyTo(options.BatchExportProcessorOptions);
otlpSettings.CopyTo(options);
pluginManager?.ConfigureLogsOptions(options);
});
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static LoggerProviderBuilder AddOtlpGrpcExporter(LoggerProviderBuilder builder, PluginManager pluginManager, LogBatchProcessorConfig batch, OtlpGrpcExporterConfig otlpGrpc)
{
var otlpSettings = new OtlpSettings(otlpGrpc);
return builder.AddOtlpExporter(options =>
{
batch?.CopyTo(options.BatchExportProcessorOptions);
otlpSettings.CopyTo(options);
pluginManager?.ConfigureLogsOptions(options);
});
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static LoggerProviderBuilder AddOtlpHttpExporter(LoggerProviderBuilder builder, PluginManager pluginManager, OtlpHttpExporterConfig otlpHttp)
{
var otlpSettings = new OtlpSettings(OtlpSignalType.Logs, otlpHttp);
return builder.AddOtlpExporter(options =>
{
options.ExportProcessorType = ExportProcessorType.Simple;
otlpSettings.CopyTo(options);
pluginManager?.ConfigureLogsOptions(options);
});
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static LoggerProviderBuilder AddOtlpGrpcExporter(LoggerProviderBuilder builder, PluginManager pluginManager, OtlpGrpcExporterConfig otlpGrpc)
{
var otlpSettings = new OtlpSettings(otlpGrpc);
return builder.AddOtlpExporter(options =>
{
options.ExportProcessorType = ExportProcessorType.Simple;
otlpSettings.CopyTo(options);
pluginManager?.ConfigureLogsOptions(options);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

internal class BatchLogExporterConfig
{
/// <summary>
/// Gets or sets the OTLP HTTP exporter configuration.
/// </summary>
[YamlMember(Alias = "otlp_http")]
public OtlpHttpExporterConfig? OtlpHttp { get; set; }

/// <summary>
/// Gets or sets the OTLP gRPC exporter configuration.
/// </summary>
[YamlMember(Alias = "otlp_grpc")]
public OtlpGrpcExporterConfig? OtlpGrpc { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,15 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

internal class BatchProcessorConfig
internal class BatchProcessorConfig : BatchProcessorConfigBase
{
/// <summary>
/// Gets or sets the delay interval (in milliseconds) between two consecutive exports.
/// Value must be non-negative.
/// If omitted or null, 5000 is used.
/// </summary>
[YamlMember(Alias = "schedule_delay")]
public int ScheduleDelay { get; set; } = 5000;

/// <summary>
/// Gets or sets the maximum allowed time (in milliseconds) to export data.
/// Value must be non-negative. A value of 0 indicates no limit (infinity).
/// If omitted or null, 30000 is used.
/// </summary>
[YamlMember(Alias = "export_timeout")]
public int ExportTimeout { get; set; } = 30000;

/// <summary>
/// Gets or sets the maximum queue size.
/// Value must be positive.
/// If omitted or null, 2048 is used.
/// </summary>
[YamlMember(Alias = "max_queue_size")]
public int MaxQueueSize { get; set; } = 2048;

/// <summary>
/// Gets or sets the maximum batch size.
/// Value must be positive.
/// If omitted or null, 512 is used.
/// </summary>
[YamlMember(Alias = "max_export_batch_size")]
public int MaxExportBatchSize { get; set; } = 512;

/// <summary>
/// Gets or sets the exporters.
/// </summary>
[YamlMember(Alias = "exporter")]
public BatchTracerExporterConfig? Exporter { get; set; }

public void CopyTo(BatchExportProcessorOptions<Activity> options)
{
options.ScheduledDelayMilliseconds = ScheduleDelay;
options.ExporterTimeoutMilliseconds = ExportTimeout;
options.MaxQueueSize = MaxQueueSize;
options.MaxExportBatchSize = MaxExportBatchSize;
}
}
Loading
Loading