Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Ignore informational response status codes (`100-199`) except `101 Switching Protocols` when storing the HTTP status code in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` and `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`. (#6913)
- Make `Body` handling in `Transport` consistent with stdlib in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#8618)
- Fix bucket boundaries for `rpc.server.call.duration` and `rpc.client.call.duration` in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#8642)
- Host resource detector in `go.opentelemetry.io/contrib/otelconf` now includes `os.` attributes. (#8578)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion otelconf/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceOpts(detectors []ExperimentalResourceDetector) []resource.Option {
opts = append(opts, resource.WithContainer())
}
if d.Host != nil {
opts = append(opts, resource.WithHost(), resource.WithHostID())
opts = append(opts, resource.WithHost(), resource.WithOS(), resource.WithHostID())
}
if d.Process != nil {
opts = append(opts, resource.WithProcess())
Expand Down
67 changes: 67 additions & 0 deletions otelconf/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,70 @@ func TestNewResource(t *testing.T) {
})
}
}

func TestResourceOptsWithDetectors(t *testing.T) {
tests := []struct {
name string
detectors []ExperimentalResourceDetector
wantHostAttributes bool
wantOSAttributes bool
wantHostIDAttribute bool
wantProcessAttribute bool
}{
{
name: "no-detectors",
detectors: []ExperimentalResourceDetector{},
},
{
name: "host-detector-enabled",
detectors: []ExperimentalResourceDetector{
{Host: ExperimentalHostResourceDetector{}},
},
wantHostAttributes: true,
wantOSAttributes: true,
wantHostIDAttribute: true,
},
{
name: "process-detector-only",
detectors: []ExperimentalResourceDetector{
{Process: ExperimentalProcessResourceDetector{}},
},
wantProcessAttribute: true,
},
{
name: "all-detectors",
detectors: []ExperimentalResourceDetector{
{Container: ExperimentalContainerResourceDetector{}},
{Host: ExperimentalHostResourceDetector{}},
{Process: ExperimentalProcessResourceDetector{}},
},
wantHostAttributes: true,
wantOSAttributes: true,
wantHostIDAttribute: true,
wantProcessAttribute: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config := &Resource{
DetectionDevelopment: &ExperimentalResourceDetection{
Detectors: tt.detectors,
},
}
got, err := newResource(config)
require.NoError(t, err)
require.NotNil(t, got)

attrs := got.Attributes()
attrSet := make(map[attribute.Key]bool)
for _, attr := range attrs {
attrSet[attr.Key] = true
}

assert.Equal(t, tt.wantHostAttributes, attrSet[semconv.HostNameKey], "should have host.name attribute")
assert.Equal(t, tt.wantOSAttributes, attrSet[semconv.OSTypeKey], "should have os.type attribute (from WithOS()")
assert.Equal(t, tt.wantHostIDAttribute, attrSet[semconv.HostIDKey], "should have host.id attribute")
assert.Equal(t, tt.wantProcessAttribute, attrSet[semconv.ProcessPIDKey], "should have process.pid attribute")
})
}
}
Loading