Skip to content

Commit 153f7f1

Browse files
jsternbergthaJeztah
authored andcommitted
telemetry: lock the semconv version of the otel sdk
This change prevents changes to the otel version from affecting the otel sdk version. This is done by copying the telemetry sdk implementation locally and using our own choice for semconv from within that. This prevents a schema conflict from happening since the otel version of the sdk gets implicitly updated whenever the semconv changes while we have to manually change ours. Now, we manually change both and they're locked to each other. Signed-off-by: Jonathan A. Sternberg <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 7b4cde6 commit 153f7f1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cli/command/telemetry.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/google/uuid"
1212
"go.opentelemetry.io/otel"
1313
"go.opentelemetry.io/otel/metric"
14+
otelsdk "go.opentelemetry.io/otel/sdk"
1415
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
1516
"go.opentelemetry.io/otel/sdk/metric/metricdata"
1617
"go.opentelemetry.io/otel/sdk/resource"
@@ -146,7 +147,7 @@ func defaultResourceOptions() []resource.Option {
146147
semconv.ServiceInstanceID(uuid.NewString()),
147148
),
148149
resource.WithFromEnv(),
149-
resource.WithTelemetrySDK(),
150+
resource.WithDetectors(telemetrySDK{}),
150151
}
151152
}
152153

@@ -157,7 +158,10 @@ func (r *telemetryResource) AppendOptions(opts ...resource.Option) {
157158
r.opts = append(r.opts, opts...)
158159
}
159160

160-
type serviceNameDetector struct{}
161+
type (
162+
serviceNameDetector struct{}
163+
telemetrySDK struct{}
164+
)
161165

162166
func (serviceNameDetector) Detect(ctx context.Context) (*resource.Resource, error) {
163167
return resource.StringDetector(
@@ -169,6 +173,16 @@ func (serviceNameDetector) Detect(ctx context.Context) (*resource.Resource, erro
169173
).Detect(ctx)
170174
}
171175

176+
// Detect returns a *Resource that describes the OpenTelemetry SDK used.
177+
func (telemetrySDK) Detect(context.Context) (*resource.Resource, error) {
178+
return resource.NewWithAttributes(
179+
semconv.SchemaURL,
180+
semconv.TelemetrySDKName("opentelemetry"),
181+
semconv.TelemetrySDKLanguageGo,
182+
semconv.TelemetrySDKVersion(otelsdk.Version()),
183+
), nil
184+
}
185+
172186
// cliReader is an implementation of Reader that will automatically
173187
// report to a designated Exporter when Shutdown is called.
174188
type cliReader struct {

0 commit comments

Comments
 (0)