-
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set tags on SentryOptions through external configuration (#1066)
Add an option to set tags on SentryOptions through external configuration. Fixes gh-981
- Loading branch information
1 parent
8160083
commit bb58d45
Showing
16 changed files
with
252 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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.