Skip to content

Commit

Permalink
distro: Avoid merge resource conflict (#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Jan 22, 2024
1 parent 6e37409 commit c651943
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Fixed

- Allow bumping OpenTelemetry Go (`go.opentelemetry.io/otel`)
without bumping the Splunk Distribution (`github.com/signalfx/splunk-otel-go`).
It fixes a merge resource runtime error, which could occur when
the application uses a version of OpenTelemetry Go that is newer
than the one which the Splunk Distribution is depending on. (#2759)

## [1.12.0] - 2024-01-18

This release deprecates `jaeger-thrift-splunk` option support for `OTEL_TRACES_EXPORTER`
Expand Down
26 changes: 13 additions & 13 deletions distro/otel.go
Expand Up @@ -26,7 +26,6 @@ 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"
)

var errShutdown = errors.New("SDK shutdown failure")
Expand Down Expand Up @@ -115,22 +114,23 @@ func Run(opts ...Option) (SDK, error) {

func newResource(ctx context.Context) (*resource.Resource, error) {
// SDK's default resource.
defaultRes := resource.Default()
// Add additional detectors.
resWithDetectors, err := resource.New(ctx,
resource.WithDetectors(
// Add Splunk-specific attributes.
resource.StringDetector(semconv.SchemaURL, distroVerAttr, func() (string, error) {
return Version(), nil
}),
),
// Add process and Go runtime information.
res := resource.Default()

// Add process and Go runtime information.
procRes, err := resource.New(ctx,
resource.WithProcess(),
)
if err != nil {
return nil, err
}
res, err := resource.Merge(defaultRes, resWithDetectors)
res, err = resource.Merge(res, procRes)
if err != nil {
return nil, err
}

// Add Splunk-specific attributes.
splunkRes := resource.NewSchemaless(attribute.String(distroVerAttr, Version()))
res, err = resource.Merge(res, splunkRes)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -194,6 +194,6 @@ func runMetrics(c *config, res *resource.Resource) (shutdownFunc, error) {
}

func serviceNameDefined(r *resource.Resource) bool {
val, ok := r.Set().Value(semconv.ServiceNameKey)
val, ok := r.Set().Value("service.name")
return ok && val.Type() == attribute.STRING && !strings.HasPrefix(val.AsString(), "unknown_service:")
}

0 comments on commit c651943

Please sign in to comment.