From 4e6ac2e2f4010a83fb4da1320dd7d98d487dd761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 6 Apr 2023 12:25:16 +0200 Subject: [PATCH 01/11] Container resource detectors + manage resource detectors --- .cspell/other.txt | 2 + CHANGELOG.md | 4 ++ docs/config.md | 24 ++++++++++-- ...ry.AutoInstrumentation.Dependencies.nuspec | 2 + src/Directory.Packages.props | 1 + .../Configurations/ConfigurationExtensions.cs | 2 +- .../Configurations/ConfigurationKeys.cs | 10 +++++ .../Configurations/GeneralSettings.cs | 13 ++++++- .../Configurations/LogSettings.cs | 2 +- .../Configurations/MetricSettings.cs | 2 +- .../Configurations/ResourceConfigurator.cs | 29 +++++++++++--- .../Configurations/ResourceDetector.cs | 38 +++++++++++++++++++ .../Configurations/TracerSettings.cs | 2 +- .../Instrumentation.cs | 8 ++-- .../Logger/LogBuilderExtensions.cs | 2 +- .../OpenTelemetry.AutoInstrumentation.csproj | 1 + .../ServiceNameConfiguratorTests.cs | 7 +++- .../Configurations/SettingsTests.cs | 23 +++++++++++ 18 files changed, 151 insertions(+), 21 deletions(-) create mode 100644 src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceDetector.cs diff --git a/.cspell/other.txt b/.cspell/other.txt index cc02d16fac..4bb0987620 100644 --- a/.cspell/other.txt +++ b/.cspell/other.txt @@ -46,3 +46,5 @@ MASSTRANSIT HTTPCLIENT GRPCNETCLIENT ENTITYFRAMEWORKCORE +ENVIRONMENTALVARIABLES +TELEMETRYSDK diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e7180890e..47daafa685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h ensuring back off instead of crashing, improving overall stability. - The environment variable `OTEL_DOTNET_AUTO_RULE_ENGINE_ENABLED` could be used to enable or disable the rule engine. +- Support for Container resource detector. +- Support for enabling well known resource detectors such by + - `OTEL_DOTNET_AUTO_RESOURCE_DETECTOR_ENABLED` + - `OTEL_DOTNET_AUTO_{0}_RESOURCE_DETECTOR_ENABLED`. ### Changed diff --git a/docs/config.md b/docs/config.md index 2eea45f54a..fbee983bbc 100644 --- a/docs/config.md +++ b/docs/config.md @@ -62,7 +62,23 @@ However, if given setting supports it, then: A resource is the immutable representation of the entity producing the telemetry. See [Resource semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions) -for more details. +for more details. Resource are detected by resource detectors. + +| Environment variable | Description | Default value | Status | +|--------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------| +| `OTEL_DOTNET_AUTO_RESOURCE_DETECTOR_ENABLED` | Enables all resource detectors. | `true` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_DOTNET_AUTO_{0}_RESOURCE_DETECTOR_ENABLED` | Configuration pattern for enabling a specific resource detector, where `{0}` is the uppercase id of the resource detector you want to enable. Overrides `OTEL_DOTNET_AUTO_RESOURCE_DETECTOR_ENABLED`. | `true` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | + +Supported resource detectors: + +| ID | Description | Documentation | Status | +|--------------------------|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| +| `ENVIRONMENTALVARIABLES` | Environment variables detector | See /[1/] | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `TELEMETRYSDK` | Telemetry SDK detector | [Telemetry SDK resources documentation](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md?plain=1#L117) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `CONTAINER` | Container detector | [Container resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/src/OpenTelemetry.ResourceDetectors.Container/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | + +/[1/] `ENVIRONMENTALVARIABLES` detector is using following environmental variables +to detect resources: | Environment variable | Description | Default value | Status | |----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| @@ -337,9 +353,9 @@ or when the deployment changes or the Automatic Instrumentation library is upgraded. Once validated, there's no need to revalidate the rules when the application restarts. -| Environment variable | Description | Default value | Status | -|--------------------------------------- |---------------------|----------------|-----------------------------------------------------------------------------------------------------------------------------------| -| `OTEL_DOTNET_AUTO_RULE_ENGINE_ENABLED` | Enables RuleEngine. | `true` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| Environment variable | Description | Default value | Status | +|----------------------------------------|---------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------| +| `OTEL_DOTNET_AUTO_RULE_ENGINE_ENABLED` | Enables RuleEngine. | `true` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | ## .NET CLR Profiler diff --git a/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec b/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec index 19e918da3e..87d0ed8ce0 100644 --- a/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec +++ b/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec @@ -38,6 +38,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 9a8f99a0b7..1e91b4777e 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -24,6 +24,7 @@ + diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index 46953c20ba..e45125e5a6 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -20,7 +20,7 @@ namespace OpenTelemetry.AutoInstrumentation.Configurations; internal static class ConfigurationExtensions { - public static IList ParseEnabledEnumList(this Configuration source, bool enabledByDefault, string enabledConfigurationTemplate) + public static IReadOnlyList ParseEnabledEnumList(this Configuration source, bool enabledByDefault, string enabledConfigurationTemplate) where TEnum : struct, Enum, IConvertible { var allConfigurations = Enum.GetValues(typeof(TEnum)).Cast().ToArray(); diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index ef7169128f..39bf0ef69b 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -60,6 +60,16 @@ internal static class ConfigurationKeys /// public const string InstrumentationEnabled = "OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"; + /// + /// Configuration key for disabling all trace instrumentations. + /// + public const string ResourceDetectorEnabled = "OTEL_DOTNET_AUTO_RESOURCE_DETECTOR_ENABLED"; + + /// + /// Configuration key template for disabled trace instrumentations. + /// + public const string EnabledResourceDetectorTemplate = "OTEL_DOTNET_AUTO_{0}_RESOURCE_DETECTOR_ENABLED"; + /// /// Configuration keys for traces. /// diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/GeneralSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/GeneralSettings.cs index 39d9b115f6..ffcdda9b78 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/GeneralSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/GeneralSettings.cs @@ -21,7 +21,12 @@ internal class GeneralSettings : Settings /// /// Gets the list of plugins represented by . /// - public IList Plugins { get; private set; } = new List(); + public IList Plugins { get; } = new List(); + + /// + /// Gets the list of enabled resource detectors. + /// + public IReadOnlyList EnabledResourceDetectors { get; private set; } = new List(); /// /// Gets a value indicating whether the event should trigger @@ -46,6 +51,12 @@ protected override void OnLoad(Configuration configuration) } } + var resourceDetectorsEnabledByDefault = configuration.GetBool(ConfigurationKeys.ResourceDetectorEnabled) ?? true; + + EnabledResourceDetectors = configuration.ParseEnabledEnumList( + enabledByDefault: resourceDetectorsEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.EnabledResourceDetectorTemplate); + FlushOnUnhandledException = configuration.GetBool(ConfigurationKeys.FlushOnUnhandledException) ?? false; SetupSdk = configuration.GetBool(ConfigurationKeys.SetupSdk) ?? true; } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs index 7a7555c137..bb4c8b04ab 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs @@ -48,7 +48,7 @@ internal class LogSettings : Settings /// /// Gets the list of enabled instrumentations. /// - public IList EnabledInstrumentations { get; private set; } = new List(); + public IReadOnlyList EnabledInstrumentations { get; private set; } = new List(); protected override void OnLoad(Configuration configuration) { diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs index a4ccc1a79b..ecf0aaf356 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs @@ -43,7 +43,7 @@ internal class MetricSettings : Settings /// /// Gets the list of enabled meters. /// - public IList EnabledInstrumentations { get; private set; } = new List(); + public IReadOnlyList EnabledInstrumentations { get; private set; } = new List(); /// /// Gets the list of meters to be added to the MeterProvider at the startup. diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs index be67fa3e01..d713d4bc21 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs @@ -14,6 +14,8 @@ // limitations under the License. // +using System.Runtime.CompilerServices; +using OpenTelemetry.Extensions.Docker.Resources; using OpenTelemetry.Resources; namespace OpenTelemetry.AutoInstrumentation.Configurations; @@ -22,13 +24,21 @@ internal static class ResourceConfigurator { internal const string ServiceNameAttribute = "service.name"; - public static ResourceBuilder CreateResourceBuilder() + public static ResourceBuilder CreateResourceBuilder(IReadOnlyList enabledResourceDetectors) { var resourceBuilder = ResourceBuilder - .CreateEmpty() // Don't use CreateDefault because it puts service name unknown by default. - .AddEnvironmentVariableDetector() - .AddTelemetrySdk() - .AddAttributes(new KeyValuePair[] { new(Constants.Tracer.AutoInstrumentationVersionName, Constants.Tracer.Version) }); + .CreateEmpty(); // Don't use CreateDefault because it puts service name unknown by default. + + foreach (var enabledResourceDetector in enabledResourceDetectors) + { + resourceBuilder = enabledResourceDetector switch + { + ResourceDetector.EnvironmentalVariables => resourceBuilder.AddEnvironmentVariableDetector(), + ResourceDetector.TelemetrySdk => resourceBuilder.AddTelemetrySdk().AddAttributes(new KeyValuePair[] { new(Constants.Tracer.AutoInstrumentationVersionName, Constants.Tracer.Version) }), + ResourceDetector.Container => Wrappers.AddContainerResourceDetector(resourceBuilder), + _ => resourceBuilder, + }; + } var pluginManager = Instrumentation.PluginManager; if (pluginManager != null) @@ -45,4 +55,13 @@ public static ResourceBuilder CreateResourceBuilder() return resourceBuilder; } + + private static class Wrappers + { + [MethodImpl(MethodImplOptions.NoInlining)] + public static ResourceBuilder AddContainerResourceDetector(ResourceBuilder resourceBuilder) + { + return resourceBuilder.AddDetector(new DockerResourceDetector()); + } + } } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceDetector.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceDetector.cs new file mode 100644 index 0000000000..0b3a1b30de --- /dev/null +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceDetector.cs @@ -0,0 +1,38 @@ +// +// 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. +// + +namespace OpenTelemetry.AutoInstrumentation.Configurations; + +/// +/// Enum representing supported resource detectors. +/// +internal enum ResourceDetector +{ + /// + /// Environmental variables resource detector. + /// + EnvironmentalVariables = 0, + + /// + /// TelemetrySdk resource detector. + /// + TelemetrySdk = 1, + + /// + /// Container resource detector. + /// + Container = 2 +} diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs index b5e8524eec..e353bd442a 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs @@ -48,7 +48,7 @@ internal class TracerSettings : Settings /// /// Gets the list of enabled instrumentations. /// - public IList EnabledInstrumentations { get; private set; } = new List(); + public IReadOnlyList EnabledInstrumentations { get; private set; } = new List(); /// /// Gets the list of activity configurations to be added to the tracer at the startup. diff --git a/src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs b/src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs index db0ae84fa4..5ebc03a9c2 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Instrumentation.cs @@ -134,7 +134,7 @@ public static void Initialize() { var builder = Sdk .CreateTracerProviderBuilder() - .SetResourceBuilder(ResourceConfigurator.CreateResourceBuilder()) + .SetResourceBuilder(ResourceConfigurator.CreateResourceBuilder(GeneralSettings.Value.EnabledResourceDetectors)) .UseEnvironmentVariables(LazyInstrumentationLoader, TracerSettings.Value, _pluginManager) .InvokePlugins(_pluginManager); @@ -154,7 +154,7 @@ public static void Initialize() { var builder = Sdk .CreateMeterProviderBuilder() - .SetResourceBuilder(ResourceConfigurator.CreateResourceBuilder()) + .SetResourceBuilder(ResourceConfigurator.CreateResourceBuilder(GeneralSettings.Value.EnabledResourceDetectors)) .UseEnvironmentVariables(LazyInstrumentationLoader, MetricSettings.Value, _pluginManager) .InvokePlugins(_pluginManager); @@ -181,7 +181,7 @@ public static void Initialize() } } - private static void AddLazilyLoadedMetricInstrumentations(LazyInstrumentationLoader lazyInstrumentationLoader, IList enabledInstrumentations) + private static void AddLazilyLoadedMetricInstrumentations(LazyInstrumentationLoader lazyInstrumentationLoader, IReadOnlyList enabledInstrumentations) { foreach (var instrumentation in enabledInstrumentations) { @@ -213,7 +213,7 @@ private static void AddLazilyLoadedMetricInstrumentations(LazyInstrumentationLoa } } - private static void AddLazilyLoadedTraceInstrumentations(LazyInstrumentationLoader lazyInstrumentationLoader, PluginManager pluginManager, IList enabledInstrumentations) + private static void AddLazilyLoadedTraceInstrumentations(LazyInstrumentationLoader lazyInstrumentationLoader, PluginManager pluginManager, IReadOnlyList enabledInstrumentations) { foreach (var instrumentation in enabledInstrumentations) { diff --git a/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs index 1398376c33..018eb3b80e 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Logger/LogBuilderExtensions.cs @@ -46,7 +46,7 @@ public static ILoggingBuilder AddOpenTelemetryLogs(this ILoggingBuilder builder) builder.AddOpenTelemetry(options => { - options.SetResourceBuilder(ResourceConfigurator.CreateResourceBuilder()); + options.SetResourceBuilder(ResourceConfigurator.CreateResourceBuilder(Instrumentation.GeneralSettings.Value.EnabledResourceDetectors)); options.IncludeFormattedMessage = settings.IncludeFormattedMessage; diff --git a/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj b/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj index 16546f282b..3e4064eda3 100644 --- a/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj +++ b/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj @@ -22,6 +22,7 @@ + diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ServiceNameConfiguratorTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ServiceNameConfiguratorTests.cs index 9901f613fd..2a337a56d3 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ServiceNameConfiguratorTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ServiceNameConfiguratorTests.cs @@ -29,7 +29,7 @@ public class ServiceNameConfiguratorTests [Fact] public void GetFallbackServiceName() { - var resourceBuilder = ResourceConfigurator.CreateResourceBuilder(); + var resourceBuilder = ResourceConfigurator.CreateResourceBuilder(new List()); var resource = resourceBuilder.Build(); var serviceName = resource.Attributes.FirstOrDefault(a => a.Key == ServiceName).Value as string; @@ -44,7 +44,10 @@ public void ServiceName_Retained_EnvVarSet() { Environment.SetEnvironmentVariable(OtelServiceVariable, setServiceName); - var resourceBuilder = ResourceConfigurator.CreateResourceBuilder(); + var resourceBuilder = ResourceConfigurator.CreateResourceBuilder(new List + { + ResourceDetector.EnvironmentalVariables + }); var resource = resourceBuilder.Build(); var serviceName = resource.Attributes.FirstOrDefault(a => a.Key == ServiceName).Value as string; diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index 9c41a5cc98..533461b3dc 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -46,6 +46,7 @@ internal void GeneralSettings_DefaultValues() using (new AssertionScope()) { settings.Plugins.Should().BeEmpty(); + settings.EnabledResourceDetectors.Should().NotBeEmpty(); settings.FlushOnUnhandledException.Should().BeFalse(); settings.OtlpExportProtocol.Should().Be(OtlpExportProtocol.HttpProtobuf); } @@ -299,6 +300,20 @@ internal void FlushOnUnhandledException_DependsOnCorrespondingEnvVariable(string settings.FlushOnUnhandledException.Should().Be(expectedValue); } + [Theory] + [InlineData("ENVIRONMENTALVARIABLES", ResourceDetector.EnvironmentalVariables)] + [InlineData("TELEMETRYSDK", ResourceDetector.TelemetrySdk)] + [InlineData("CONTAINER", ResourceDetector.Container)] + internal void GeneralSettings_Instrumentations_SupportedValues(string resourceDetector, ResourceDetector expectedResourceDetector) + { + Environment.SetEnvironmentVariable(ConfigurationKeys.ResourceDetectorEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.EnabledResourceDetectorTemplate, resourceDetector), "true"); + + var settings = Settings.FromDefaultSources(); + + settings.EnabledResourceDetectors.Should().BeEquivalentTo(new List { expectedResourceDetector }); + } + private static void ClearEnvVars() { Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, null); @@ -329,6 +344,14 @@ private static void ClearEnvVars() Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.InstrumentationOptions.GraphQLSetDocument, null); Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpProtocol, null); Environment.SetEnvironmentVariable(ConfigurationKeys.FlushOnUnhandledException, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.ResourceDetectorEnabled, null); + + Environment.SetEnvironmentVariable(ConfigurationKeys.ResourceDetectorEnabled, null); + foreach (var re in Enum.GetValues(typeof(ResourceDetector)).Cast()) + { + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.EnabledResourceDetectorTemplate, re.ToString().ToUpperInvariant()), null); + } + Environment.SetEnvironmentVariable(ConfigurationKeys.Sdk.Propagators, null); } } From e131bec6fbb876f7623c72beb0ea06ba84cbc021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 7 Apr 2023 07:24:18 +0200 Subject: [PATCH 02/11] switch package --- .../OpenTelemetry.AutoInstrumentation.Dependencies.nuspec | 4 ++-- src/Directory.Packages.props | 2 +- .../Configurations/ResourceConfigurator.cs | 4 ++-- .../OpenTelemetry.AutoInstrumentation.csproj | 2 +- test/IntegrationTests/ModuleTests.cs | 1 + 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec b/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec index 87d0ed8ce0..f7a5e560d9 100644 --- a/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec +++ b/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec @@ -38,7 +38,7 @@ - + @@ -57,7 +57,7 @@ - + diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 1e91b4777e..f54fb33d02 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -24,7 +24,7 @@ - + diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs index d713d4bc21..b23b7489ba 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs @@ -15,7 +15,7 @@ // using System.Runtime.CompilerServices; -using OpenTelemetry.Extensions.Docker.Resources; +using OpenTelemetry.ResourceDetectors.Container; using OpenTelemetry.Resources; namespace OpenTelemetry.AutoInstrumentation.Configurations; @@ -61,7 +61,7 @@ private static class Wrappers [MethodImpl(MethodImplOptions.NoInlining)] public static ResourceBuilder AddContainerResourceDetector(ResourceBuilder resourceBuilder) { - return resourceBuilder.AddDetector(new DockerResourceDetector()); + return resourceBuilder.AddDetector(new ContainerResourceDetector()); } } } diff --git a/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj b/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj index 3e4064eda3..7332edab74 100644 --- a/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj +++ b/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj @@ -22,7 +22,7 @@ - + diff --git a/test/IntegrationTests/ModuleTests.cs b/test/IntegrationTests/ModuleTests.cs index 2341a4b23b..4c7d7849e9 100644 --- a/test/IntegrationTests/ModuleTests.cs +++ b/test/IntegrationTests/ModuleTests.cs @@ -70,6 +70,7 @@ public async Task DefaultNoExporters() public async Task Minimal() { SetEnvironmentVariable(ConfigurationKeys.InstrumentationEnabled, "false"); + SetEnvironmentVariable(ConfigurationKeys.ResourceDetectorEnabled, "false"); SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, Constants.ConfigurationValues.None); From b74af64ca078f945359cedd489d0d8baf9267964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 7 Apr 2023 07:38:51 +0200 Subject: [PATCH 03/11] generated file --- .../netfx_assembly_redirection.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h b/src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h index 89c7d9e58e..faa76c9929 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/netfx_assembly_redirection.h @@ -47,6 +47,7 @@ void CorProfiler::InitNetFxAssemblyRedirectsMap() { L"OpenTelemetry.Instrumentation.Runtime", {1, 1, 0, 2} }, { L"OpenTelemetry.Instrumentation.SqlClient", {1, 0, 0, 0} }, { L"OpenTelemetry.Instrumentation.Wcf", {1, 0, 0, 9} }, + { L"OpenTelemetry.ResourceDetectors.Container", {1, 0, 0, 3} }, { L"OpenTelemetry.Shims.OpenTracing", {1, 0, 0, 0} }, { L"OpenTracing", {0, 12, 1, 0} }, { L"System.AppContext", {4, 1, 2, 0} }, From 1cb4c648d3e25fce971ad51430edc5c9b706cad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 7 Apr 2023 07:39:12 +0200 Subject: [PATCH 04/11] Fix build tests --- .../BuildTests.DistributionStructure_alpine-linux.verified.txt | 1 + .../BuildTests.DistributionStructure_linux.verified.txt | 1 + .../BuildTests.DistributionStructure_osx.verified.txt | 1 + .../BuildTests.DistributionStructure_windows.verified.txt | 2 ++ 4 files changed, 5 insertions(+) diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt index a3ce8803a2..d0dbad64a5 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_alpine-linux.verified.txt @@ -36,6 +36,7 @@ /net/OpenTelemetry.Instrumentation.SqlClient.dll, /net/OpenTelemetry.Instrumentation.StackExchangeRedis.dll, /net/OpenTelemetry.Instrumentation.Wcf.dll, + /net/OpenTelemetry.ResourceDetectors.Container.dll, /net/OpenTelemetry.Shims.OpenTracing.dll, /net/OpenTelemetry.dll, /net/OpenTracing.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt index cdfb44f91e..8f0f064d39 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_linux.verified.txt @@ -36,6 +36,7 @@ /net/OpenTelemetry.Instrumentation.SqlClient.dll, /net/OpenTelemetry.Instrumentation.StackExchangeRedis.dll, /net/OpenTelemetry.Instrumentation.Wcf.dll, + /net/OpenTelemetry.ResourceDetectors.Container.dll, /net/OpenTelemetry.Shims.OpenTracing.dll, /net/OpenTelemetry.dll, /net/OpenTracing.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt index b177dd7b2f..3cb25139bc 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_osx.verified.txt @@ -35,6 +35,7 @@ /net/OpenTelemetry.Instrumentation.SqlClient.dll, /net/OpenTelemetry.Instrumentation.StackExchangeRedis.dll, /net/OpenTelemetry.Instrumentation.Wcf.dll, + /net/OpenTelemetry.ResourceDetectors.Container.dll, /net/OpenTelemetry.Shims.OpenTracing.dll, /net/OpenTelemetry.dll, /net/OpenTracing.dll, diff --git a/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt b/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt index 65861c89a4..eeca22480b 100644 --- a/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt +++ b/test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt @@ -35,6 +35,7 @@ \net\OpenTelemetry.Instrumentation.SqlClient.dll, \net\OpenTelemetry.Instrumentation.StackExchangeRedis.dll, \net\OpenTelemetry.Instrumentation.Wcf.dll, + \net\OpenTelemetry.ResourceDetectors.Container.dll, \net\OpenTelemetry.Shims.OpenTracing.dll, \net\OpenTelemetry.dll, \net\OpenTracing.dll, @@ -77,6 +78,7 @@ \netfx\OpenTelemetry.Instrumentation.Runtime.dll, \netfx\OpenTelemetry.Instrumentation.SqlClient.dll, \netfx\OpenTelemetry.Instrumentation.Wcf.dll, + \netfx\OpenTelemetry.ResourceDetectors.Container.dll, \netfx\OpenTelemetry.Shims.OpenTracing.dll, \netfx\OpenTelemetry.dll, \netfx\OpenTracing.dll, From a6ceb1673c528fc64ac5993acce3451d3d107d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 7 Apr 2023 07:39:18 +0200 Subject: [PATCH 05/11] Fix Module tests --- test/IntegrationTests/ModuleTests.Default.NetCore.verified.txt | 3 ++- test/IntegrationTests/ModuleTests.Default.NetFx.verified.txt | 3 ++- .../ModuleTests.DefaultNoExporters.NetCore.verified.txt | 3 ++- .../ModuleTests.DefaultNoExporters.NetFx.verified.txt | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/IntegrationTests/ModuleTests.Default.NetCore.verified.txt b/test/IntegrationTests/ModuleTests.Default.NetCore.verified.txt index ad00d12726..8a80a7c718 100644 --- a/test/IntegrationTests/ModuleTests.Default.NetCore.verified.txt +++ b/test/IntegrationTests/ModuleTests.Default.NetCore.verified.txt @@ -8,5 +8,6 @@ OpenTelemetry.Exporter.OpenTelemetryProtocol, OpenTelemetry.Instrumentation.Http, OpenTelemetry.Instrumentation.Process, - OpenTelemetry.Instrumentation.Runtime + OpenTelemetry.Instrumentation.Runtime, + OpenTelemetry.ResourceDetectors.Container ] \ No newline at end of file diff --git a/test/IntegrationTests/ModuleTests.Default.NetFx.verified.txt b/test/IntegrationTests/ModuleTests.Default.NetFx.verified.txt index 107812a77e..be129b31a7 100644 --- a/test/IntegrationTests/ModuleTests.Default.NetFx.verified.txt +++ b/test/IntegrationTests/ModuleTests.Default.NetFx.verified.txt @@ -7,5 +7,6 @@ OpenTelemetry.Exporter.OpenTelemetryProtocol, OpenTelemetry.Instrumentation.Http, OpenTelemetry.Instrumentation.Process, - OpenTelemetry.Instrumentation.Runtime + OpenTelemetry.Instrumentation.Runtime, + OpenTelemetry.ResourceDetectors.Container ] \ No newline at end of file diff --git a/test/IntegrationTests/ModuleTests.DefaultNoExporters.NetCore.verified.txt b/test/IntegrationTests/ModuleTests.DefaultNoExporters.NetCore.verified.txt index 6b8c55596e..e39298893f 100644 --- a/test/IntegrationTests/ModuleTests.DefaultNoExporters.NetCore.verified.txt +++ b/test/IntegrationTests/ModuleTests.DefaultNoExporters.NetCore.verified.txt @@ -7,5 +7,6 @@ OpenTelemetry.AutoInstrumentation.StartupHook, OpenTelemetry.Exporter.OpenTelemetryProtocol, OpenTelemetry.Instrumentation.Process, - OpenTelemetry.Instrumentation.Runtime + OpenTelemetry.Instrumentation.Runtime, + OpenTelemetry.ResourceDetectors.Container ] \ No newline at end of file diff --git a/test/IntegrationTests/ModuleTests.DefaultNoExporters.NetFx.verified.txt b/test/IntegrationTests/ModuleTests.DefaultNoExporters.NetFx.verified.txt index c3a5c9d244..383e242157 100644 --- a/test/IntegrationTests/ModuleTests.DefaultNoExporters.NetFx.verified.txt +++ b/test/IntegrationTests/ModuleTests.DefaultNoExporters.NetFx.verified.txt @@ -6,5 +6,6 @@ OpenTelemetry.AutoInstrumentation.Loader, OpenTelemetry.Exporter.OpenTelemetryProtocol, OpenTelemetry.Instrumentation.Process, - OpenTelemetry.Instrumentation.Runtime + OpenTelemetry.Instrumentation.Runtime, + OpenTelemetry.ResourceDetectors.Container ] \ No newline at end of file From 34abca9d812f55e0a80b2f055d5db65a6f61efb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 13 Apr 2023 07:13:44 +0200 Subject: [PATCH 06/11] pr feedback --- CHANGELOG.md | 3 +- docs/config.md | 37 +++++++++---------- .../Configurations/ConfigurationKeys.cs | 4 +- .../Configurations/ResourceConfigurator.cs | 10 +++-- .../Configurations/ResourceDetector.cs | 12 +----- .../Configurations/SettingsTests.cs | 6 +-- 6 files changed, 32 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47daafa685..73c17514b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,8 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h - The environment variable `OTEL_DOTNET_AUTO_RULE_ENGINE_ENABLED` could be used to enable or disable the rule engine. - Support for Container resource detector. -- Support for enabling well known resource detectors such by +- Support for enabling well known resource detectors + by using the environment variables - `OTEL_DOTNET_AUTO_RESOURCE_DETECTOR_ENABLED` - `OTEL_DOTNET_AUTO_{0}_RESOURCE_DETECTOR_ENABLED`. diff --git a/docs/config.md b/docs/config.md index f8d5bb0331..4a4b1e794c 100644 --- a/docs/config.md +++ b/docs/config.md @@ -62,7 +62,16 @@ However, if given setting supports it, then: A resource is the immutable representation of the entity producing the telemetry. See [Resource semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions) -for more details. Resource are detected by resource detectors. +for more details. + +Resources can be configured by following environmental variables + +| Environment variable | Description | Default value | Status | +|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| +| `OTEL_RESOURCE_ATTRIBUTES` | Key-value pairs to be used as resource attributes. See [Resource SDK](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable) for more details. | See [Resource semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value) for details. | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_SERVICE_NAME` | Sets the value of the [`service.name`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service) resource attribute. If `service.name` is provided in `OTEL_RESOURCE_ATTRIBUTES`, the value of `OTEL_SERVICE_NAME` takes precedence. | See [Service name automatic detection](#configuration-methods) under Configuration method section. | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | + +and detected by resource detectors. | Environment variable | Description | Default value | Status | |--------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------| @@ -71,19 +80,9 @@ for more details. Resource are detected by resource detectors. Supported resource detectors: -| ID | Description | Documentation | Status | -|--------------------------|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| -| `ENVIRONMENTALVARIABLES` | Environment variables detector | See /[1/] | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `TELEMETRYSDK` | Telemetry SDK detector | [Telemetry SDK resources documentation](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md?plain=1#L117) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `CONTAINER` | Container detector | [Container resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/src/OpenTelemetry.ResourceDetectors.Container/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | - -/[1/] `ENVIRONMENTALVARIABLES` detector is using following environmental variables -to detect resources: - -| Environment variable | Description | Default value | Status | -|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| -| `OTEL_RESOURCE_ATTRIBUTES` | Key-value pairs to be used as resource attributes. See [Resource SDK](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable) for more details. | See [Resource semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value) for details. | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_SERVICE_NAME` | Sets the value of the [`service.name`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service) resource attribute. If `service.name` is provided in `OTEL_RESOURCE_ATTRIBUTES`, the value of `OTEL_SERVICE_NAME` takes precedence. | See [Service name automatic detection](#configuration-methods) under Configuration method section. | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| ID | Description | Documentation | Status | +|-------------|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| +| `CONTAINER` | Container detector | [Container resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/src/OpenTelemetry.ResourceDetectors.Container/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | ## Instrumentations @@ -103,13 +102,13 @@ for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentatio | Environment variable | Description | Default value | Status | |--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| | `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Enables all instrumentations. | `true` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Enables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling a specific trace instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Enables all instrumentations. | `true` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Enables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling a specific trace instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | | `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Disables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling a specific metric instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling a specific metric instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | | `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Disables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling a specific log instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling a specific log instrumentation, where `{0}` is the uppercase id of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | ### Traces instrumentations diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index 39bf0ef69b..614a843d86 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -61,12 +61,12 @@ internal static class ConfigurationKeys public const string InstrumentationEnabled = "OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"; /// - /// Configuration key for disabling all trace instrumentations. + /// Configuration key for enabling all resource detectors. /// public const string ResourceDetectorEnabled = "OTEL_DOTNET_AUTO_RESOURCE_DETECTOR_ENABLED"; /// - /// Configuration key template for disabled trace instrumentations. + /// Configuration key template for enabling resource detectors. /// public const string EnabledResourceDetectorTemplate = "OTEL_DOTNET_AUTO_{0}_RESOURCE_DETECTOR_ENABLED"; diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs index b23b7489ba..cf18d23e79 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs @@ -27,14 +27,18 @@ internal static class ResourceConfigurator public static ResourceBuilder CreateResourceBuilder(IReadOnlyList enabledResourceDetectors) { var resourceBuilder = ResourceBuilder - .CreateEmpty(); // Don't use CreateDefault because it puts service name unknown by default. + .CreateEmpty() // Don't use CreateDefault because it puts service name unknown by default. + .AddEnvironmentVariableDetector() + .AddTelemetrySdk() + .AddAttributes(new KeyValuePair[] + { + new(Constants.Tracer.AutoInstrumentationVersionName, Constants.Tracer.Version) + }); foreach (var enabledResourceDetector in enabledResourceDetectors) { resourceBuilder = enabledResourceDetector switch { - ResourceDetector.EnvironmentalVariables => resourceBuilder.AddEnvironmentVariableDetector(), - ResourceDetector.TelemetrySdk => resourceBuilder.AddTelemetrySdk().AddAttributes(new KeyValuePair[] { new(Constants.Tracer.AutoInstrumentationVersionName, Constants.Tracer.Version) }), ResourceDetector.Container => Wrappers.AddContainerResourceDetector(resourceBuilder), _ => resourceBuilder, }; diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceDetector.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceDetector.cs index 0b3a1b30de..4eaef227c1 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceDetector.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceDetector.cs @@ -21,18 +21,8 @@ namespace OpenTelemetry.AutoInstrumentation.Configurations; /// internal enum ResourceDetector { - /// - /// Environmental variables resource detector. - /// - EnvironmentalVariables = 0, - - /// - /// TelemetrySdk resource detector. - /// - TelemetrySdk = 1, - /// /// Container resource detector. /// - Container = 2 + Container = 0 } diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index 533461b3dc..b9962505b0 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -301,8 +301,6 @@ internal void FlushOnUnhandledException_DependsOnCorrespondingEnvVariable(string } [Theory] - [InlineData("ENVIRONMENTALVARIABLES", ResourceDetector.EnvironmentalVariables)] - [InlineData("TELEMETRYSDK", ResourceDetector.TelemetrySdk)] [InlineData("CONTAINER", ResourceDetector.Container)] internal void GeneralSettings_Instrumentations_SupportedValues(string resourceDetector, ResourceDetector expectedResourceDetector) { @@ -347,9 +345,9 @@ private static void ClearEnvVars() Environment.SetEnvironmentVariable(ConfigurationKeys.ResourceDetectorEnabled, null); Environment.SetEnvironmentVariable(ConfigurationKeys.ResourceDetectorEnabled, null); - foreach (var re in Enum.GetValues(typeof(ResourceDetector)).Cast()) + foreach (var resourceDetector in Enum.GetValues(typeof(ResourceDetector)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.EnabledResourceDetectorTemplate, re.ToString().ToUpperInvariant()), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.EnabledResourceDetectorTemplate, resourceDetector.ToString().ToUpperInvariant()), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Sdk.Propagators, null); From d563c02bf0a9008efb3588410af6b8231310b7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 13 Apr 2023 07:15:28 +0200 Subject: [PATCH 07/11] remove space --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73c17514b1..62797aa12f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h used to enable or disable the rule engine. - Support for Container resource detector. - Support for enabling well known resource detectors - by using the environment variables + by using the environment variables - `OTEL_DOTNET_AUTO_RESOURCE_DETECTOR_ENABLED` - `OTEL_DOTNET_AUTO_{0}_RESOURCE_DETECTOR_ENABLED`. From d70787b6b237444749c1815c8b7eee406ea3dc49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 13 Apr 2023 07:55:25 +0200 Subject: [PATCH 08/11] missing file --- .../Configurations/ServiceNameConfiguratorTests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ServiceNameConfiguratorTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ServiceNameConfiguratorTests.cs index 2a337a56d3..4c5c052c3b 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ServiceNameConfiguratorTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ServiceNameConfiguratorTests.cs @@ -44,10 +44,7 @@ public void ServiceName_Retained_EnvVarSet() { Environment.SetEnvironmentVariable(OtelServiceVariable, setServiceName); - var resourceBuilder = ResourceConfigurator.CreateResourceBuilder(new List - { - ResourceDetector.EnvironmentalVariables - }); + var resourceBuilder = ResourceConfigurator.CreateResourceBuilder(Array.Empty()); var resource = resourceBuilder.Build(); var serviceName = resource.Attributes.FirstOrDefault(a => a.Key == ServiceName).Value as string; From 95c96685d97d30e362ebafc529fe538ab9632cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 13 Apr 2023 08:03:13 +0200 Subject: [PATCH 09/11] revert cspell dict --- .cspell/other.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/.cspell/other.txt b/.cspell/other.txt index 2fbbd715bb..a42246a5ca 100644 --- a/.cspell/other.txt +++ b/.cspell/other.txt @@ -46,7 +46,5 @@ MASSTRANSIT HTTPCLIENT GRPCNETCLIENT ENTITYFRAMEWORKCORE -ENVIRONMENTALVARIABLES -TELEMETRYSDK appcmd inetsrv From 1ac46da0ab8a6e36bb02bf73c9d6470d7d09169e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 13 Apr 2023 08:12:26 +0200 Subject: [PATCH 10/11] documentation - pr feedback --- docs/config.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/config.md b/docs/config.md index 4a4b1e794c..d68de00c36 100644 --- a/docs/config.md +++ b/docs/config.md @@ -64,14 +64,14 @@ A resource is the immutable representation of the entity producing the telemetry See [Resource semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions) for more details. -Resources can be configured by following environmental variables +### Resource attributes | Environment variable | Description | Default value | Status | |----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| | `OTEL_RESOURCE_ATTRIBUTES` | Key-value pairs to be used as resource attributes. See [Resource SDK](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable) for more details. | See [Resource semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value) for details. | [Stable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | | `OTEL_SERVICE_NAME` | Sets the value of the [`service.name`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service) resource attribute. If `service.name` is provided in `OTEL_RESOURCE_ATTRIBUTES`, the value of `OTEL_SERVICE_NAME` takes precedence. | See [Service name automatic detection](#configuration-methods) under Configuration method section. | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | -and detected by resource detectors. +### Resource detectors | Environment variable | Description | Default value | Status | |--------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------| @@ -82,7 +82,7 @@ Supported resource detectors: | ID | Description | Documentation | Status | |-------------|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| -| `CONTAINER` | Container detector | [Container resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/src/OpenTelemetry.ResourceDetectors.Container/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| `CONTAINER` | Container detector | [Container resource detector documentation](ResourceDetectors.Container-1.0.0-beta.3) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | ## Instrumentations From b38c268395cf11190e9c7606f85dd5e800dcbab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 13 Apr 2023 08:14:52 +0200 Subject: [PATCH 11/11] fix link --- docs/config.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/config.md b/docs/config.md index d68de00c36..9961f865df 100644 --- a/docs/config.md +++ b/docs/config.md @@ -80,9 +80,9 @@ for more details. Supported resource detectors: -| ID | Description | Documentation | Status | -|-------------|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| -| `CONTAINER` | Container detector | [Container resource detector documentation](ResourceDetectors.Container-1.0.0-beta.3) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | +| ID | Description | Documentation | Status | +|-------------|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| +| `CONTAINER` | Container detector | [Container resource detector documentation](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/ResourceDetectors.Container-1.0.0-beta.3/src/OpenTelemetry.ResourceDetectors.Container/README.md) | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) | ## Instrumentations