Update Env var getter / setter to reflect spec changes#8233
Update Env var getter / setter to reflect spec changes#8233jack-berg wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (75.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #8233 +/- ##
============================================
- Coverage 90.32% 90.30% -0.03%
+ Complexity 7653 7649 -4
============================================
Files 843 843
Lines 23080 23073 -7
Branches 2312 2312
============================================
- Hits 20846 20835 -11
- Misses 1516 1517 +1
- Partials 718 721 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| result.add(key.toLowerCase(Locale.ROOT)); | ||
| } | ||
| return result; | ||
| return new ArrayList<>(carrier.keySet()); |
There was a problem hiding this comment.
could be a bit surprising that this method may return keys that can't be read (because get normalizes keys)
There was a problem hiding this comment.
Do you think we should only returns keys that can be actually read (conform to the normalized name)?
There was a problem hiding this comment.
The keys method is only used in deprecated JaegerPropagator and OtTracePropagator so it doesn't really have much of a impact. Even if the environment getter would return empty keys it would probably be fine.
In
uberctx-. If the key is normalized to upper case the check will fail. If it is not then later get will fail to find the value.In I think having the keys normalized would actually work.
There was a problem hiding this comment.
Thanks! Then I think that the keys should be normalized.
Moreover, if you add key = key.toLowerCase(Locale.ROOT); before
then even the deprecated JaegerPropagatorwould work.
I am going address the same issue in Go implementation and also add something the the OTel Specification.
There was a problem hiding this comment.
There was a problem hiding this comment.
Actually the OtTracePropagator wouldn't work either since the prefix is ot-baggage- and - gets replaced with _.
There was a problem hiding this comment.
The keys method is only used in deprecated JaegerPropagator and OtTracePropagator so it doesn't really have much of a impact.
Deprecated and only used for baggage propagation within those.
So what I'm hearing is that keys is incompatible with any propagator which calls it and has keys with characters which would be normalized
Options:
- Throw when
keysis called. Probably a non-starter since you don't know which propagators are configured and throwing an unchecked exception would be disruptive. However, if you are doing this propagation, you do know that you're usingEnvironmentGetterand we could document that for this use case you need to handle exceptions when you callTextMapPropagator.extract(Context.current(), env, EnvironmentGetter.getInstance()). - When
keysis called, return empty iterable and:- Log a warning. Means that propagation will fail with certain propagators, but at least there's a breadcrumb point to what happened.
- Do nothing extra. Means that propagation will fail silently with certain propagators.
- Return normalized or lowercased keys, and adjust JaegerPropagator / OtTracePropagator to reduce dependency on
keysand make it more resilient to-vs._, and:- Log a warning when
keysis called. This would allow future propagators to have bread crumb if they use keys, which may not function in env var context. - Do nothing extra.
- Log a warning when
I lean towards logging a warning when keys is called, and not very opinionated about what the actual return value of keys is (as is, normalized, lowercased, or empty).
There was a problem hiding this comment.
If Keys returns keys in normalized form then Get should also normalize the cached env vars. Otherwise we will have similar problem as described in #8233 (comment). This is what is done in open-telemetry/opentelemetry-go-contrib#8761
See open-telemetry/opentelemetry-specification#4961
Changes:
_prefix if the key would start with a digitcc @Bhagirath00