Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distro: Avoid merge resource conflict #2759

Merged
merged 2 commits into from
Jan 22, 2024
Merged
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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:")
}