Skip to content
Open
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 .lycheeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
http://localhost
http://169.254.169.254/metadata/instance/compute
https://10.0.0.0
https://10.0.0.1
https://localhost:4317
localhost:14250
file:///var/log/logs.jsonl
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- Add support for the `aws.ec2` resource detector in `go.opentelemetry.io/contrib/otelconf/x`. (#9139)
- Add `go.opentelemetry.io/contrib/detectors/openshift`, a new resource detector for OpenShift 4 clusters, ported from `processor/resourcedetectionprocessor/internal/openshift` in `opentelemetry-collector-contrib`. Detects `k8s.cluster.name`, and `cloud.provider`, `cloud.platform` and `cloud.region` for clusters running on AWS, Azure, Google Cloud and IBM Cloud; OpenStack clusters report only `cloud.region`. (#9499)

### Fixed

Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ detectors/gcp/ @open-te
detectors/hetzner/ @open-telemetry/go-approvers @paulojmdias
detectors/ibmcloud/vpc/ @open-telemetry/go-approvers @paulojmdias @iblancasa
detectors/k8sapi/ @open-telemetry/go-approvers @paulojmdias @iblancasa @dashpole
detectors/openshift/ @open-telemetry/go-approvers @paulojmdias @iblancasa
detectors/vultr/ @open-telemetry/go-approvers @paulojmdias @iblancasa

exporters/autoexport @open-telemetry/go-approvers @MikeGoldsmith @pellared
Expand Down
7 changes: 7 additions & 0 deletions detectors/autodetect/autodetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.opentelemetry.io/contrib/detectors/hetzner"
"go.opentelemetry.io/contrib/detectors/ibmcloud/vpc"
"go.opentelemetry.io/contrib/detectors/k8sapi"
"go.opentelemetry.io/contrib/detectors/openshift"
"go.opentelemetry.io/contrib/detectors/vultr"
)

Expand Down Expand Up @@ -73,6 +74,10 @@ var (
// attributes from the Kubernetes API (see k8sapi.NewResourceDetector for
// details).
IDK8sAPI = ID("k8sapi")
// IDOpenShift is the ID for the OpenShift detector that detects resource
// attributes of OpenShift 4 clusters (see openshift.NewResourceDetector
// for details).
IDOpenShift = ID("openshift")
// IDVultr is the ID for the Vultr detector that detects resource attributes
// on Vultr Cloud Compute instances (see vultr.NewResourceDetector for
// details).
Expand Down Expand Up @@ -168,6 +173,8 @@ var (

IDK8sAPI: func() resource.Detector { return k8sapi.NewResourceDetector() },

IDOpenShift: func() resource.Detector { return openshift.NewResourceDetector() },

IDVultr: func() resource.Detector { return vultr.NewResourceDetector() },

IDHost: optFactory(resource.WithHost()),
Expand Down
15 changes: 15 additions & 0 deletions detectors/autodetect/autodetect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ func TestIBMCloudVPCDetectorRegistered(t *testing.T) {
}
}

func TestOpenShiftDetectorRegistered(t *testing.T) {
detector, err := Detector(IDOpenShift)
if err != nil {
t.Fatalf("got error: %v, expected no error", err)
}

c, ok := detector.(*composite)
if !ok {
t.Fatalf("got %T, expected composite detector", detector)
}
if len(c.detectors) != 1 {
t.Fatalf("got %d detectors, expected 1 detector", len(c.detectors))
}
}

func TestOptDetectorDetect(t *testing.T) {
want := attribute.String("key", "value")
opt := resource.WithAttributes(want)
Expand Down
3 changes: 3 additions & 0 deletions detectors/autodetect/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
go.opentelemetry.io/contrib/detectors/hetzner v0.17.0
go.opentelemetry.io/contrib/detectors/ibmcloud/vpc v0.17.0
go.opentelemetry.io/contrib/detectors/k8sapi v0.17.0
go.opentelemetry.io/contrib/detectors/openshift v0.17.0
go.opentelemetry.io/contrib/detectors/vultr v0.17.0
go.opentelemetry.io/otel v1.45.0
go.opentelemetry.io/otel/sdk v1.45.0
Expand Down Expand Up @@ -122,3 +123,5 @@ replace go.opentelemetry.io/contrib/detectors/k8sapi => ../k8sapi
replace go.opentelemetry.io/contrib/detectors/vultr => ../vultr

replace go.opentelemetry.io/contrib/detectors/aws/ec2/v2 => ../aws/ec2/v2

replace go.opentelemetry.io/contrib/detectors/openshift => ../openshift
5 changes: 5 additions & 0 deletions detectors/openshift/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OpenShift Resource Detector for Go

<!--[![Go Reference][goref-image]][goref-url]-->
<!--[goref-image]: https://pkg.go.dev/badge/go.opentelemetry.io/contrib/detectors/openshift.svg-->
<!--[goref-url]: https://pkg.go.dev/go.opentelemetry.io/contrib/detectors/openshift-->
43 changes: 43 additions & 0 deletions detectors/openshift/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

/*
Package openshift provides a [resource.Detector] which supports detecting
attributes specific to OpenShift 4 clusters.

The detector reads the cluster-scoped Infrastructure config object from the
OpenShift API server, authenticating with the service account token projected
into the pod. It requires the following RBAC:

- apiGroups: ["config.openshift.io"]
resources: ["infrastructures"]
resourceNames: ["cluster"]
verbs: ["get"]

According to semantic conventions for [cloud] and [k8s] attributes, each of the
following attributes is added if it is available:

- cloud.provider
- cloud.platform
- cloud.region
- k8s.cluster.name

The k8s.cluster.name value is the infrastructure name of the cluster. Which
cloud attributes are reported depends on the infrastructure the cluster runs
on:

- AWS, Azure, Google Cloud and IBM Cloud clusters report cloud.provider,
cloud.platform and cloud.region.
- OpenStack clusters report only cloud.region. Semantic conventions define no
cloud.provider value for OpenStack and no cloud.platform value for
OpenShift on OpenStack.
- Clusters that do not run on a cloud provider, such as bare metal, vSphere
and oVirt, report no cloud attributes at all. This is not treated as a
partial resource.

Region values are normalized to lower case.

[cloud]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/cloud.md
[k8s]: https://opentelemetry.io/docs/specs/semconv/resource/k8s/
*/
package openshift
28 changes: 28 additions & 0 deletions detectors/openshift/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package openshift_test

import (
"context"
"log"

"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"

"go.opentelemetry.io/contrib/detectors/openshift"
)

func ExampleNewResourceDetector() {
res, err := resource.New(
context.Background(),
resource.WithDetectors(openshift.NewResourceDetector()),
)
if err != nil {
log.Fatal(err)
}

tp := sdktrace.NewTracerProvider(sdktrace.WithResource(res))
_ = tp.Shutdown(context.Background())
// Use tp to create tracers ...
}
23 changes: 23 additions & 0 deletions detectors/openshift/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module go.opentelemetry.io/contrib/detectors/openshift

go 1.25.0

require (
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/otel v1.45.0
go.opentelemetry.io/otel/sdk v1.45.0
)

require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/metric v1.45.0 // indirect
go.opentelemetry.io/otel/trace v1.45.0 // indirect
golang.org/x/sys v0.47.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
44 changes: 44 additions & 0 deletions detectors/openshift/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.45.0 h1:pdrWmLHofpubmArBv1LgFSv1Z0Ie/ppdZzu+kUN5EeU=
go.opentelemetry.io/otel v1.45.0/go.mod h1:XZxIqPapzEYnhNSScF5DIqXhm/rYi0FzCe2XddAwZfQ=
go.opentelemetry.io/otel/metric v1.45.0 h1:7Eg1uH7CJ5cXv9is6tnBe1FI6rj1nwUdbFypRm3br/M=
go.opentelemetry.io/otel/metric v1.45.0/go.mod h1:HAPbm1nd3p1PmFH7v2dR+6BjXxw+Lq4a2+pndMAm08s=
go.opentelemetry.io/otel/sdk v1.45.0 h1:4VVSMgQ83dUgW2aoX5f6JgLvHwIvzcuLnF9lUdCSpCw=
go.opentelemetry.io/otel/sdk v1.45.0/go.mod h1:Sr40LgXV7DsKMMJMKOhUWOgMWTfAaqvm2kF0g7ilwuA=
go.opentelemetry.io/otel/sdk/metric v1.45.0 h1:oVFszMfyj1Am6s24Vtc7wBb8BKLcwepJjNEYILuiE3o=
go.opentelemetry.io/otel/sdk/metric v1.45.0/go.mod h1:vUWUxDZvu1WVRj8JA8S0AdhsPrZoDpA2DdZauIh4mDA=
go.opentelemetry.io/otel/trace v1.45.0 h1:l/mP6Uv7oNO7/TblbhpbgMidxhq1uO/rPsikOyVhxag=
go.opentelemetry.io/otel/trace v1.45.0/go.mod h1:qoJJA2xNMnxRrdISU/kLtfUH2wNeQbiv+jhs/CxI8bc=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Loading