From d19a6ca45aa17251cc55492dca99c6752ee97809 Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Fri, 19 Sep 2025 09:29:17 +0200 Subject: [PATCH 1/8] Add configuration for resource detectors --- .../DetectionDevelopment.cs | 16 +++++ .../FileBasedConfiguration/DotNetDetectors.cs | 71 +++++++++++++++++++ .../ResourceConfiguration.cs | 6 ++ .../Configurations/ResourceSettings.cs | 2 +- 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DetectionDevelopment.cs create mode 100644 src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DotNetDetectors.cs diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DetectionDevelopment.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DetectionDevelopment.cs new file mode 100644 index 0000000000..0db7b77b1e --- /dev/null +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DetectionDevelopment.cs @@ -0,0 +1,16 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using Vendors.YamlDotNet.Serialization; + +namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; + +internal class DetectionDevelopment +{ + /// + /// Gets or sets the configuration for resource detectors. + /// If omitted or null, no resource detectors are enabled. + /// + [YamlMember(Alias = "detectors")] + public DotNetDetectors? Detectors { get; set; } +} diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DotNetDetectors.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DotNetDetectors.cs new file mode 100644 index 0000000000..4142eedb04 --- /dev/null +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DotNetDetectors.cs @@ -0,0 +1,71 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using System.Reflection; +using Vendors.YamlDotNet.Serialization; + +namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; + +internal class DotNetDetectors +{ + /// + /// Gets or sets the Azure App Service detector configuration. + /// + [YamlMember(Alias = "azureappservice")] + public object? AzureAppService { get; set; } + +#if NET + /// + /// Gets or sets the container detector configuration. + /// + [YamlMember(Alias = "container")] + public object? Container { get; set; } +#endif + + /// + /// Gets or sets the host detector configuration. + /// + [YamlMember(Alias = "host")] + public object? Host { get; set; } + + /// + /// Gets or sets the operating system detector configuration. + /// + [YamlMember(Alias = "operatingsystem")] + public object? OperatingSystem { get; set; } + + /// + /// Gets or sets the process detector configuration. + /// + [YamlMember(Alias = "process")] + public object? Process { get; set; } + + /// + /// Gets or sets the process runtime detector configuration. + /// + [YamlMember(Alias = "processruntime")] + public object? ProcessRuntime { get; set; } + + /// + /// Returns the list of enabled resource detectors. + /// + public IReadOnlyList GetEnabledResourceDetectors() + { + var enabled = new List(); + var properties = typeof(DotNetDetectors).GetProperties(BindingFlags.Instance | BindingFlags.Public); + + foreach (var prop in properties) + { + var value = prop.GetValue(this); + if (value != null) + { + if (Enum.TryParse(prop.Name, out var resourceDetector)) + { + enabled.Add(resourceDetector); + } + } + } + + return enabled; + } +} diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/ResourceConfiguration.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/ResourceConfiguration.cs index 886c906ced..4f5b57af68 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/ResourceConfiguration.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/ResourceConfiguration.cs @@ -19,6 +19,12 @@ internal class ResourceConfiguration [YamlMember(Alias = "attributes_list")] public string? AttributesList { get; set; } + /// + /// Gets or sets the detection development configuration. + /// + [YamlMember(Alias = "detection/development")] + public DetectionDevelopment? DetectionDevelopment { get; set; } + public List> ParseAttributes() { var resourceAttributesWithPriority = new Dictionary(); diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceSettings.cs index 1554a16757..49fc39f207 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceSettings.cs @@ -37,6 +37,6 @@ protected override void OnLoadFile(YamlConfiguration configuration) Resources = configuration.Resource?.ParseAttributes() ?? []; - // TODO initialize EnabledDetectors from file configuration + EnabledDetectors = configuration.Resource?.DetectionDevelopment?.Detectors?.GetEnabledResourceDetectors() ?? []; } } From e1e7465ae91f375c6bc6e4e11a248127f23f4a68 Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Fri, 19 Sep 2025 09:30:54 +0200 Subject: [PATCH 2/8] Add resource detectors tests --- .../FileBased/FileBasedTestHelper.cs | 32 ++++++++++++++++ ...s.cs => FilebasedResourceSettingsTests.cs} | 38 ++++++++++++++++++- .../FileBased/Files/TestFile.yaml | 9 +++++ .../FileBased/{ => Parser}/ParserTests.cs | 28 ++++++++++++-- 4 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FileBasedTestHelper.cs rename test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/{FilebasedGeneralSettingsTests.cs => FilebasedResourceSettingsTests.cs} (75%) rename test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/{ => Parser}/ParserTests.cs (59%) diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FileBasedTestHelper.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FileBasedTestHelper.cs new file mode 100644 index 0000000000..793c7d6b29 --- /dev/null +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FileBasedTestHelper.cs @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using System.Reflection; +using Vendors.YamlDotNet.Core; +using Vendors.YamlDotNet.Serialization; +using Xunit; + +namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased; + +internal static class FileBasedTestHelper +{ + public static void MoveParserToScalar(IParser parser) + { + parser.MoveNext(); // StreamStart + parser.MoveNext(); // DocumentStart + parser.MoveNext(); // Scalar + } + + public static void AssertAliasPropertyExists(T obj, string alias) + { + Assert.NotNull(obj); + + var prop = typeof(T).GetProperties() + .FirstOrDefault(p => p.GetCustomAttribute()?.Alias == alias); + + Assert.NotNull(prop); + + var value = prop.GetValue(obj); + Assert.NotNull(value); + } +} diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FilebasedGeneralSettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FilebasedResourceSettingsTests.cs similarity index 75% rename from test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FilebasedGeneralSettingsTests.cs rename to test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FilebasedResourceSettingsTests.cs index 52ab2d51be..2e8fcdafa8 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FilebasedGeneralSettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FilebasedResourceSettingsTests.cs @@ -7,7 +7,7 @@ namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased; -public class FilebasedGeneralSettingsTests +public class FilebasedResourceSettingsTests { [Fact] public void LoadFile_MergesBaseAndCustomResourceAttributes() @@ -97,4 +97,40 @@ public void LoadFile_AttributesListOverwrittenByAttributes() Assert.Equal("fromAttributes", result["key1"]); } + + [Fact] + public void GetEnabledResourceDetector_ReturnsCorrectEnabledDetectors() + { + var detectors = new DotNetDetectors + { + AzureAppService = new object(), + Host = new object(), + OperatingSystem = null, + Process = new object(), + ProcessRuntime = null + }; + +#if NET + detectors.Container = new object(); +#endif + + var result = detectors.GetEnabledResourceDetectors(); + + var expected = new List + { + ResourceDetector.AzureAppService, + ResourceDetector.Host, + ResourceDetector.Process + }; + +#if NET + expected.Add(ResourceDetector.Container); +#endif + + Assert.Equal(expected.Count, result.Count); + foreach (var detector in expected) + { + Assert.Contains(detector, result); + } + } } diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestFile.yaml b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestFile.yaml index a6722a1859..4a6a91c840 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestFile.yaml +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestFile.yaml @@ -5,3 +5,12 @@ resource: - name: service.name value: unknown_service attributes_list: + detection/development: + detectors: + azureappservice: + container: + host: + operatingsystem: + process: + processruntime: + diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/ParserTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserTests.cs similarity index 59% rename from test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/ParserTests.cs rename to test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserTests.cs index ddec15a763..8236e7e733 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/ParserTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserTests.cs @@ -1,10 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser; using Xunit; +using YamlParser = OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser.Parser; -namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased; +namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased.Parser; [Collection("Non-Parallel Collection")] public class ParserTests @@ -12,7 +12,7 @@ public class ParserTests [Fact] public void Parse_FullConfigYaml_ShouldPopulateModelCorrectly() { - var config = Parser.ParseYaml("Configurations/FileBased/Files/TestFile.yaml"); + var config = YamlParser.ParseYaml("Configurations/FileBased/Files/TestFile.yaml"); Assert.NotNull(config); @@ -28,6 +28,26 @@ public void Parse_FullConfigYaml_ShouldPopulateModelCorrectly() Assert.NotNull(config.Resource.AttributesList); Assert.Empty(config.Resource.AttributesList); + Assert.NotNull(config.Resource.DetectionDevelopment); + +#if NET + string[] expectedDetecors = [ + "azureappservice", "container", "host", "operatingsystem", "process", "processruntime" + ]; +#endif +#if NETFRAMEWORK + string[] expectedDetecors = [ + "azureappservice", "host", "operatingsystem", "process", "processruntime" + ]; +#endif + + var detectors = config.Resource.DetectionDevelopment.Detectors; + Assert.NotNull(detectors); + + foreach (var alias in expectedDetecors) + { + FileBasedTestHelper.AssertAliasPropertyExists(detectors, alias); + } } [Fact] @@ -37,7 +57,7 @@ public void Parse_EnvVarYaml_ShouldPopulateModelCompletely() Environment.SetEnvironmentVariable("OTEL_SERVICE_NAME", "my‑service"); Environment.SetEnvironmentVariable("OTEL_RESOURCE_ATTRIBUTES", "key=value"); - var config = Parser.ParseYaml("Configurations/FileBased/Files/TestFileEnvVars.yaml"); + var config = YamlParser.ParseYaml("Configurations/FileBased/Files/TestFileEnvVars.yaml"); Assert.Equal("1.0-rc.1", config.FileFormat); var serviceAttr = config.Resource?.Attributes?.First(a => a.Name == "service.name"); From d5a160aaffb653421baae004214c327abb45ed0e Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Fri, 19 Sep 2025 09:32:00 +0200 Subject: [PATCH 3/8] merge two tests folders (FileBased/FileBasedConfiguration) --- .../Parser/ConditionalDeserializerTests.cs | 3 ++- .../Parser/EnvVarTypeConverterTests.cs | 2 +- .../FileBasedTestHelper.cs | 16 ---------------- 3 files changed, 3 insertions(+), 18 deletions(-) rename test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/{FileBasedConfiguration => FileBased}/Parser/ConditionalDeserializerTests.cs (97%) rename test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/{FileBasedConfiguration => FileBased}/Parser/EnvVarTypeConverterTests.cs (99%) delete mode 100644 test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/FileBasedTestHelper.cs diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/Parser/ConditionalDeserializerTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ConditionalDeserializerTests.cs similarity index 97% rename from test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/Parser/ConditionalDeserializerTests.cs rename to test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ConditionalDeserializerTests.cs index 18feab0c9d..0a4ee5fa4e 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/Parser/ConditionalDeserializerTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ConditionalDeserializerTests.cs @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser; +using OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased; using Vendors.YamlDotNet.Core; using Vendors.YamlDotNet.Serialization; using Xunit; using YamlParser = Vendors.YamlDotNet.Core.Parser; -namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBasedConfiguration.Parser; +namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased.Parser; public class ConditionalDeserializerTests { diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/Parser/EnvVarTypeConverterTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/EnvVarTypeConverterTests.cs similarity index 99% rename from test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/Parser/EnvVarTypeConverterTests.cs rename to test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/EnvVarTypeConverterTests.cs index 56bfc5b38f..9fc348687f 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/Parser/EnvVarTypeConverterTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/EnvVarTypeConverterTests.cs @@ -5,7 +5,7 @@ using Xunit; using YamlParser = Vendors.YamlDotNet.Core.Parser; -namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBasedConfiguration.Parser; +namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased.Parser; public class EnvVarTypeConverterTests { diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/FileBasedTestHelper.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/FileBasedTestHelper.cs deleted file mode 100644 index 5f87f9ceff..0000000000 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/FileBasedTestHelper.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -using Vendors.YamlDotNet.Core; - -namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBasedConfiguration; - -internal static class FileBasedTestHelper -{ - public static void MoveParserToScalar(IParser parser) - { - parser.MoveNext(); // StreamStart - parser.MoveNext(); // DocumentStart - parser.MoveNext(); // Scalar - } -} From a2d7d449459abd5285899740e1eff65e2145f4d8 Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Fri, 19 Sep 2025 09:40:04 +0200 Subject: [PATCH 4/8] Docs --- docs/config.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/docs/config.md b/docs/config.md index db21585e43..3c94da59cd 100644 --- a/docs/config.md +++ b/docs/config.md @@ -45,6 +45,34 @@ with environment variables taking precedence over `App.config` or `Web.config` f `SiteName\VirtualPath` ex: `MySite\MyApp` - If that is not the case it will use the name of the application [entry Assembly](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=net-7.0). +4. File-based Configuration (Experimental) + + > **Status:** [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) + > For more information about the OpenTelemetry configuration specification, see: + > **[File-based configuration documentation](https://opentelemetry.io/docs/specs/otel/configuration/sdk/)** + + You can configure OpenTelemetry using a YAML file. This method is disabled + by default and must be explicitly enabled. + + To enable file-based configuration, set the following environment variable: + + ```bash + OTEL_EXPERIMENTAL_FILE_BASED_CONFIGURATION_ENABLED=true + ``` + + By default, the value is false. + + You can also specify the configuration file path (default: config.yaml): + + ```bash + OTEL_EXPERIMENTAL_CONFIG_FILE=/path/to/config.yaml + ``` + + In your config file you can use environment variables in format: ${ENVIRONMENT_VARIABLE} + instead of "value" + + See [configuration examples](#configuration-examples) + By default we recommend using environment variables for configuration. However, if given setting supports it, then: @@ -503,3 +531,40 @@ 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) | + +## Configuration Examples + +### Resource Configuration + +You can configure text map context propagators directly in YAML or via the +`OTEL_RESOURCE_ATTRIBUTES` environment variable. + +``` yaml +resource: +# Configure resource attributes. Entries have higher priority than entries from .resource.attributes_list. +# Entries must contain .name and .value, and may optionally include .type. If an entry's .type omitted or null, string is used. +# The .value's type must match the .type. Values for .type include: string, bool, int, double, string_array, bool_array, int_array, double_array. + attributes: + - name: service.name + value: unknown_service + type: string + # Alternatively, configure via a comma-separated list (same format as OTEL_RESOURCE_ATTRIBUTES). + attributes_list: ${OTEL_RESOURCE_ATTRIBUTES} +``` + +### Resource Detectors Configuration + +For more details and updates, see: [Resource Detectors list and documentation](https://opentelemetry.io/docs/zero-code/dotnet/configuration/#resource-detectors) + +``` yaml +resource: + detection/development: + detectors: + azureappservice: # Detects Azure App Service resource information + container: # Detects container resource info (container.* attributes) [Core only] + host: # Detects host resource info (host.* attributes) + operatingsystem: # Detects OS-level attributes (os.*) + process: # Detects process-level attributes (process.*) + processruntime: # Detects process runtime attributes (process.runtime.*) + service: # Detects service.name and service.instance.id +``` From 1bb7a80e90312c5d21ac560105ebac51898b6981 Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Fri, 19 Sep 2025 09:51:09 +0200 Subject: [PATCH 5/8] update docs --- docs/config.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/config.md b/docs/config.md index 3c94da59cd..40f2d6dfb3 100644 --- a/docs/config.md +++ b/docs/config.md @@ -68,8 +68,11 @@ with environment variables taking precedence over `App.config` or `Web.config` f OTEL_EXPERIMENTAL_CONFIG_FILE=/path/to/config.yaml ``` - In your config file you can use environment variables in format: ${ENVIRONMENT_VARIABLE} - instead of "value" + In your config file you can use environment variables in the format `${ENVIRONMENT_VARIABLE}` + instead of a fixed value. + + You can also use `${ENVIRONMENT_VARIABLE:-value}`, where `value` is the fallback if the + environment variable is empty or not set. See [configuration examples](#configuration-examples) From e643a3114139d0a79a90192c0f869c18548fbd9e Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Fri, 19 Sep 2025 09:59:03 +0200 Subject: [PATCH 6/8] fix --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index 40f2d6dfb3..4469b815c3 100644 --- a/docs/config.md +++ b/docs/config.md @@ -539,7 +539,7 @@ instead. ### Resource Configuration -You can configure text map context propagators directly in YAML or via the +You can configure resource attributes directly in YAML or via the `OTEL_RESOURCE_ATTRIBUTES` environment variable. ``` yaml From 5fa44e7211f003bc0fce0677285d4c02459dd47f Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Fri, 19 Sep 2025 10:57:29 +0200 Subject: [PATCH 7/8] rename files --- .../Files/{TestFile.yaml => TestResourceFile.yaml} | 0 .../{TestFileEnvVars.yaml => TestResourceFileEnvVars.yaml} | 0 .../Parser/{ParserTests.cs => ParserResourceTests.cs} | 6 +++--- .../OpenTelemetry.AutoInstrumentation.Tests.csproj | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) rename test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/{TestFile.yaml => TestResourceFile.yaml} (100%) rename test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/{TestFileEnvVars.yaml => TestResourceFileEnvVars.yaml} (100%) rename test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/{ParserTests.cs => ParserResourceTests.cs} (95%) diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestFile.yaml b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestResourceFile.yaml similarity index 100% rename from test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestFile.yaml rename to test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestResourceFile.yaml diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestFileEnvVars.yaml b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestResourceFileEnvVars.yaml similarity index 100% rename from test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestFileEnvVars.yaml rename to test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/TestResourceFileEnvVars.yaml diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserResourceTests.cs similarity index 95% rename from test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserTests.cs rename to test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserResourceTests.cs index 8236e7e733..98c20cbffb 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Parser/ParserResourceTests.cs @@ -7,12 +7,12 @@ namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased.Parser; [Collection("Non-Parallel Collection")] -public class ParserTests +public class ParserResourceTests { [Fact] public void Parse_FullConfigYaml_ShouldPopulateModelCorrectly() { - var config = YamlParser.ParseYaml("Configurations/FileBased/Files/TestFile.yaml"); + var config = YamlParser.ParseYaml("Configurations/FileBased/Files/TestResourceFile.yaml"); Assert.NotNull(config); @@ -57,7 +57,7 @@ public void Parse_EnvVarYaml_ShouldPopulateModelCompletely() Environment.SetEnvironmentVariable("OTEL_SERVICE_NAME", "my‑service"); Environment.SetEnvironmentVariable("OTEL_RESOURCE_ATTRIBUTES", "key=value"); - var config = YamlParser.ParseYaml("Configurations/FileBased/Files/TestFileEnvVars.yaml"); + var config = YamlParser.ParseYaml("Configurations/FileBased/Files/TestResourceFileEnvVars.yaml"); Assert.Equal("1.0-rc.1", config.FileFormat); var serviceAttr = config.Resource?.Attributes?.First(a => a.Name == "service.name"); diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/OpenTelemetry.AutoInstrumentation.Tests.csproj b/test/OpenTelemetry.AutoInstrumentation.Tests/OpenTelemetry.AutoInstrumentation.Tests.csproj index 0aa0bc3fb7..50c9bfa3f0 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/OpenTelemetry.AutoInstrumentation.Tests.csproj +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/OpenTelemetry.AutoInstrumentation.Tests.csproj @@ -12,10 +12,10 @@ - + PreserveNewest - + PreserveNewest From 78ee235262d8e75030a823fec7d6c6499f518c21 Mon Sep 17 00:00:00 2001 From: Yevhenii Solomchenko Date: Fri, 19 Sep 2025 11:44:25 +0200 Subject: [PATCH 8/8] remove docs(will be in separete PR) --- docs/config.md | 68 -------------------------------------------------- 1 file changed, 68 deletions(-) diff --git a/docs/config.md b/docs/config.md index 4469b815c3..db21585e43 100644 --- a/docs/config.md +++ b/docs/config.md @@ -45,37 +45,6 @@ with environment variables taking precedence over `App.config` or `Web.config` f `SiteName\VirtualPath` ex: `MySite\MyApp` - If that is not the case it will use the name of the application [entry Assembly](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=net-7.0). -4. File-based Configuration (Experimental) - - > **Status:** [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) - > For more information about the OpenTelemetry configuration specification, see: - > **[File-based configuration documentation](https://opentelemetry.io/docs/specs/otel/configuration/sdk/)** - - You can configure OpenTelemetry using a YAML file. This method is disabled - by default and must be explicitly enabled. - - To enable file-based configuration, set the following environment variable: - - ```bash - OTEL_EXPERIMENTAL_FILE_BASED_CONFIGURATION_ENABLED=true - ``` - - By default, the value is false. - - You can also specify the configuration file path (default: config.yaml): - - ```bash - OTEL_EXPERIMENTAL_CONFIG_FILE=/path/to/config.yaml - ``` - - In your config file you can use environment variables in the format `${ENVIRONMENT_VARIABLE}` - instead of a fixed value. - - You can also use `${ENVIRONMENT_VARIABLE:-value}`, where `value` is the fallback if the - environment variable is empty or not set. - - See [configuration examples](#configuration-examples) - By default we recommend using environment variables for configuration. However, if given setting supports it, then: @@ -534,40 +503,3 @@ 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) | - -## Configuration Examples - -### Resource Configuration - -You can configure resource attributes directly in YAML or via the -`OTEL_RESOURCE_ATTRIBUTES` environment variable. - -``` yaml -resource: -# Configure resource attributes. Entries have higher priority than entries from .resource.attributes_list. -# Entries must contain .name and .value, and may optionally include .type. If an entry's .type omitted or null, string is used. -# The .value's type must match the .type. Values for .type include: string, bool, int, double, string_array, bool_array, int_array, double_array. - attributes: - - name: service.name - value: unknown_service - type: string - # Alternatively, configure via a comma-separated list (same format as OTEL_RESOURCE_ATTRIBUTES). - attributes_list: ${OTEL_RESOURCE_ATTRIBUTES} -``` - -### Resource Detectors Configuration - -For more details and updates, see: [Resource Detectors list and documentation](https://opentelemetry.io/docs/zero-code/dotnet/configuration/#resource-detectors) - -``` yaml -resource: - detection/development: - detectors: - azureappservice: # Detects Azure App Service resource information - container: # Detects container resource info (container.* attributes) [Core only] - host: # Detects host resource info (host.* attributes) - operatingsystem: # Detects OS-level attributes (os.*) - process: # Detects process-level attributes (process.*) - processruntime: # Detects process runtime attributes (process.runtime.*) - service: # Detects service.name and service.instance.id -```