-
-
Notifications
You must be signed in to change notification settings - Fork 465
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
Merged
+40
−31
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
46b17cb
Synchronize Baggage keyValues
markushi 9a5e29c
Update Changelog
markushi 1eb8f8b
Add todo for SpanContext copy ctor
markushi f610184
Synchronize iterators
markushi ead5da3
Use AutoClosableReentrantLock in favor of synchronized
markushi 3cc7514
Ensure null values work
markushi cf9ee6c
Merge branch 'main' into markushi/fix/synchronize-mutable-baggages
markushi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import io.sentry.protocol.SentryId; | ||
| import io.sentry.protocol.TransactionNameSource; | ||
| import io.sentry.util.AutoClosableReentrantLock; | ||
| import io.sentry.util.SampleRateUtils; | ||
| import io.sentry.util.StringUtils; | ||
| import java.io.UnsupportedEncodingException; | ||
|
|
@@ -13,7 +14,7 @@ | |
| import java.text.DecimalFormatSymbols; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
|
|
@@ -44,13 +45,15 @@ 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 ConcurrentHashMap<String, String> keyValues; | ||
| private final @NotNull AutoClosableReentrantLock keyValuesLock = new AutoClosableReentrantLock(); | ||
|
|
||
| final @Nullable String thirdPartyHeader; | ||
| private @Nullable Double sampleRate; | ||
| private @Nullable Double sampleRand; | ||
|
|
||
| private final @Nullable String thirdPartyHeader; | ||
| private boolean mutable; | ||
| private boolean shouldFreeze; | ||
| private final boolean shouldFreeze; | ||
| final @NotNull ILogger logger; | ||
|
|
||
| @NotNull | ||
|
|
@@ -99,7 +102,9 @@ public static Baggage fromHeader( | |
| final @Nullable String headerValue, | ||
| final boolean includeThirdPartyValues, | ||
| final @NotNull ILogger logger) { | ||
| final @NotNull Map<String, String> keyValues = new HashMap<>(); | ||
|
|
||
| final @NotNull ConcurrentHashMap<String, String> keyValues = new ConcurrentHashMap<>(); | ||
|
|
||
| final @NotNull List<String> thirdPartyKeyValueStrings = new ArrayList<>(); | ||
| boolean shouldFreeze = false; | ||
|
|
||
|
|
@@ -196,7 +201,7 @@ public static Baggage fromEvent( | |
|
|
||
| @ApiStatus.Internal | ||
| public Baggage(final @NotNull ILogger logger) { | ||
| this(new HashMap<>(), null, null, null, true, false, logger); | ||
| this(new ConcurrentHashMap<>(), null, null, null, true, false, logger); | ||
| } | ||
|
|
||
| @ApiStatus.Internal | ||
|
|
@@ -213,12 +218,12 @@ public Baggage(final @NotNull Baggage baggage) { | |
|
|
||
| @ApiStatus.Internal | ||
| public Baggage( | ||
| final @NotNull Map<String, String> keyValues, | ||
| final @NotNull ConcurrentHashMap<String, String> keyValues, | ||
| 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; | ||
| this.sampleRate = sampleRate; | ||
|
|
@@ -260,7 +265,10 @@ public String getThirdPartyHeader() { | |
| separator = ","; | ||
| } | ||
|
|
||
| final Set<String> keys = new TreeSet<>(keyValues.keySet()); | ||
| final Set<String> keys; | ||
| try (final @NotNull ISentryLifecycleToken ignored = keyValuesLock.acquire()) { | ||
| keys = new TreeSet<>(Collections.list(keyValues.keys())); | ||
| } | ||
| keys.add(DSCKeys.SAMPLE_RATE); | ||
| keys.add(DSCKeys.SAMPLE_RAND); | ||
|
|
||
|
|
@@ -440,38 +448,38 @@ 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) { | ||
| this.keyValues.put(key, value); | ||
| @ApiStatus.Internal | ||
| public void set(final @NotNull String key, final @Nullable String value) { | ||
| if (mutable) { | ||
| if (value == null) { | ||
| keyValues.remove(key); | ||
| } else { | ||
| 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); | ||
| try (final @NotNull ISentryLifecycleToken ignored = keyValuesLock.acquire()) { | ||
| 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; | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.