open-telemetry / opentelemetry-specification

Specifications for OpenTelemetry
https://opentelemetry.io
Apache License 2.0
3.72k stars 888 forks source link

What should be the schema URL merge behavior when a resource is empty (no attributes) #3710

Open joaopgrassi opened 1 year ago

joaopgrassi commented 1 year ago

The Merge section of the Resource SDK specification, describes how the schemaURL of two resources should be merged. But it is unclear what should happen if one of the merging resources is empty, meaning, has 0 attributes but a non-empty schema url.

For ex, given this scenario:

According with the merge behavior, the resulting resource should receive the schema url of the updating resource.

I wonder if this is correct? Given the resource that will influence the ultimate schema has no attributes, would it be better if, in that case, no schema would be set? Or should the schema be set regardless?

carlosalberto commented 1 year ago

cc @tigrannajaryan

pyohannes commented 1 year ago

I wonder if this is correct? Given the resource that will influence the ultimate schema has no attributes, would it be better if, in that case, no schema would be set? Or should the schema be set regardless?

In my opinion the currently defined behavior is fine. Otherwise you'd get into situations where setting or unsetting an environment variable causes or resolves resource merging errors, which is quite unexpected.

joaopgrassi commented 1 year ago

Otherwise you'd get into situations where setting or unsetting an environment variable causes or resolves resource merging errors, which is quite unexpected.

@pyohannes But it's also the current behavior today, no? By setting the schemaURL from an empty resource, we may be affecting the other resource attribute's value if a transformation happen, no?

pyohannes commented 1 year ago

By setting the schemaURL from an empty resource, we may be affecting the other resource attribute's value if a transformation happen, no?

Well, I'd say that's more a problem of having schema-sensitive resources without specified schema.

From the spec:

Resource detectors that populate resource attributes according to OpenTelemetry semantic conventions MUST ensure that the resource has a Schema URL set to a value that matches the semantic conventions.

tigrannajaryan commented 1 year ago

For ex, given this scenario:

  • Old resource: has attributes and empty schemaUrl
  • Updating resource: has 0 attributes and schemaUrl: https://opentelemetry.io/docs/specs/otel/schemas/v1.2.0

According with the merge behavior, the resulting resource should receive the schema url of the updating resource.

This seems like the desirable behavior to me. The updating resource's schemaUrl is explicitly provided and I would expect it become the schemaUrl of the resulting resource.

joaopgrassi commented 1 year ago

Well, I'd say that's more a problem of having schema-sensitive resources without specified schema.

From the spec:

Resource detectors that populate resource attributes according to OpenTelemetry semantic conventions MUST ensure that the resource has a Schema URL set to a value that matches the semantic conventions.

I guess that's fair. What I was thinking is: Let's say I have a resource detector that contains some attributes that happen to follow the OTel semconv, but also it contains other, unrelated attributes. By following the spec, that resource detector should not populate the schema url, as it contains things that are not in the semconv.

But: by getting the Schema URL of the updating resource (and empty), my old resource is now bound to it, and may change because of transformations. If that's intended then we are fine, but I wanted to see if everyone agrees.