- 
        Couldn't load subscription status. 
- Fork 123
[FileBasedConfiguration] General Settings #4481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
74f5b2d
              854a5a4
              2dd4a74
              584c20c
              c5f6c2d
              8337bd4
              89099dc
              325ee5c
              de0ed91
              1c2596b
              c960a5f
              e00b4cb
              9596695
              88acb11
              b380a12
              fc982c1
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|  | ||
| using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; | ||
| using Vendors.YamlDotNet.Core.Tokens; | ||
|  | ||
| namespace OpenTelemetry.AutoInstrumentation.Configurations; | ||
|  | ||
| internal class GeneralSettings : Settings | ||
| { | ||
| /// <summary> | ||
| /// Gets the list of plugins represented by <see cref="Type.AssemblyQualifiedName"/>. | ||
| /// </summary> | ||
| public IList<string> Plugins { get; } = new List<string>(); | ||
| public IList<string> Plugins { get; } = []; | ||
|  | ||
| /// <summary> | ||
| /// Gets a value indicating whether the <see cref="AppDomain.UnhandledException"/> event should trigger | ||
|  | @@ -43,4 +46,14 @@ protected override void OnLoadEnvVar(Configuration configuration) | |
|  | ||
| ProfilerEnabled = configuration.GetString(ConfigurationKeys.ProfilingEnabled) == "1"; | ||
| } | ||
|  | ||
| protected override void OnLoadFile(YamlConfiguration configuration) | ||
| { | ||
| SetupSdk = !configuration.Disabled; | ||
| FlushOnUnhandledException = configuration.FlushOnUnhandledException; | ||
|  | ||
| // Using the environment variable instead of YamlConfiguration because the default.NET environment variable | ||
| // is used for enabling the profiler, and without this environment variable, the profiler will not work. | ||
| ProfilerEnabled = Environment.GetEnvironmentVariable(ConfigurationKeys.ProfilingEnabled) == "1"; | ||
| } | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mandatory for this PR: You need to set up here also ProfilerEnabled (by fallback to envs). Plugins are alsoe required, but it can be configured also from the file. If you want to make a follow up PR, you need to ensure that it is extracted to separate setting, and readed from EvnVars. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plugins will be added in separate PR. | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|  | ||
| using OpenTelemetry.AutoInstrumentation.Configurations; | ||
| using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; | ||
| using Xunit; | ||
|  | ||
| namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased; | ||
|  | ||
| public class FilebasedGeneralSettingsTests | ||
| { | ||
| [Fact] | ||
| public void LoadFile_GeneralSettings() | ||
| { | ||
| var conf = new YamlConfiguration | ||
| { | ||
| Disabled = false, | ||
| FlushOnUnhandledException = true, | ||
| }; | ||
|  | ||
| var settings = new GeneralSettings(); | ||
|  | ||
| settings.LoadFile(conf); | ||
|  | ||
| Assert.True(settings.SetupSdk); | ||
| Assert.True(settings.FlushOnUnhandledException); | ||
| } | ||
|  | ||
| [Fact] | ||
| public void LoadFile_FailFastSettings() | ||
| { | ||
| var conf = new YamlConfiguration | ||
| { | ||
| FailFast = true, | ||
| }; | ||
|  | ||
| var settings = new FailFastSettings(); | ||
|  | ||
| settings.LoadFile(conf); | ||
|  | ||
| Assert.True(settings.FailFast); | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| file_format: "1.0-rc.1" | ||
| disabled: false | ||
| fail_fast: false | ||
| flush_on_unhandled_exception: false | ||
|  | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| file_format: "1.0-rc.1" | ||
| disabled: ${OTEL_SDK_DISABLED} | ||
| fail_fast: ${OTEL_DOTNET_AUTO_FAIL_FAST_ENABLED} | ||
| flush_on_unhandled_exception: ${OTEL_DOTNET_AUTO_FLUSH_ON_UNHANDLEDEXCEPTION} | ||
|  | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|  | ||
| using Xunit; | ||
| using YamlParser = OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser.Parser; | ||
|  | ||
| namespace OpenTelemetry.AutoInstrumentation.Tests.Configurations.FileBased.Parser; | ||
|  | ||
| [Collection("Non-Parallel Collection")] | ||
| public class ParserGeneralTests | ||
| { | ||
| [Fact] | ||
| public void Parse_FullConfigYaml_ShouldPopulateModelCorrectly() | ||
| { | ||
| var config = YamlParser.ParseYaml("Configurations/FileBased/Files/TestGeneralFile.yaml"); | ||
|  | ||
| Assert.NotNull(config); | ||
|  | ||
| Assert.Equal("1.0-rc.1", config.FileFormat); | ||
| Assert.False(config.Disabled); | ||
| Assert.False(config.FailFast); | ||
| Assert.False(config.FlushOnUnhandledException); | ||
| } | ||
|  | ||
| [Fact] | ||
| public void Parse_EnvVarYaml_ShouldPopulateModelCompletely() | ||
| { | ||
| Environment.SetEnvironmentVariable("OTEL_SDK_DISABLED", "true"); | ||
| Environment.SetEnvironmentVariable("OTEL_DOTNET_AUTO_FAIL_FAST_ENABLED", "true"); | ||
| Environment.SetEnvironmentVariable("OTEL_DOTNET_AUTO_FLUSH_ON_UNHANDLEDEXCEPTION", "false"); | ||
|  | ||
| var config = YamlParser.ParseYaml("Configurations/FileBased/Files/TestGeneralFileEnvVars.yaml"); | ||
|  | ||
| Assert.NotNull(config); | ||
|  | ||
| Assert.Equal("1.0-rc.1", config.FileFormat); | ||
| Assert.True(config.Disabled); | ||
| Assert.True(config.FailFast); | ||
| Assert.False(config.FlushOnUnhandledException); | ||
| } | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can put here some comment why you are using direclty env vars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added in b380a12