-
Couldn't load subscription status.
- Fork 123
[FileBasedConfiguration] Resource Detectors #4468
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 9 commits into
open-telemetry:main
from
ysolomchenko:FileBasedConfiguration-Resource-Detectors
Sep 23, 2025
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d19a6ca
Add configuration for resource detectors
ysolomchenko e1e7465
Add resource detectors tests
ysolomchenko d5a160a
merge two tests folders (FileBased/FileBasedConfiguration)
ysolomchenko a2d7d44
Docs
ysolomchenko 1bb7a80
update docs
ysolomchenko e643a31
fix
ysolomchenko 5fa44e7
rename files
ysolomchenko 78ee235
remove docs(will be in separete PR)
ysolomchenko d241228
Merge branch 'main' into FileBasedConfiguration-Resource-Detectors
ysolomchenko 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
16 changes: 16 additions & 0 deletions
16
...lemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DetectionDevelopment.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,16 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using Vendors.YamlDotNet.Serialization; | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration; | ||
|
|
||
| internal class DetectionDevelopment | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the configuration for resource detectors. | ||
| /// If omitted or null, no resource detectors are enabled. | ||
| /// </summary> | ||
| [YamlMember(Alias = "detectors")] | ||
| public DotNetDetectors? Detectors { get; set; } | ||
| } |
71 changes: 71 additions & 0 deletions
71
...penTelemetry.AutoInstrumentation/Configurations/FileBasedConfiguration/DotNetDetectors.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,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 | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the Azure App Service detector configuration. | ||
| /// </summary> | ||
| [YamlMember(Alias = "azureappservice")] | ||
| public object? AzureAppService { get; set; } | ||
|
|
||
| #if NET | ||
| /// <summary> | ||
| /// Gets or sets the container detector configuration. | ||
| /// </summary> | ||
| [YamlMember(Alias = "container")] | ||
| public object? Container { get; set; } | ||
| #endif | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the host detector configuration. | ||
| /// </summary> | ||
| [YamlMember(Alias = "host")] | ||
| public object? Host { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the operating system detector configuration. | ||
| /// </summary> | ||
| [YamlMember(Alias = "operatingsystem")] | ||
| public object? OperatingSystem { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the process detector configuration. | ||
| /// </summary> | ||
| [YamlMember(Alias = "process")] | ||
| public object? Process { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the process runtime detector configuration. | ||
| /// </summary> | ||
| [YamlMember(Alias = "processruntime")] | ||
| public object? ProcessRuntime { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Returns the list of enabled resource detectors. | ||
| /// </summary> | ||
| public IReadOnlyList<ResourceDetector> GetEnabledResourceDetectors() | ||
| { | ||
| var enabled = new List<ResourceDetector>(); | ||
| 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<ResourceDetector>(prop.Name, out var resourceDetector)) | ||
| { | ||
| enabled.Add(resourceDetector); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return enabled; | ||
| } | ||
| } |
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
32 changes: 32 additions & 0 deletions
32
test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/FileBasedTestHelper.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,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>(T obj, string alias) | ||
| { | ||
| Assert.NotNull(obj); | ||
|
|
||
| var prop = typeof(T).GetProperties() | ||
| .FirstOrDefault(p => p.GetCustomAttribute<YamlMemberAttribute>()?.Alias == alias); | ||
|
|
||
| Assert.NotNull(prop); | ||
|
|
||
| var value = prop.GetValue(obj); | ||
| Assert.NotNull(value); | ||
| } | ||
| } |
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
ysolomchenko marked this conversation as resolved.
Show resolved
Hide resolved
|
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
16 changes: 0 additions & 16 deletions
16
...ry.AutoInstrumentation.Tests/Configurations/FileBasedConfiguration/FileBasedTestHelper.cs
This file was deleted.
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.