This repository was archived by the owner on Aug 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
Refactor using common parts of SentryOptions.
#528
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1016310
Move SentryProperties to sentry-core.
maciejwalkowiak b84ea26
Use SentryProperties in Logback integration.
maciejwalkowiak aedd072
Add tests & polish.
maciejwalkowiak a5c6d33
Remove default diagnostic level in SentryCommonOptions.
maciejwalkowiak 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
263 changes: 263 additions & 0 deletions
263
sentry-core/src/main/java/io/sentry/core/SentryCommonOptions.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,263 @@ | ||
| package io.sentry.core; | ||
|
|
||
| import com.jakewharton.nopen.annotation.Open; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** Subset of {@link SentryOptions} properties used in 3rd party framework integrations. */ | ||
| @Open | ||
| public class SentryCommonOptions { | ||
|
|
||
| /** @see SentryOptions#dsn */ | ||
| private String dsn = ""; | ||
|
|
||
| /** @see SentryOptions#shutdownTimeoutMillis */ | ||
| private Long shutdownTimeoutMillis; | ||
|
|
||
| /** @see SentryOptions#flushTimeoutMillis */ | ||
| private Long flushTimeoutMillis; | ||
|
|
||
| /** @see SentryOptions#readTimeoutMillis */ | ||
| private Integer readTimeoutMillis; | ||
|
|
||
| /** @see SentryOptions#bypassSecurity */ | ||
| private Boolean bypassSecurity; | ||
|
|
||
| /** @see SentryOptions#debug */ | ||
| private Boolean debug; | ||
|
|
||
| /** @see SentryOptions#diagnosticLevel */ | ||
| private SentryLevel diagnosticLevel; | ||
|
|
||
| /** @see SentryOptions#maxBreadcrumbs */ | ||
| private Integer maxBreadcrumbs; | ||
|
|
||
| /** @see SentryOptions#release */ | ||
| private String release; | ||
|
|
||
| /** @see SentryOptions#environment */ | ||
| private String environment; | ||
|
|
||
| /** @see SentryOptions#sampleRate */ | ||
| private Double sampleRate; | ||
|
|
||
| /** @see SentryOptions#inAppExcludes */ | ||
| private List<String> inAppExcludes = new ArrayList<>(); | ||
|
|
||
| /** @see SentryOptions#inAppIncludes */ | ||
| private List<String> inAppIncludes = new ArrayList<>(); | ||
|
|
||
| /** @see SentryOptions#dist */ | ||
| private String dist; | ||
|
|
||
| /** @see SentryOptions#attachThreads */ | ||
| private Boolean attachThreads; | ||
|
|
||
| /** @see SentryOptions#attachStacktrace */ | ||
| private Boolean attachStacktrace; | ||
|
|
||
| /** @see SentryOptions#serverName */ | ||
| private String serverName; | ||
|
|
||
| /** | ||
| * Applies configuration from this instance to the {@link SentryOptions} instance. | ||
| * | ||
| * @param options the instance of {@link SentryOptions} to apply the configuration to | ||
| */ | ||
| public void applyTo(SentryOptions options) { | ||
| if (dsn != null) { | ||
| options.setDsn(dsn); | ||
| } | ||
| if (maxBreadcrumbs != null) { | ||
| options.setMaxBreadcrumbs(maxBreadcrumbs); | ||
| } | ||
| if (environment != null) { | ||
| options.setEnvironment(environment); | ||
| } | ||
| if (shutdownTimeoutMillis != null) { | ||
| options.setShutdownTimeout(shutdownTimeoutMillis); | ||
| } | ||
| if (flushTimeoutMillis != null) { | ||
| options.setFlushTimeoutMillis(flushTimeoutMillis); | ||
| } | ||
| if (readTimeoutMillis != null) { | ||
| options.setReadTimeoutMillis(readTimeoutMillis); | ||
| } | ||
| if (sampleRate != null) { | ||
| options.setSampleRate(sampleRate); | ||
| } | ||
| if (bypassSecurity != null) { | ||
| options.setBypassSecurity(bypassSecurity); | ||
| } | ||
| if (debug != null) { | ||
| options.setDebug(debug); | ||
| } | ||
| if (attachThreads != null) { | ||
| options.setAttachThreads(attachThreads); | ||
| } | ||
| if (attachStacktrace != null) { | ||
| options.setAttachStacktrace(attachStacktrace); | ||
| } | ||
| if (diagnosticLevel != null) { | ||
| options.setDiagnosticLevel(diagnosticLevel); | ||
| } | ||
| if (dist != null) { | ||
| options.setDist(dist); | ||
| } | ||
| if (release != null) { | ||
| options.setRelease(release); | ||
| } | ||
| if (sampleRate != null) { | ||
| options.setSampleRate(sampleRate); | ||
| } | ||
| if (serverName != null) { | ||
| options.setServerName(serverName); | ||
| } | ||
| if (inAppExcludes != null) { | ||
| for (String inAppExclude : inAppExcludes) { | ||
| options.addInAppExclude(inAppExclude); | ||
| } | ||
| } | ||
| if (inAppIncludes != null) { | ||
| for (String inAppInclude : inAppIncludes) { | ||
| options.addInAppInclude(inAppInclude); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public String getDsn() { | ||
| return dsn; | ||
| } | ||
|
|
||
| public void setDsn(String dsn) { | ||
| this.dsn = dsn; | ||
| } | ||
|
|
||
| public Long getShutdownTimeoutMillis() { | ||
| return shutdownTimeoutMillis; | ||
| } | ||
|
|
||
| public void setShutdownTimeoutMillis(Long shutdownTimeoutMillis) { | ||
| this.shutdownTimeoutMillis = shutdownTimeoutMillis; | ||
| } | ||
|
|
||
| public Long getFlushTimeoutMillis() { | ||
| return flushTimeoutMillis; | ||
| } | ||
|
|
||
| public void setFlushTimeoutMillis(Long flushTimeoutMillis) { | ||
| this.flushTimeoutMillis = flushTimeoutMillis; | ||
| } | ||
|
|
||
| public Integer getReadTimeoutMillis() { | ||
| return readTimeoutMillis; | ||
| } | ||
|
|
||
| public void setReadTimeoutMillis(Integer readTimeoutMillis) { | ||
| this.readTimeoutMillis = readTimeoutMillis; | ||
| } | ||
|
|
||
| public Boolean getBypassSecurity() { | ||
| return bypassSecurity; | ||
| } | ||
|
|
||
| public void setBypassSecurity(Boolean bypassSecurity) { | ||
| this.bypassSecurity = bypassSecurity; | ||
| } | ||
|
|
||
| public Boolean getDebug() { | ||
| return debug; | ||
| } | ||
|
|
||
| public void setDebug(Boolean debug) { | ||
| this.debug = debug; | ||
| } | ||
|
|
||
| public SentryLevel getDiagnosticLevel() { | ||
| return diagnosticLevel; | ||
| } | ||
|
|
||
| public void setDiagnosticLevel(SentryLevel diagnosticLevel) { | ||
| this.diagnosticLevel = diagnosticLevel; | ||
|
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. if you look at 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. In |
||
| } | ||
|
|
||
| public Integer getMaxBreadcrumbs() { | ||
| return maxBreadcrumbs; | ||
| } | ||
|
|
||
| public void setMaxBreadcrumbs(Integer maxBreadcrumbs) { | ||
| this.maxBreadcrumbs = maxBreadcrumbs; | ||
| } | ||
|
|
||
| public String getRelease() { | ||
| return release; | ||
| } | ||
|
|
||
| public void setRelease(String release) { | ||
| this.release = release; | ||
| } | ||
|
|
||
| public String getEnvironment() { | ||
| return environment; | ||
| } | ||
|
|
||
| public void setEnvironment(String environment) { | ||
| this.environment = environment; | ||
| } | ||
|
|
||
| public Double getSampleRate() { | ||
| return sampleRate; | ||
| } | ||
|
|
||
| public void setSampleRate(Double sampleRate) { | ||
| this.sampleRate = sampleRate; | ||
| } | ||
|
|
||
| public List<String> getInAppExcludes() { | ||
| return inAppExcludes; | ||
| } | ||
|
|
||
| public void setInAppExcludes(List<String> inAppExcludes) { | ||
| this.inAppExcludes = inAppExcludes; | ||
| } | ||
|
|
||
| public List<String> getInAppIncludes() { | ||
| return inAppIncludes; | ||
| } | ||
|
|
||
| public void setInAppIncludes(List<String> inAppIncludes) { | ||
| this.inAppIncludes = inAppIncludes; | ||
| } | ||
|
|
||
| public String getDist() { | ||
| return dist; | ||
| } | ||
|
|
||
| public void setDist(String dist) { | ||
| this.dist = dist; | ||
| } | ||
|
|
||
| public Boolean getAttachThreads() { | ||
| return attachThreads; | ||
| } | ||
|
|
||
| public void setAttachThreads(Boolean attachThreads) { | ||
| this.attachThreads = attachThreads; | ||
| } | ||
|
|
||
| public Boolean getAttachStacktrace() { | ||
| return attachStacktrace; | ||
| } | ||
|
|
||
| public void setAttachStacktrace(Boolean attachStacktrace) { | ||
| this.attachStacktrace = attachStacktrace; | ||
| } | ||
|
|
||
| public String getServerName() { | ||
| return serverName; | ||
| } | ||
|
|
||
| public void setServerName(String serverName) { | ||
| this.serverName = serverName; | ||
| } | ||
| } | ||
52 changes: 52 additions & 0 deletions
52
sentry-core/src/test/java/io/sentry/core/SentryCommonOptionsTest.kt
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,52 @@ | ||
| package io.sentry.core | ||
|
|
||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class SentryCommonOptionsTest { | ||
|
|
||
| @Test | ||
| fun `applies properties to SentryOptions`() { | ||
| val commonOptions = with(SentryCommonOptions()) { | ||
| dsn = "http://key@localhost/proj" | ||
| readTimeoutMillis = 10 | ||
| shutdownTimeoutMillis = 20L | ||
| flushTimeoutMillis = 30 | ||
| bypassSecurity = true | ||
| debug = true | ||
| diagnosticLevel = SentryLevel.INFO | ||
| maxBreadcrumbs = 100 | ||
| release = "1.0.3" | ||
| environment = "production" | ||
| sampleRate = 0.2 | ||
| inAppExcludes = listOf("org.springframework") | ||
| inAppIncludes = listOf("com.myapp") | ||
| dist = "my-dist" | ||
| attachStacktrace = true | ||
| attachThreads = true | ||
| serverName = "host-001" | ||
| this | ||
| } | ||
|
|
||
| val options = SentryOptions() | ||
| commonOptions.applyTo(options) | ||
|
|
||
| assertEquals(10, options.readTimeoutMillis) | ||
| assertEquals(20, options.shutdownTimeout) | ||
| assertEquals(30, options.flushTimeoutMillis) | ||
| assertEquals(true, options.isBypassSecurity) | ||
| assertEquals(true, options.isDebug) | ||
| assertEquals(SentryLevel.INFO, options.diagnosticLevel) | ||
| assertEquals(100, options.maxBreadcrumbs) | ||
| assertEquals("1.0.3", options.release) | ||
| assertEquals("production", options.environment) | ||
| assertEquals(0.2, options.sampleRate) | ||
| assertTrue(options.inAppExcludes.contains("org.springframework")) | ||
| assertTrue(options.inAppIncludes.contains("com.myapp")) | ||
| assertEquals("my-dist", options.dist) | ||
| assertEquals(true, options.isAttachThreads) | ||
| assertEquals(true, options.isAttachStacktrace) | ||
| assertEquals("host-001", options.serverName) | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use primitive types? otherwise, we'd need to do NPE checks in the setters too, also for all the other fields that are primitive types in SentryOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advantage is being able to know if the value was set explicitly by the user and being able to flip the default after invoking a user callback.
But for this field I agree probably doesn't make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @bruno-garcia said, we need to know which values were set explicitly by user. This way we don't need to keep in sync default values on
SentryOptionsandSentryCommonOptions. This also includes data type for fields - they have to be nullable otherwise we loose this information.