Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
The route is already added automatically for spans.
For metrics, the alternative is to use the `WithMetricAttributesFn` option. (#8268)

### Changed

- `go.opentelemetry.io/contrib/detectors/azure/azurevm` now uses semantic convention key constants with `.String()` method instead of helper functions for creating resource attributes. (#8346)

<!-- Released section -->
<!-- Don't change this section unless doing release -->

Expand Down
12 changes: 6 additions & 6 deletions detectors/azure/azurevm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@ func (detector *ResourceDetector) Detect(ctx context.Context) (*resource.Resourc
}

if metadata.VMId != nil {
attributes = append(attributes, semconv.HostID(*metadata.VMId))
attributes = append(attributes, semconv.HostIDKey.String(*metadata.VMId))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you want to adjust it this way?

For now, the functional style seems to be somewhat better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows issue #8272 to switch from helper functions to key-based strings for semantic conventions. I see your point about the functional style being cleaner. I just implemented as per my understanding of the issue, so in case we prefer the current implementation, I am happy to close the PR

Copy link
Copy Markdown
Member

@flc1125 flc1125 Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might have misunderstood. You can refer to #8142 to help you understand the purpose and requirements of #8272.

}
if metadata.Location != nil {
attributes = append(attributes, semconv.CloudRegion(*metadata.Location))
attributes = append(attributes, semconv.CloudRegionKey.String(*metadata.Location))
}
if metadata.ResourceId != nil {
attributes = append(attributes, semconv.CloudResourceID(*metadata.ResourceId))
attributes = append(attributes, semconv.CloudResourceIDKey.String(*metadata.ResourceId))
}
if metadata.Name != nil {
attributes = append(attributes, semconv.HostName(*metadata.Name))
attributes = append(attributes, semconv.HostNameKey.String(*metadata.Name))
}
if metadata.VMSize != nil {
attributes = append(attributes, semconv.HostType(*metadata.VMSize))
attributes = append(attributes, semconv.HostTypeKey.String(*metadata.VMSize))
}
if metadata.OsType != nil {
attributes = append(attributes, semconv.OSTypeKey.String(*metadata.OsType))
}
if metadata.Version != nil {
attributes = append(attributes, semconv.OSVersion(*metadata.Version))
attributes = append(attributes, semconv.OSVersionKey.String(*metadata.Version))
}

return resource.NewWithAttributes(semconv.SchemaURL, attributes...), nil
Expand Down
12 changes: 6 additions & 6 deletions detectors/azure/azurevm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func TestDetect(t *testing.T) {
resource: resource.NewWithAttributes(semconv.SchemaURL, []attribute.KeyValue{
semconv.CloudProviderAzure,
semconv.CloudPlatformAzureVM,
semconv.CloudRegion("us-west3"),
semconv.CloudResourceID("/subscriptions/sid/resourceGroups/rid/providers/pname/name"),
semconv.HostID("43f65c49-8715-4639-88a9-be6d7eb749a5"),
semconv.HostName("localhost-3"),
semconv.HostType("Standard_D2s_v3"),
semconv.CloudRegionKey.String("us-west3"),
semconv.CloudResourceIDKey.String("/subscriptions/sid/resourceGroups/rid/providers/pname/name"),
semconv.HostIDKey.String("43f65c49-8715-4639-88a9-be6d7eb749a5"),
semconv.HostNameKey.String("localhost-3"),
semconv.HostTypeKey.String("Standard_D2s_v3"),
semconv.OSTypeKey.String("linux"),
semconv.OSVersion("6.5.0-26-generic"),
semconv.OSVersionKey.String("6.5.0-26-generic"),
}...),
err: false,
},
Expand Down
Loading