-
-
Notifications
You must be signed in to change notification settings - Fork 468
Synchronize Baggage keyValues #4327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
46b17cb
9a5e29c
1eb8f8b
f610184
ead5da3
3cc7514
cf9ee6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||
| import java.text.DecimalFormatSymbols; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.Arrays; | ||||||
| import java.util.Collections; | ||||||
| import java.util.HashMap; | ||||||
| import java.util.List; | ||||||
| import java.util.Locale; | ||||||
|
|
@@ -44,13 +45,13 @@ protected DecimalFormat initialValue() { | |||||
| private static final DecimalFormatterThreadLocal decimalFormatter = | ||||||
| new DecimalFormatterThreadLocal(); | ||||||
|
|
||||||
| final @NotNull Map<String, String> keyValues; | ||||||
| @Nullable Double sampleRate; | ||||||
| @Nullable Double sampleRand; | ||||||
| private final @NotNull Map<String, String> keyValues; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
we should also change this in all locations of this file, where we have |
||||||
| private @Nullable Double sampleRate; | ||||||
| private @Nullable Double sampleRand; | ||||||
|
|
||||||
| final @Nullable String thirdPartyHeader; | ||||||
| private final @Nullable String thirdPartyHeader; | ||||||
| private boolean mutable; | ||||||
| private boolean shouldFreeze; | ||||||
| private final boolean shouldFreeze; | ||||||
| final @NotNull ILogger logger; | ||||||
|
|
||||||
| @NotNull | ||||||
|
|
@@ -217,10 +218,12 @@ public Baggage( | |||||
| final @Nullable Double sampleRate, | ||||||
| final @Nullable Double sampleRand, | ||||||
| final @Nullable String thirdPartyHeader, | ||||||
| boolean isMutable, | ||||||
| boolean shouldFreeze, | ||||||
| final boolean isMutable, | ||||||
| final boolean shouldFreeze, | ||||||
| final @NotNull ILogger logger) { | ||||||
| this.keyValues = keyValues; | ||||||
| // TODO should we deep-copy the keyValues here? | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we sometimes want to write to a shared baggage. |
||||||
| // if so we could optimize this by only synchronizing in case isMutable is true | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are cases where we forcefully overwrite the sample rate, even if mutable = false. |
||||||
| this.keyValues = Collections.synchronizedMap(keyValues); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of wrapping here, which will cause problems with virtual threads again due to using |
||||||
| this.sampleRate = sampleRate; | ||||||
| this.sampleRand = sampleRand; | ||||||
| this.logger = logger; | ||||||
|
|
@@ -260,7 +263,10 @@ public String getThirdPartyHeader() { | |||||
| separator = ","; | ||||||
| } | ||||||
|
|
||||||
| final Set<String> keys = new TreeSet<>(keyValues.keySet()); | ||||||
| final Set<String> keys; | ||||||
| synchronized (keyValues) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See below, replace with |
||||||
| keys = new TreeSet<>(keyValues.keySet()); | ||||||
| } | ||||||
| keys.add(DSCKeys.SAMPLE_RATE); | ||||||
| keys.add(DSCKeys.SAMPLE_RAND); | ||||||
|
|
||||||
|
|
@@ -440,38 +446,34 @@ public void setReplayId(final @Nullable String replayId) { | |||||
| set(DSCKeys.REPLAY_ID, replayId); | ||||||
| } | ||||||
|
|
||||||
| @ApiStatus.Internal | ||||||
| public void set(final @NotNull String key, final @Nullable String value) { | ||||||
| set(key, value, false); | ||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was always called with |
||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Sets / updates a value | ||||||
| * Sets / updates a value, but only if the baggage is still mutable. | ||||||
| * | ||||||
| * @param key key | ||||||
| * @param value value to set | ||||||
| * @param force ignores mutability of this baggage and sets the value anyways | ||||||
| */ | ||||||
| private void set(final @NotNull String key, final @Nullable String value, final boolean force) { | ||||||
| if (mutable || force) { | ||||||
| @ApiStatus.Internal | ||||||
| public void set(final @NotNull String key, final @Nullable String value) { | ||||||
| if (mutable) { | ||||||
| this.keyValues.put(key, value); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| @ApiStatus.Internal | ||||||
| public @NotNull Map<String, Object> getUnknown() { | ||||||
| final @NotNull Map<String, Object> unknown = new ConcurrentHashMap<>(); | ||||||
| for (Map.Entry<String, String> keyValue : this.keyValues.entrySet()) { | ||||||
| final @NotNull String key = keyValue.getKey(); | ||||||
| final @Nullable String value = keyValue.getValue(); | ||||||
| if (!DSCKeys.ALL.contains(key)) { | ||||||
| if (value != null) { | ||||||
| final @NotNull String unknownKey = key.replaceFirst(SENTRY_BAGGAGE_PREFIX, ""); | ||||||
| unknown.put(unknownKey, value); | ||||||
| synchronized (keyValues) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use |
||||||
| for (final Map.Entry<String, String> keyValue : keyValues.entrySet()) { | ||||||
| final @NotNull String key = keyValue.getKey(); | ||||||
| final @Nullable String value = keyValue.getValue(); | ||||||
| if (!DSCKeys.ALL.contains(key)) { | ||||||
| if (value != null) { | ||||||
| final @NotNull String unknownKey = key.replaceFirst(SENTRY_BAGGAGE_PREFIX, ""); | ||||||
| unknown.put(unknownKey, value); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return unknown; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,7 @@ public SpanContext(final @NotNull SpanContext spanContext) { | |
| if (copiedUnknown != null) { | ||
| this.unknown = copiedUnknown; | ||
| } | ||
| // TODO should this be a deep copy instead? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we need to share entries. |
||
| this.baggage = spanContext.baggage; | ||
| final Map<String, Object> copiedData = CollectionUtils.newConcurrentHashMap(spanContext.data); | ||
| if (copiedData != null) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.