Skip to content

Commit

Permalink
Log error on resource schema conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Jan 31, 2024
1 parent d9d9507 commit 8ea4ac3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sdk/resource/resource.go
Expand Up @@ -21,6 +21,7 @@ import (

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/global"
)

// Resource describes an entity about which identifying information
Expand All @@ -40,7 +41,7 @@ var (
defaultResourceOnce sync.Once
)

var errMergeConflictSchemaURL = errors.New("cannot merge resource due to conflicting Schema URL")
var errMergeConflictSchemaURL = errors.New("conflicting Schema URL")

// New returns a Resource combined from the user-provided detectors.
func New(ctx context.Context, opts ...Option) (*Resource, error) {
Expand Down Expand Up @@ -177,7 +178,16 @@ func Merge(a, b *Resource) (*Resource, error) {
case a.schemaURL == b.schemaURL:
schemaURL = a.schemaURL
default:
return Empty(), errMergeConflictSchemaURL
// Log conflict, but do not return an error. The user is not always
// able to handle these errors directly (i.e. resource detectors from
// 3rd-party packages). Returning something, and logging information,
// here is a better user-story than returning an unrecoverable error.
global.Error(
errMergeConflictSchemaURL,
"the merged resource schema URL is empty",
"URL 1", a.schemaURL,
"URL 2", b.schemaURL,
)
}

// Note: 'b' attributes will overwrite 'a' with last-value-wins in attribute.Key()
Expand Down

0 comments on commit 8ea4ac3

Please sign in to comment.