Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Resources.Host/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Added support for the `host.arch` resource attribute in `HostDetector`, reporting the host architecture (e.g., `X64`, `Arm64`) using `System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture`.

Check failure on line 5 in src/OpenTelemetry.Resources.Host/CHANGELOG.md

View workflow job for this annotation

GitHub Actions / lint-md / run-markdownlint

Line length

src/OpenTelemetry.Resources.Host/CHANGELOG.md:5:81 MD013/line-length Line length [Expected: 80; Actual: 207] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md013.md

## 1.12.0-beta.1

Released 2025-May-06
Expand Down
8 changes: 8 additions & 0 deletions src/OpenTelemetry.Resources.Host/HostDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public Resource Detect()
{
attributes.Add(new(HostSemanticConventions.AttributeHostId, machineId));
}
#if !NETFRAMEWORK
// Architecture is only supported in .NET 5+
var arch = RuntimeInformation.ProcessArchitecture.ToString();
if (arch != null && !string.IsNullOrEmpty(arch))
{
attributes.Add(new(HostSemanticConventions.AttributeHostArch, arch));
}
#endif

return new Resource(attributes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ internal static class HostSemanticConventions
{
public const string AttributeHostName = "host.name";
public const string AttributeHostId = "host.id";
public const string AttributeHostArch = "host.arch";
}
7 changes: 5 additions & 2 deletions src/OpenTelemetry.Resources.Host/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@
The resource detectors will record the following metadata based on where
your application is running:

- **HostDetector**: `host.id` (when running on non-containerized systems), `host.name`.
- **HostDetector**:
- `host.id` (when running on non-containerized systems)
- `host.name`
- `host.arch` (the host architecture, e.g., `X64`, `Arm64`)

## References

- [OpenTelemetry Project](https://opentelemetry.io/)
- [OpenTelemetry Project](https://opentelemetry.io/)

Check failure on line 64 in src/OpenTelemetry.Resources.Host/README.md

View workflow job for this annotation

GitHub Actions / lint-md / run-markdownlint

Files should end with a single newline character

src/OpenTelemetry.Resources.Host/README.md:64:52 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md047.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@

var resourceAttributes = resource.Attributes.ToDictionary(x => x.Key, x => (string)x.Value);

#if NET
Assert.Equal(3, resourceAttributes.Count);
#else
Assert.Equal(2, resourceAttributes.Count);
#endif

Assert.NotEmpty(resourceAttributes[HostSemanticConventions.AttributeHostName]);
Assert.NotEmpty(resourceAttributes[HostSemanticConventions.AttributeHostId]);
#if NET
Assert.NotEmpty(resourceAttributes["host.arch"]);
Assert.Equal(System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString(), resourceAttributes["host.arch"]);

Check warning on line 64 in test/OpenTelemetry.Resources.Host.Tests/HostDetectorTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format

Name can be simplified

Check warning on line 64 in test/OpenTelemetry.Resources.Host.Tests/HostDetectorTests.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format

Name can be simplified
#endif
}

#if NET
Expand Down
Loading