Skip to content

Commit 0ef2f5c

Browse files
author
Dominik Rosiek
committed
feat: use opentelemetry sdk
Signed-off-by: Dominik Rosiek <[email protected]>
1 parent a8b184e commit 0ef2f5c

File tree

8 files changed

+55
-75
lines changed

8 files changed

+55
-75
lines changed

.chloggen/drosiek-host-id-2.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ change_type: enhancement
55
component: resourcedetectionprocessor
66

77
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8-
note: use gopsutil for host id detection
8+
note: "use opentelemetry-go library for `host.id` detection in the `system` detector"
99

1010
# One or more tracking issues related to the change
1111
issues: [18533]

internal/metadataproviders/go.mod

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ require (
77
github.com/aws/aws-sdk-go v1.44.277
88
github.com/docker/docker v24.0.2+incompatible
99
github.com/hashicorp/consul/api v1.21.0
10-
github.com/shirou/gopsutil/v3 v3.23.4
1110
github.com/stretchr/testify v1.8.4
11+
go.opentelemetry.io/collector/semconv v0.79.0
12+
go.opentelemetry.io/otel/sdk v1.16.0
1213
)
1314

1415
require (
@@ -19,7 +20,8 @@ require (
1920
github.com/docker/go-connections v0.4.0 // indirect
2021
github.com/docker/go-units v0.4.0 // indirect
2122
github.com/fatih/color v1.13.0 // indirect
22-
github.com/go-ole/go-ole v1.2.6 // indirect
23+
github.com/go-logr/logr v1.2.4 // indirect
24+
github.com/go-logr/stdr v1.2.2 // indirect
2325
github.com/gogo/protobuf v1.3.2 // indirect
2426
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
2527
github.com/hashicorp/go-hclog v1.5.0 // indirect
@@ -28,7 +30,6 @@ require (
2830
github.com/hashicorp/golang-lru v0.5.4 // indirect
2931
github.com/hashicorp/serf v0.10.1 // indirect
3032
github.com/jmespath/go-jmespath v0.4.0 // indirect
31-
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
3233
github.com/mattn/go-colorable v0.1.12 // indirect
3334
github.com/mattn/go-isatty v0.0.14 // indirect
3435
github.com/mitchellh/go-homedir v1.1.0 // indirect
@@ -39,12 +40,10 @@ require (
3940
github.com/opencontainers/image-spec v1.0.2 // indirect
4041
github.com/pkg/errors v0.9.1 // indirect
4142
github.com/pmezard/go-difflib v1.0.0 // indirect
42-
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
43-
github.com/shoenig/go-m1cpu v0.1.5 // indirect
4443
github.com/stretchr/objx v0.5.0 // indirect
45-
github.com/tklauser/go-sysconf v0.3.11 // indirect
46-
github.com/tklauser/numcpus v0.6.0 // indirect
47-
github.com/yusufpapurcu/wmi v1.2.2 // indirect
44+
go.opentelemetry.io/otel v1.16.0 // indirect
45+
go.opentelemetry.io/otel/metric v1.16.0 // indirect
46+
go.opentelemetry.io/otel/trace v1.16.0 // indirect
4847
golang.org/x/net v0.10.0 // indirect
4948
golang.org/x/sys v0.8.0 // indirect
5049
golang.org/x/time v0.3.0 // indirect

internal/metadataproviders/go.sum

+19-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/metadataproviders/system/metadata.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
package system // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/system"
55

66
import (
7+
"context"
78
"fmt"
89
"net"
910
"os"
1011
"runtime"
1112
"strings"
1213

1314
"github.com/Showmax/go-fqdn"
14-
"github.com/shirou/gopsutil/v3/host"
15+
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
16+
"go.opentelemetry.io/otel/sdk/resource"
1517

1618
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/internal"
1719
)
@@ -53,7 +55,7 @@ type Provider interface {
5355
ReverseLookupHost() (string, error)
5456

5557
// HostID returns Host Unique Identifier
56-
HostID() (string, error)
58+
HostID(ctx context.Context) (string, error)
5759
}
5860

5961
type systemMetadataProvider struct {
@@ -117,6 +119,22 @@ func (p systemMetadataProvider) reverseLookup(ipAddresses []string) (string, err
117119
return "", fmt.Errorf("reverseLookup failed to convert IP addresses to name: %w", err)
118120
}
119121

120-
func (p systemMetadataProvider) HostID() (string, error) {
121-
return host.HostID()
122+
func (p systemMetadataProvider) HostID(ctx context.Context) (string, error) {
123+
res, err := resource.New(ctx,
124+
resource.WithHostID(),
125+
)
126+
127+
if err != nil {
128+
return "", fmt.Errorf("failed to obtain host id: %w", err)
129+
}
130+
131+
iter := res.Iter()
132+
133+
for iter.Next() {
134+
if iter.Attribute().Key == conventions.AttributeHostID {
135+
return iter.Attribute().Value.Emit(), nil
136+
}
137+
}
138+
139+
return "", fmt.Errorf("failed to obtain host id")
122140
}

processor/resourcedetectionprocessor/go.mod

+1-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ require (
4040
github.com/fsnotify/fsnotify v1.6.0 // indirect
4141
github.com/go-logr/logr v1.2.4 // indirect
4242
github.com/go-logr/stdr v1.2.2 // indirect
43-
github.com/go-ole/go-ole v1.2.6 // indirect
4443
github.com/go-openapi/jsonpointer v0.19.6 // indirect
4544
github.com/go-openapi/jsonreference v0.20.1 // indirect
4645
github.com/go-openapi/swag v0.22.3 // indirect
@@ -62,7 +61,6 @@ require (
6261
github.com/json-iterator/go v1.1.12 // indirect
6362
github.com/klauspost/compress v1.16.5 // indirect
6463
github.com/knadh/koanf v1.5.0 // indirect
65-
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
6664
github.com/mailru/easyjson v0.7.7 // indirect
6765
github.com/mattn/go-colorable v0.1.12 // indirect
6866
github.com/mattn/go-isatty v0.0.14 // indirect
@@ -78,19 +76,14 @@ require (
7876
github.com/opencontainers/image-spec v1.0.2 // indirect
7977
github.com/pkg/errors v0.9.1 // indirect
8078
github.com/pmezard/go-difflib v1.0.0 // indirect
81-
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
8279
github.com/rs/cors v1.9.0 // indirect
83-
github.com/shirou/gopsutil/v3 v3.23.4 // indirect
84-
github.com/shoenig/go-m1cpu v0.1.5 // indirect
8580
github.com/stretchr/objx v0.5.0 // indirect
86-
github.com/tklauser/go-sysconf v0.3.11 // indirect
87-
github.com/tklauser/numcpus v0.6.0 // indirect
88-
github.com/yusufpapurcu/wmi v1.2.2 // indirect
8981
go.opencensus.io v0.24.0 // indirect
9082
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0012 // indirect
9183
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 // indirect
9284
go.opentelemetry.io/otel v1.16.0 // indirect
9385
go.opentelemetry.io/otel/metric v1.16.0 // indirect
86+
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
9487
go.opentelemetry.io/otel/trace v1.16.0 // indirect
9588
go.uber.org/atomic v1.10.0 // indirect
9689
golang.org/x/net v0.10.0 // indirect

0 commit comments

Comments
 (0)