Skip to content

Commit

Permalink
add new gcp host attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Aug 31, 2023
1 parent 84de4d2 commit 7ac6623
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion detectors/gcp/detector.go
Expand Up @@ -23,7 +23,7 @@ import (

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
)

// NewDetector returns a resource detector which detects resource attributes on:
Expand Down Expand Up @@ -87,6 +87,8 @@ func (d *detector) Detect(ctx context.Context) (*resource.Resource, error) {
b.add(semconv.HostTypeKey, d.detector.GCEHostType)
b.add(semconv.HostIDKey, d.detector.GCEHostID)
b.add(semconv.HostNameKey, d.detector.GCEHostName)
b.add(semconv.GCPGceInstanceNameKey, d.detector.GCEInstanceHostname)
b.add(semconv.GCPGceInstanceHostnameKey, d.detector.GCEInstanceName)
default:
// We don't support this platform yet, so just return with what we have
}
Expand Down
16 changes: 16 additions & 0 deletions detectors/gcp/detector_test.go
Expand Up @@ -238,6 +238,8 @@ type fakeGCPDetector struct {
gceHostType string
gceHostID string
gceHostName string
gcpGceInstanceName string
gcpGceInstanceHostname string
}

func (f *fakeGCPDetector) ProjectID() (string, error) {
Expand Down Expand Up @@ -379,3 +381,17 @@ func (f *fakeGCPDetector) GCEHostName() (string, error) {
}
return f.gceHostName, nil
}

func (f *fakeGCPDetector) GCEInstanceName() (string, error) {
if f.err != nil {
return "", f.err
}
return f.gcpGceInstanceName, nil
}

func (f *fakeGCPDetector) GCEInstanceHostname() (string, error) {
if f.err != nil {
return "", f.err
}
return f.gcpGceInstanceHostname, nil
}
2 changes: 2 additions & 0 deletions detectors/gcp/types.go
Expand Up @@ -37,4 +37,6 @@ type gcpDetector interface {
GCEHostType() (string, error)
GCEHostID() (string, error)
GCEHostName() (string, error)
GCEInstanceHostname() (string, error)
GCEInstanceName() (string, error)
}

0 comments on commit 7ac6623

Please sign in to comment.