-
Couldn't load subscription status.
- Fork 123
[FileBasedConfiguration] Resources #4462
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
Merged
Kielek
merged 20 commits into
open-telemetry:main
from
Kielek:filebasedconfig-resources
Sep 19, 2025
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4bae3e9
[File Based Config] Resources
Kielek 46b1e4b
Update File Format to 1.0-rc.1
Kielek e5fbafc
Extract file based config env vars
Kielek 3cf0409
remove redundant null check
Kielek 4ae4d9b
bring back telemetrydistro resources to resource configurator
Kielek c3d49c0
remove redundant null check
Kielek 6c13e3d
ignore resources when reading from env. vars.
Kielek 3d5c573
TODO validate file and file version
Kielek 338f627
Refactor resource settings to separate class + add EnvVarDetector switch
Kielek 91d64bb
TODO for the types
Kielek ec1d51c
Cache yaml configuration to avoid multiple time parsing
Kielek 0c9ca47
remove wrong tests
Kielek 3fda793
const chars
Kielek f75734a
drop redundant using
Kielek 70abe4e
drop empty body
Kielek 5aff608
PR feedback - refactor parse attributes
Kielek 8138c24
Rename EnabledEnvironmentalVariablesDetector to EnvironmentalVariable…
Kielek da76bfb
Merge branch 'main' into filebasedconfig-resources
Kielek 2cefa3f
PR feedback, split only by first equal sign
Kielek 680314a
fix docs comment
Kielek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...toInstrumentation/Configurations/FileBasedConfiguration/Parser/ConditionalDeserializer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/OpenTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/Parser/Parser.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using Vendors.YamlDotNet.Serialization; | ||
| using Vendors.YamlDotNet.Serialization.NodeDeserializers; | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser; | ||
|
|
||
| internal static class Parser | ||
| { | ||
| public static YamlConfiguration ParseYaml(string filePath) | ||
| { | ||
| var deserializer = new DeserializerBuilder() | ||
| .WithNodeDeserializer(existing => new ConditionalDeserializer(existing), s => s.InsteadOf<NullNodeDeserializer>()) | ||
| .WithTypeConverter(new EnvVarTypeConverter()) | ||
| .IgnoreUnmatchedProperties() | ||
| .Build(); | ||
|
|
||
| var yaml = File.ReadAllText(filePath); | ||
| var config = deserializer.Deserialize<YamlConfiguration>(yaml); | ||
RassK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return config; | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
...nTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/ResourceAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using Vendors.YamlDotNet.Serialization; | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; | ||
|
|
||
| internal class ResourceAttribute | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the name of the resource attribute. | ||
| /// </summary> | ||
| [YamlMember(Alias = "name")] | ||
| public string Name { get; set; } = null!; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the value of the resource attribute. | ||
| /// </summary> | ||
| [YamlMember(Alias = "value")] | ||
| public object Value { get; set; } = null!; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the type of the resource attribute. | ||
| /// </summary> | ||
| [YamlMember(Alias = "type")] | ||
| public string Type { get; set; } = "string"; | ||
| } |
63 changes: 63 additions & 0 deletions
63
...emetry.AutoInstrumentation/Configurations/FileBasedConfiguration/ResourceConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using Vendors.YamlDotNet.Serialization; | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; | ||
|
|
||
| internal class ResourceConfiguration | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the list of resource attributes. | ||
| /// </summary> | ||
| [YamlMember(Alias = "attributes")] | ||
| public List<ResourceAttribute>? Attributes { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the attributes list for the resource. | ||
| /// </summary> | ||
| [YamlMember(Alias = "attributes_list")] | ||
| public string? AttributesList { get; set; } | ||
|
|
||
| public List<KeyValuePair<string, object>> ParseAttributes() | ||
RassK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| var resourceAttributesWithPriority = new Dictionary<string, object>(); | ||
|
|
||
| if (Attributes != null) | ||
| { | ||
| foreach (var attr in Attributes) | ||
| { | ||
| if (!resourceAttributesWithPriority.ContainsKey(attr.Name)) | ||
| { | ||
| // TODO parse type and converting the value accordingly. | ||
| resourceAttributesWithPriority.Add(attr.Name, attr.Value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (AttributesList != null) | ||
| { | ||
| const char attributeListSplitter = ','; | ||
| char[] attributeKeyValueSplitter = ['=']; | ||
|
|
||
| var rawAttributes = AttributesList.Split(attributeListSplitter); | ||
| foreach (var rawKeyValuePair in rawAttributes) | ||
| { | ||
| var keyValuePair = rawKeyValuePair.Split(attributeKeyValueSplitter, 2); | ||
| if (keyValuePair.Length != 2) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var key = keyValuePair[0].Trim(); | ||
|
|
||
| if (!resourceAttributesWithPriority.ContainsKey(key)) | ||
| { | ||
| resourceAttributesWithPriority.Add(key, keyValuePair[1].Trim()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return resourceAttributesWithPriority.ToList(); | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
...nTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/YamlConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using Vendors.YamlDotNet.Serialization; | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; | ||
|
|
||
| internal class YamlConfiguration | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the file format version. | ||
| /// The yaml format is documented at | ||
| /// https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema | ||
| /// </summary> | ||
| [YamlMember(Alias = "file_format")] | ||
| public string? FileFormat { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the resource configuration. | ||
| /// Configure resource for all signals. | ||
| /// If omitted, the default resource is used. | ||
| /// </summary> | ||
| [YamlMember(Alias = "resource")] | ||
| public ResourceConfiguration? Resource { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceSettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations; | ||
|
|
||
| internal class ResourceSettings : Settings | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the list of enabled resource detectors. | ||
| /// </summary> | ||
| public IReadOnlyList<ResourceDetector> EnabledDetectors { get; set; } = []; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the list of enabled resources. | ||
| /// </summary> | ||
| public IReadOnlyList<KeyValuePair<string, object>> Resources { get; set; } = []; | ||
|
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. for the future, may want to use union ref struct not to cause object boxing for simple types. |
||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating whether environmental variables resource detector is enabled. | ||
| /// </summary> | ||
| public bool EnvironmentalVariablesDetectorEnabled { get; set; } = true; | ||
|
|
||
| protected override void OnLoadEnvVar(Configuration configuration) | ||
| { | ||
| var resourceDetectorsEnabledByDefault = configuration.GetBool(ConfigurationKeys.ResourceDetectorEnabled) ?? true; | ||
|
|
||
| EnabledDetectors = configuration.ParseEnabledEnumList<ResourceDetector>( | ||
| enabledByDefault: resourceDetectorsEnabledByDefault, | ||
| enabledConfigurationTemplate: ConfigurationKeys.EnabledResourceDetectorTemplate); | ||
| } | ||
|
|
||
| protected override void OnLoadFile(YamlConfiguration configuration) | ||
| { | ||
| EnvironmentalVariablesDetectorEnabled = false; | ||
|
|
||
| Resources = configuration.Resource?.ParseAttributes() ?? []; | ||
|
|
||
| // TODO initialize EnabledDetectors from file configuration | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.