-
-
Notifications
You must be signed in to change notification settings - Fork 472
Set tags on SentryOptions through external configuration #1066
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
58 changes: 58 additions & 0 deletions
58
sentry/src/main/java/io/sentry/config/AbstractPropertiesProvider.java
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package io.sentry.config; | ||
|
|
||
| import io.sentry.util.Objects; | ||
| import io.sentry.util.StringUtils; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Properties; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** | ||
| * Base class for properties provider resolving properties from {@link Properties} based sources. | ||
| */ | ||
| abstract class AbstractPropertiesProvider implements PropertiesProvider { | ||
| private final @NotNull String prefix; | ||
| private final @NotNull Properties properties; | ||
|
|
||
| protected AbstractPropertiesProvider( | ||
| final @NotNull String prefix, final @NotNull Properties properties) { | ||
| this.prefix = Objects.requireNonNull(prefix, "prefix is required"); | ||
| this.properties = Objects.requireNonNull(properties, "properties are required"); | ||
| } | ||
|
|
||
| protected AbstractPropertiesProvider(final @NotNull Properties properties) { | ||
| this("", properties); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable String getProperty(final @NotNull String property) { | ||
| return StringUtils.removeSurrounding(properties.getProperty(prefix + property), "\""); | ||
| } | ||
|
|
||
| /** | ||
| * Gets property map based on the property name, where property name is a prefix for the expected | ||
| * property name. For example, when {@link #prefix} is set to {@code "sentry."} and following | ||
| * properties are set: sentry.tags.tag1=value1 and sentry.tags.tag2=value2, calling {@code | ||
| * getMap("tags")} returns a map containing pairs "tag1" => "value1" and "tag2" => "value2". | ||
| * | ||
| * @param property the property name | ||
| * @return the map or empty if no matching environment variables found. | ||
| */ | ||
| @Override | ||
| public @NotNull Map<String, String> getMap(final @NotNull String property) { | ||
| final String prefix = this.prefix + property + "."; | ||
|
|
||
| final Map<String, String> result = new HashMap<>(); | ||
| for (Map.Entry<Object, Object> entry : properties.entrySet()) { | ||
| if (entry.getKey() instanceof String && entry.getValue() instanceof String) { | ||
| final String key = (String) entry.getKey(); | ||
| if (key.startsWith(prefix)) { | ||
| final String value = StringUtils.removeSurrounding((String) entry.getValue(), "\""); | ||
| result.put(key.substring(prefix.length()), value); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| } |
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
12 changes: 2 additions & 10 deletions
12
sentry/src/main/java/io/sentry/config/SimplePropertiesProvider.java
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 |
|---|---|---|
| @@ -1,20 +1,12 @@ | ||
| package io.sentry.config; | ||
|
|
||
| import io.sentry.util.StringUtils; | ||
| import java.util.Properties; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** {@link PropertiesProvider} implementation that delegates to {@link Properties}. */ | ||
| final class SimplePropertiesProvider implements PropertiesProvider { | ||
| private final @NotNull Properties properties; | ||
| final class SimplePropertiesProvider extends AbstractPropertiesProvider { | ||
|
|
||
| public SimplePropertiesProvider(final @NotNull Properties properties) { | ||
| this.properties = properties; | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable String getProperty(@NotNull String property) { | ||
| return StringUtils.removeSurrounding(properties.getProperty(property), "\""); | ||
| super(properties); | ||
| } | ||
| } |
13 changes: 4 additions & 9 deletions
13
sentry/src/main/java/io/sentry/config/SystemPropertyPropertiesProvider.java
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 |
|---|---|---|
| @@ -1,17 +1,12 @@ | ||
| package io.sentry.config; | ||
|
|
||
| import io.sentry.util.StringUtils; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** | ||
| * {@link PropertiesProvider} implementation that resolves properties from Java system properties. | ||
| */ | ||
| final class SystemPropertyPropertiesProvider implements PropertiesProvider { | ||
| private static final String PREFIX = "sentry"; | ||
| final class SystemPropertyPropertiesProvider extends AbstractPropertiesProvider { | ||
| private static final String PREFIX = "sentry."; | ||
|
|
||
| @Override | ||
| public @Nullable String getProperty(@NotNull String property) { | ||
| return StringUtils.removeSurrounding(System.getProperty(PREFIX + "." + property), "\""); | ||
| public SystemPropertyPropertiesProvider() { | ||
| super(PREFIX, System.getProperties()); | ||
| } | ||
| } |
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
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.