feat: Explicitly define include/exclude attributes for views#4951
feat: Explicitly define include/exclude attributes for views#4951thompson-tomo wants to merge 6 commits intoopen-telemetry:mainfrom
Conversation
| `Attributes` (a list of [attribute keys](../common/README.md#attribute)) is | ||
| the recommended set of attribute keys to be used for the resulting metrics. | ||
|
|
||
| ##### Instrument advisory parameter: `Exclude_Attributes` |
There was a problem hiding this comment.
don't need this in the API/advisory. if something should not be used, then instrumentation can not provide it at all.
There was a problem hiding this comment.
Wouldn't opt-in/deprecated attributes reside in this advisory? That way if stream config doesn't specify included/excluded attributes the advisory can be used to exclude them with 0 zero config.
There was a problem hiding this comment.
Opt-in attributes are not emitted by instrumentation (because SDK respects it) by default — they only appear when the user explicitly opts in via Views. So there's nothing to exclude in the zero-config case.
For exclude_attributes, the instrumentation library itself should stop emitting them (or the semantic conventions should guide the migration). The fix belongs at the instrumentation layer, not as an SDK-side exclude hint.
The existing Attributes (include) advisory already covers the zero-config story: the instrumentation author lists the recommended attribute keys, and anything not on that list is implicitly not recommended.
dashpole
left a comment
There was a problem hiding this comment.
As @cijothomas points out, this is already supported by the Attributes advisory parameter.
|
Separately, I realized that Declarative Config already includes support for this - https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema/meter_provider.yaml#L605-L609 Spec wording is a bit hand-wavy/flexible, so I think it makes sense to make it more concrete. |
|
That is part of the SDK's View, not part of the API. |
bcc605a to
2cbc29a
Compare
2cbc29a to
e0f4d2b
Compare
|
@thompson-tomo is there an issue? We don't take new features unless there is an issue and the issue is triaged and accepted. |
reyang
left a comment
There was a problem hiding this comment.
Need an issue + follow the issue workflow https://github.com/open-telemetry/opentelemetry-specification/blob/main/CONTRIBUTING.md#proposing-a-change.
|
@cijothomas / @dashpole I have descoped this PR to only touch the sdk view config. This pr now bring across the definition from declarative config ie include & exclude of attributes. I have left the existing attribute. |
|
@reyang i was asked to raise a pr for this by a spec sponser @cijothomas as per https://cloud-native.slack.com/archives/C01N7PP1THC/p1773713324834269?thread_ts=1773667594.006789&channel=C01N7PP1THC&message_ts=1773713324.834269 hence I didn't think an issue was needed. As identified by the sponser this functionality is actually already defined in stable declarative config so is it actually a new feature? And at the same time the spec already mentioned attributes can be excluded. |
This is what I was using to determine for this PR:
|
|
Ok, I understand but in the case here it could just as easily be classified as a fix given that the spec itself mentions the ability to exclude attributes and it is in released stable declarative config. If you really want it could be classified as a corrective feature given it is fixing 2 things. Anyway the issue is #4960 |
|
This PR was marked stale. It will be closed in 14 days without additional activity. |
|
Awaiting @jack-berg for confirmation about alignment with declarative config. |
|
Declarative config has a policy where we only model properties described in the spec or semantic conventions. My understanding is that this PR is trying to address an apparent discrepancy between the declarative config schema and the spec with respect to a view stream's Some context:
@thompson-tomo from my POV, the only discrepancy between the spec and declarative config is the glob pattern matching semantics. I think declarative config modeling |
|
Thanks @jack-berg for me you have missed the discripency. The spec for
That differs to declarative config:
If we look at the most common use case, I want to opt-in to an optional attribute. based on the current spec I would need to know all other attributes so that I can list them along with the single attribute to add with the attribute property. This changes it so that we are able to just specify the attribute to retain in addition to the standard attributes via the include property. What we could do instead is one of the below but I am not if they would be considered breaking.
|
Sorry this goal was not clear to me. You should put this prominently in the PR title / description. Declarative config's stream config does not accomplish this. There's no mention of ViewStream.attribute_keys.included defining the set of attribute keys which must be retained in addition to the metric advisory parameter. This is net new behavior. From a declarative config standpoint, changing the semantics of |
You are right it doesn't mention that, however it doesn't mention that all other attributes will be excluded. In fact I take it as implicit inclusion due to semconv defining them as included. What it does say
However that statement is problematic when we look at Resource Detection which uses the same object/definition as that would make all opt-in attributes in semconv now the same as recommended with the opt-out nature rather than opt-in. We don't want that. So we could:
As an aside it would be beneficial to persue automatic documenting of configuration of options for semconv as I attempted to do with open-telemetry/semantic-conventions#3396 but got no traction. |
Let's discuss through some examples:
There's no interaction with the Attribute Keys Advisory Param, except when included / excluded are unset. If either included and/or excluded are set, they combine to form a predicate (Predicate in java lingo) which attribute keys are evaluated against.
IncludeExclude does apply to resource to detection as well via .resource.detection/development.attributes, but the filter it forms applies to the output of Let's use another example to discuss:
I don't view the current state of resource detection as ideal. The set of well known resource detectors was added extremely late (well after languages defined these things with their own subjective interpretations) and the semantics (i.e. which exact attributes they provide) are underdefined. This is a stop gap that will hopefully defined with entities, which I expect to have much more rigorously defined entity detectors defined in semantic conventions. |
|
Those examples all work well, so I can see how the design was design has come to be. But they have all focussed on defining the view aspect as opposed to instrument creation as mentioned in https://opentelemetry.io/docs/specs/otel/metrics/sdk/#instrument-advisory-parameters, hence my example above:
This is based on examples in sem-conv such as https://opentelemetry.io/docs/specs/semconv/system/system-metrics/#metric-systemcputime among others. If I replicate your table for that example to opt-in to the 1 attribute I get.
Hence all attributes must be known. If the example was more complex let's say https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#metric-httpserverrequestduration and I wanted to include server.address but not user_agent.synthetic.type my config based on the above approach would need to have 8 attributes listed within attribute_keys.included. In relation to resource detector the way I would interrupt that is include all attributes except for process.command_line which would mean that we would end up with host.ip/mac included even though it is opt-in https://opentelemetry.io/docs/specs/semconv/registry/entities/host/. How could I even include host.ip without listing every single attribute. As an aside I think open-telemetry/weaver#1230 would help with atleast definining resource detectors in terms of their names & the entities provided. |
Fixes #
Changes
Explicitly define method to exclude metric attributes which was already mentioned functionality in the attributes property description in the spec. This exclude functionality was already defined in the stable declarative config. The include is added to avoid changing the behaviour of the existing property.
Discussed on slack -> https://cloud-native.slack.com/archives/C01N7PP1THC/p1773667594006789
For non-trivial changes, follow the change proposal process.
CHANGELOG.mdfile updated for non-trivial changes[chore]in the PR title to skip the changelog check