Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b20820b
implement parser with file based configuration
ysolomchenko Jun 24, 2025
7e9805b
create method to get enabled detectors
ysolomchenko Jun 25, 2025
0ecd47a
remove unused properties
ysolomchenko Jun 25, 2025
f2aec25
fix lint
ysolomchenko Jun 25, 2025
4b64c8f
Add support for
ysolomchenko Jun 25, 2025
42da3c4
Add Resources
ysolomchenko Jun 30, 2025
8c182c8
add unit test/ minor fixes
ysolomchenko Jul 9, 2025
7a6b0e3
fix test
ysolomchenko Jul 23, 2025
03ca73c
remove unused usings + minor fix
ysolomchenko Jul 30, 2025
d5294ca
fix bug with null entry
ysolomchenko Jul 30, 2025
afc5141
fix lint in yaml files
ysolomchenko Jul 30, 2025
37e1e5c
fix parser test for framework + cleanup
ysolomchenko Jul 30, 2025
e378484
fix bug with disabled
ysolomchenko Jul 30, 2025
8aa99ab
add integration tests
ysolomchenko Jul 30, 2025
f0bb42e
remove unused using
ysolomchenko Jul 30, 2025
900baa2
fix tests
ysolomchenko Jul 30, 2025
252061c
Add FailFast
ysolomchenko Aug 1, 2025
206948a
dosc
ysolomchenko Aug 1, 2025
c7d1dce
changelog
ysolomchenko Aug 1, 2025
5ea0fcd
fix
ysolomchenko Aug 1, 2025
61d1538
cleanup
ysolomchenko Aug 1, 2025
0a80dd0
fix tests
ysolomchenko Aug 14, 2025
93b1eae
vendor YamlDotNet
ysolomchenko Aug 14, 2025
45079f2
fix dotnet format
ysolomchenko Aug 18, 2025
1474b3c
adjust vendored namespaces
Kielek Aug 28, 2025
67be19d
Fix CHANGELOG
Kielek Aug 28, 2025
8e7f82d
Merge branch 'main' into yaml-parser
Kielek Aug 29, 2025
2c2e2f7
Vendors - cleanup generator headers
Kielek Aug 29, 2025
018e49e
revert empty lines
Kielek Aug 29, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h

- Extend support for [RabbitMQ.Client](https://www.nuget.org/packages/RabbitMQ.Client/)
traces instrumentation for versions `5.*`.
- Support for [file based configuration](./docs/config.md#configuration-examples)

### Changed

Expand Down
363 changes: 363 additions & 0 deletions docs/config.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ internal partial class ConfigurationKeys
/// </summary>
public const string EnabledResourceDetectorTemplate = "OTEL_DOTNET_AUTO_{0}_RESOURCE_DETECTOR_ENABLED";

/// <summary>
/// Configuration key template for resource attributes.
/// </summary>
public const string ResourceAttributes = "OTEL_RESOURCE_ATTRIBUTES";

/// <summary>
/// Configuration key for setting the service name.
/// </summary>
public const string ServiceName = "OTEL_SERVICE_NAME";

/// <summary>
/// Configuration keys for traces.
/// </summary>
Expand Down Expand Up @@ -92,6 +102,38 @@ public static class Traces
/// </summary>
public const string AdditionalLegacySources = "OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_LEGACY_SOURCES";

/// <summary>
/// Configuration key for ZipkinEndpoint.
/// </summary>
public const string ZipkinEndpoint = "OTEL_EXPORTER_ZIPKIN_ENDPOINT";

/// <summary>
/// Configuration keys for Batch Span Processor options.
/// </summary>
public static class BatchSpanProcessorConfig
{
/// <summary>
/// Configuration key for configuring the delay interval (in milliseconds) between two consecutive exports.
/// </summary>
public const string ScheduleDelay = "OTEL_BSP_SCHEDULE_DELAY";

/// <summary>
/// Configuration key for configuring the maximum allowed time (in milliseconds) to export data.
/// </summary>
public const string ExportTimeout = "OTEL_BSP_EXPORT_TIMEOUT";

/// <summary>
/// Configuration key for configuring the maximum queue size.
/// </summary>
public const string MaxQueueSize = "OTEL_BSP_MAX_QUEUE_SIZE";

/// <summary>
/// Configuration key for configuring the maximum batch size.
/// Must be less than or equal to OTEL_BSP_MAX_QUEUE_SIZE.
/// </summary>
public const string MaxExportBatchSize = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE";
}

/// <summary>
/// Configuration keys for instrumentation options.
/// </summary>
Expand Down Expand Up @@ -193,6 +235,16 @@ public static class Metrics
/// Configuration key for additional <see cref="Meter"/> names to be added to the meter at the startup.
/// </summary>
public const string AdditionalSources = "OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES";

/// <summary>
/// Configuration key for metric reader export interval.
/// </summary>
public const string ExportInterval = "OTEL_METRIC_EXPORT_INTERVAL";

/// <summary>
/// Configuration key for metric reader export timeout.
/// </summary>
public const string ExportTimeout = "OTEL_METRIC_EXPORT_TIMEOUT";
}

/// <summary>
Expand Down Expand Up @@ -244,5 +296,17 @@ public static class Sdk
/// Default is <c>"tracecontext,baggage"</c>.
/// </summary>
public const string Propagators = "OTEL_PROPAGATORS";

/// <summary>
/// Configuration key for the maximum allowed length of attribute values.
/// Default is no limit. Valid values are non-negative integers.
/// </summary>
public const string AttributeValueLengthLimit = "OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT";

/// <summary>
/// Configuration key for the maximum allowed number of attributes per resource, span, or event.
/// Default is <c>128</c>. Valid values are non-negative integers.
/// </summary>
public const string AttributeCountLimit = "OTEL_ATTRIBUTE_COUNT_LIMIT";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static MeterProviderBuilder AddOtlpExporter(MeterProviderBuilder builder,
{
return builder.AddOtlpExporter((options, metricReaderOptions) =>
{
metricReaderOptions.PeriodicExportingMetricReaderOptions = settings.ReaderConfiguration.ToPeriodicExportingMetricReaderOptions();
// Copy Auto settings to SDK settings
settings.OtlpSettings?.CopyTo(options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static TracerProviderBuilder SetExporter(this TracerProviderBuilder buil
{
builder = traceExporter switch
{
TracesExporter.Zipkin => Wrappers.AddZipkinExporter(builder, pluginManager),
TracesExporter.Zipkin => Wrappers.AddZipkinExporter(builder, settings, pluginManager),
TracesExporter.Otlp => Wrappers.AddOtlpExporter(builder, settings, pluginManager),
TracesExporter.Console => Wrappers.AddConsoleExporter(builder, pluginManager),
_ => throw new ArgumentOutOfRangeException($"Traces exporter '{traceExporter}' is incorrect")
Expand Down Expand Up @@ -218,16 +218,24 @@ public static TracerProviderBuilder AddConsoleExporter(TracerProviderBuilder bui
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static TracerProviderBuilder AddZipkinExporter(TracerProviderBuilder builder, PluginManager pluginManager)
public static TracerProviderBuilder AddZipkinExporter(TracerProviderBuilder builder, TracerSettings settings, PluginManager pluginManager)
{
return builder.AddZipkinExporter(pluginManager.ConfigureTracesOptions);
return builder.AddZipkinExporter(options =>
{
options.BatchExportProcessorOptions = settings.BatchProcessorConfig.ToBatchExportProcessorOptions();
options.Endpoint = new Uri(settings.ZipkinSettings!.Endpoint);

pluginManager.ConfigureTracesOptions(options);
});
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static TracerProviderBuilder AddOtlpExporter(TracerProviderBuilder builder, TracerSettings settings, PluginManager pluginManager)
{
return builder.AddOtlpExporter(options =>
{
options.BatchExportProcessorOptions = settings.BatchProcessorConfig.ToBatchExportProcessorOptions();

// Copy Auto settings to SDK settings
settings.OtlpSettings?.CopyTo(options);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

namespace OpenTelemetry.AutoInstrumentation.Configurations;

internal class FailFastSettings : Settings
{
public bool FailFast { get; private set; }

protected override void OnLoad(Configuration configuration)
protected override void OnLoadEnvVar(Configuration configuration)
{
FailFast = configuration.GetBool(ConfigurationKeys.FailFast) ?? false;
}

protected override void OnLoadFile(Conf configuration)
{
FailFast = configuration.FailFast;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

internal class AttributeLimits
{
public AttributeLimits()
{
}

public AttributeLimits(int? attributeValueLengthLimit, int? attributeCountLimit)
{
if (attributeValueLengthLimit.HasValue && attributeValueLengthLimit.Value >= 0)
{
AttributeValueLengthLimit = attributeValueLengthLimit;
}

if (attributeCountLimit.HasValue && attributeCountLimit.Value >= 0)
{
AttributeCountLimit = attributeCountLimit.Value;
}
}

/// <summary>
/// Gets or sets the maximum attribute value size.
/// Value must be non-negative.
/// If omitted or null, there is no limit.
/// </summary>
[YamlMember(Alias = "attribute_value_length_limit")]
public int? AttributeValueLengthLimit { get; set; }

/// <summary>
/// Gets or sets the maximum attribute count.
/// Value must be non-negative.
/// If omitted or null, 128 is used.
/// </summary>
[YamlMember(Alias = "attribute_count_limit")]
public int AttributeCountLimit { get; set; } = 128;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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
{
public BatchProcessorConfig()
{
}

public BatchProcessorConfig(
int? scheduleDelay = null,
int? exportTimeout = null,
int? maxQueueSize = null,
int? maxExportBatchSize = null)
{
if (scheduleDelay is not null)
{
ScheduleDelay = scheduleDelay.Value;
}

if (exportTimeout is not null)
{
ExportTimeout = exportTimeout.Value;
}

if (maxQueueSize is not null)
{
MaxQueueSize = maxQueueSize.Value;
}

if (maxExportBatchSize is not null)
{
MaxExportBatchSize = maxExportBatchSize.Value;
}
}

/// <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 ExporterConfig? Exporter { get; set; }

public BatchExportProcessorOptions<Activity> ToBatchExportProcessorOptions()
{
return new BatchExportProcessorOptions<Activity>
{
ScheduledDelayMilliseconds = this.ScheduleDelay,
ExporterTimeoutMilliseconds = this.ExportTimeout,
MaxQueueSize = this.MaxQueueSize,
MaxExportBatchSize = this.MaxExportBatchSize
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser;
using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

[EmptyObjectOnEmptyYaml]
internal class CaptureHeadersConfiguration
{
/// <summary>
/// Gets or sets a comma-separated list of HTTP header names.
/// Instrumentations will capture HTTP request header values for all configured header names.
/// </summary>
[YamlMember(Alias = "capture_request_headers")]
public string? CaptureRequestHeaders { get; set; }

/// <summary>
/// Gets or sets a comma-separated list of HTTP header names.
/// Instrumentations will capture HTTP response header values for all configured header names.
/// </summary>
[YamlMember(Alias = "capture_response_headers")]
public string? CaptureResponseHeaders { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser;
using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

[EmptyObjectOnEmptyYaml]
internal class CaptureMetadataConfiguration
{
/// <summary>
/// Gets or sets a comma-separated list of gRPC metadata names.
/// Grpc.Net.Client instrumentations will capture gRPC request metadata values for all configured metadata names.
/// </summary>
[YamlMember(Alias = "capture_request_metadata")]
public string? CaptureRequestMetadata { get; set; }

/// <summary>
/// Gets or sets a comma-separated list of gRPC metadata names.
/// Grpc.Net.Client instrumentations will capture gRPC response metadata values for all configured metadata names.
/// </summary>
[YamlMember(Alias = "capture_response_metadata")]
public string? CaptureResponseMetadata { get; set; }
}
Loading
Loading