Update Env var getter / setter to reflect spec changes#8233
Update Env var getter / setter to reflect spec changes#8233jack-berg wants to merge 5 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8233 +/- ##
============================================
- Coverage 90.32% 90.31% -0.01%
- Complexity 7653 7654 +1
============================================
Files 843 842 -1
Lines 23080 23081 +1
Branches 2312 2314 +2
============================================
- Hits 20846 20845 -1
+ Misses 1516 1515 -1
- Partials 718 721 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
api/incubator/src/main/java/io/opentelemetry/api/incubator/propagation/EnvironmentGetter.java
Outdated
Show resolved
Hide resolved
| void get_normalization() { | ||
| Map<String, String> carrier = new HashMap<>(); | ||
| carrier.put("OTEL_TRACE_ID", "val1"); | ||
| carrier.put("OTEL_BAGGAGE_KEY", "val2"); |
There was a problem hiding this comment.
I think the issue described in #8233 (comment) still exists
I suggest changing this line to e.g.
| carrier.put("OTEL_BAGGAGE_KEY", "val2"); | |
| carrier.put("otel-baggage-key", "val2"); |
Note that in this scenario keys would return OTEL_TRACE_ID and OTEL_BAGGAGE_KEY as described in the test keys_valuesAreNormalized
If Keys returns keys in normalized form then Get should also normalize the cached env vars.
cached env vars == keys in the carrier
There was a problem hiding this comment.
Feel free to resolve (I do not have such power here 😉)
| if (EnvironmentSetter.normalizeKey(entryKey).equals(normalizedKey)) { | ||
| result[0] = entryValue; | ||
| } | ||
| }); |
There was a problem hiding this comment.
Not great that evertime we read a key, we have to normalize potentially all the keys in the carrier. Go gets around this by computing the normalized keys once and using the carrier as a cache. In java, its not safe to assume that the map is mutable.
I imagine this isn't a real problem though because env var propagation implies your going to start a new process and pass the context to it via env vars, which is much heavier weight than what we're doing here.
There was a problem hiding this comment.
I imagine this isn't a real problem though because env var propagation implies your going to start a new process and pass the context to it via env vars, which is much heavier weight than what we're doing here.
Agreed and at least it is a robust implementation 😁
84a17ed to
f829e51
Compare
| carrier.forEach( | ||
| (entryKey, entryValue) -> { | ||
| if (EnvironmentSetter.normalizeKey(entryKey).equals(normalizedKey)) { | ||
| result[0] = entryValue; |
There was a problem hiding this comment.
I guess that thus can be done a little more efficient.
We could break when we find a matching key instead of iterating over all env vars.
I guess iterating over carrier.entrySet() and early return the value when normalized key matches.
There was a problem hiding this comment.
Oh yeah can't exit early from for each. So it's either use a traditional loop which allocated but can exit early, or use forEach which doesn't allocate but which can't exit early
There was a problem hiding this comment.
Given that strings are being allocated for every key, trying to avoid allocating for map iteration is silly optimization. Will switch to tradition for loop and exit early
See open-telemetry/opentelemetry-specification#4961
Changes:
_prefix if the key would start with a digitcc @Bhagirath00