Skip to content

Commit

Permalink
Merge pull request chinmina#67 from jamestelfer/fix-otel-schema
Browse files Browse the repository at this point in the history
fix: OTEL schema incompatibility after upgrade
  • Loading branch information
jamestelfer authored Oct 5, 2024
2 parents 490954a + 1014aea commit a0fd6da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internal/observe/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
)

// Configure sets up OpenTelemetry according to the configuration. If it does
Expand Down Expand Up @@ -134,13 +134,7 @@ func newTraceProvider(ctx context.Context, cfg config.ObserveConfig, e exporters
return nil, err
}

r, err := resource.Merge(
resource.Default(),
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName(cfg.ServiceName),
),
)
r, err := resourceWithServiceName(resource.Default(), cfg.ServiceName)
if err != nil {
return nil, err
}
Expand All @@ -154,6 +148,16 @@ func newTraceProvider(ctx context.Context, cfg config.ObserveConfig, e exporters
return traceProvider, nil
}

func resourceWithServiceName(base *resource.Resource, serviceName string) (*resource.Resource, error) {
return resource.Merge(
base,
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName(serviceName),
),
)
}

func newMeterProvider(ctx context.Context, cfg config.ObserveConfig, e exporters) (*metric.MeterProvider, error) {
metricExporter, err := e.Metric(ctx)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions internal/observe/telemetry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package observe

import (
"testing"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/sdk/resource"
)

func Test_ResourceMerge(t *testing.T) {
// Ensure that schema incompatibility on OTEL upgrades is detected before
// merge
_, err := resourceWithServiceName(
resource.Default(),
"serviceName")

require.NoError(t, err)
}

0 comments on commit a0fd6da

Please sign in to comment.