Repository navigation
fix(metrics_sdk)!: add the attribute_keys filter for view - #2426
xuan-cao-swi wants to merge 4 commits into
Conversation
mwear
left a comment
There was a problem hiding this comment.
I left a few comments in-line. Since this changes what attribute_keys does for anyone passing a Hash today (values were merged in, now the keys filter the stream), can you mark the title as breaking, e.g. fix(metrics_sdk)!:, so it's called out in the changelog?
| included = normalize_attribute_keys(attribute_keys[:included]) | ||
| excluded = normalize_attribute_keys(attribute_keys[:excluded]) | ||
|
|
||
| OpenTelemetry.logger.warn("attribute_keys #{overlap.inspect} are both included and excluded. They will be treated as excluded.") if included && excluded && included.intersect?(excluded) |
There was a problem hiding this comment.
overlap isn't defined, so a NameError will be raised if this code path executes.
The README and the add_view docs also say this raises an ArgumentError, but the intent here looks like warn and treat the key as excluded. The spec allows either, so I have a slight preference for raising an ArgumentError, since that's what's already documented. Either way, can you make the code and docs agree and add a test for the overlap case?
There was a problem hiding this comment.
Update to use overlap and added the test case for overlap.
I still log the warning because the only concern is that don't want to break user's application, although I am open to raise the error anyway since the next comment/change also raise the error
| end | ||
|
|
||
| return [nil, nil] if attribute_keys.empty? | ||
| return [normalize_attribute_keys(attribute_keys.keys), nil] unless (attribute_keys.keys - INCLUDE_EXCLUDE_KEYS).empty? |
There was a problem hiding this comment.
If a Hash mixes the two forms, e.g. { included: ['a'], 'b' => nil }, this falls through to the legacy allow-list path and the allow-list becomes ['included', 'b'], so a gets dropped. Similarly, { 'included' => nil }, meant as a legacy allow-list for an attribute named included, becomes no filter at all because of the symbol conversion above. I think raising an ArgumentError when included/excluded are mixed with other keys would be clearer than guessing. What do you think?
There was a problem hiding this comment.
Yes, I think simplification make sense. Raising error here but I am open to just log the warning to avoid break user's application (e.g. log the error and don't ignore anything)
There was a problem hiding this comment.
p.s. either log or raise the error for both case
Description
Resolves #2359
view will filter out the attributes that is for reporting if the attributes key is in denylist or not in allowlist (e.g.
view_attributes = view.filter_attributes(attributes))