Skip to content

Commit

Permalink
Merge pull request #5503 from jsternberg/otel-semconv-sever
Browse files Browse the repository at this point in the history
detect: sever semconv relationship to otel sdk
  • Loading branch information
tonistiigi authored Nov 18, 2024
2 parents 6d93e03 + 9863dd3 commit 5cd5a63
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions util/tracing/detect/resource.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package detect

import (
Expand All @@ -7,6 +10,7 @@ import (
"sync"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
)
Expand All @@ -23,7 +27,7 @@ func Resource() *resource.Resource {
res, err := resource.New(context.Background(),
resource.WithDetectors(serviceNameDetector{}),
resource.WithFromEnv(),
resource.WithTelemetrySDK(),
resource.WithDetectors(telemetrySDK{}),
)
if err != nil {
otel.Handle(err)
Expand All @@ -42,7 +46,15 @@ func OverrideResource(res *resource.Resource) {
})
}

type serviceNameDetector struct{}
type (
telemetrySDK struct{}
serviceNameDetector struct{}
)

var (
_ resource.Detector = telemetrySDK{}
_ resource.Detector = serviceNameDetector{}
)

func (serviceNameDetector) Detect(ctx context.Context) (*resource.Resource, error) {
return resource.StringDetector(
Expand All @@ -56,3 +68,13 @@ func (serviceNameDetector) Detect(ctx context.Context) (*resource.Resource, erro
},
).Detect(ctx)
}

// Detect returns a *Resource that describes the OpenTelemetry SDK used.
func (telemetrySDK) Detect(context.Context) (*resource.Resource, error) {
return resource.NewWithAttributes(
semconv.SchemaURL,
semconv.TelemetrySDKName("opentelemetry"),
semconv.TelemetrySDKLanguageGo,
semconv.TelemetrySDKVersion(sdk.Version()),
), nil
}

0 comments on commit 5cd5a63

Please sign in to comment.