diff --git a/sentry-core/src/main/java/io/sentry/core/SentryBindableOptions.java b/sentry-core/src/main/java/io/sentry/core/SentryBindableOptions.java new file mode 100644 index 000000000..8a8255d73 --- /dev/null +++ b/sentry-core/src/main/java/io/sentry/core/SentryBindableOptions.java @@ -0,0 +1,487 @@ +package io.sentry.core; + +import static io.sentry.core.SentryOptions.DEFAULT_DIAGNOSTIC_LEVEL; + +import com.jakewharton.nopen.annotation.Open; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Subset of {@link SentryOptions} properties bindable from text, extracted to separate class to be + * used in 3rd party framework integrations. + */ +@Open +public class SentryBindableOptions { + + /** + * The DSN tells the SDK where to send the events to. If this value is not provided, the SDK will + * just not send any events. + */ + private @Nullable String dsn; + + /** + * Controls how many seconds to wait before shutting down. Sentry SDKs send events from a + * background queue and this queue is given a certain amount to drain pending events Default is + * 2000 = 2s + */ + private long shutdownTimeout = 2000; // 2s + + /** + * Controls how many seconds to wait before flushing down. Sentry SDKs cache events from a + * background queue and this queue is given a certain amount to drain pending events Default is + * 15000 = 15s + */ + private long flushTimeoutMillis = 15000; // 15s + + /** connection timeout in milliseconds. */ + private int connectionTimeoutMillis = 5000; + + /** minimum LogLevel to be used if debug is enabled */ + private @NotNull SentryLevel diagnosticLevel = DEFAULT_DIAGNOSTIC_LEVEL; + + /** + * Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging + * information if something goes wrong. Default is disabled. + */ + private boolean debug; + + /** + * This variable controls the total amount of breadcrumbs that should be captured Default is 100 + */ + private int maxBreadcrumbs = 100; + + /** Sets the release. SDK will try to automatically configure a release out of the box */ + private @Nullable String release; + + /** + * Sets the environment. This string is freeform and not set by default. A release can be + * associated with more than one environment to separate them in the UI Think staging vs prod or + * similar. + */ + private @Nullable String environment; + + /** + * Configures the sample rate as a percentage of events to be sent in the range of 0.0 to 1.0. if + * 1.0 is set it means that 100% of events are sent. If set to 0.1 only 10% of events will be + * sent. Events are picked randomly. Default is null (disabled) + */ + private @Nullable Double sampleRate; + + /** + * A list of string prefixes of module names that do not belong to the app, but rather third-party + * packages. Modules considered not to be part of the app will be hidden from stack traces by + * default. + */ + private @NotNull List inAppExcludes = new CopyOnWriteArrayList<>(); + + /** + * A list of string prefixes of module names that belong to the app. This option takes precedence + * over inAppExcludes. + */ + private @NotNull List inAppIncludes = new CopyOnWriteArrayList<>(); + + /** Sets the distribution. Think about it together with release and environment */ + private @Nullable String dist; + + /** When enabled, threads are automatically attached to all logged events. */ + private boolean attachThreads = true; + + /** + * When enabled, stack traces are automatically attached to all threads logged. Stack traces are + * always attached to exceptions but when this is set stack traces are also sent with threads + */ + private boolean attachStacktrace; + + /** The server name used in the Sentry messages. */ + private String serverName; + + /** read timeout in milliseconds */ + private int readTimeoutMillis = 5000; + + /** whether to ignore TLS errors */ + private boolean bypassSecurity = false; + + /** + * 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 (environment != null) { + options.setEnvironment(environment); + } + if (sampleRate != null) { + options.setSampleRate(sampleRate); + } + if (dist != null) { + options.setDist(dist); + } + if (release != null) { + options.setRelease(release); + } + if (sampleRate != null) { + options.setSampleRate(sampleRate); + } + if (serverName != null) { + options.setServerName(serverName); + } + for (String inAppExclude : inAppExcludes) { + options.addInAppExclude(inAppExclude); + } + for (String inAppInclude : inAppIncludes) { + options.addInAppInclude(inAppInclude); + } + options.setMaxBreadcrumbs(maxBreadcrumbs); + options.setShutdownTimeout(shutdownTimeout); + options.setFlushTimeoutMillis(flushTimeoutMillis); + options.setReadTimeoutMillis(readTimeoutMillis); + options.setBypassSecurity(bypassSecurity); + options.setDebug(debug); + options.setAttachThreads(attachThreads); + options.setAttachStacktrace(attachStacktrace); + options.setDiagnosticLevel(diagnosticLevel); + } + + /** + * Returns the DSN + * + * @return the DSN or null if not set + */ + public @Nullable String getDsn() { + return dsn; + } + + /** + * Sets the DSN + * + * @param dsn the DSN + */ + public void setDsn(@Nullable String dsn) { + this.dsn = dsn; + } + + /** + * Check if debug mode is ON Default is OFF + * + * @return true if ON or false otherwise + */ + public boolean isDebug() { + return debug; + } + + /** + * Sets the debug mode to ON or OFF Default is OFF + * + * @param debug true if ON or false otherwise + */ + public void setDebug(boolean debug) { + this.debug = debug; + } + + /** + * Returns the minimum LogLevel + * + * @return the log level + */ + public @NotNull SentryLevel getDiagnosticLevel() { + return diagnosticLevel; + } + + /** + * Sets the minimum LogLevel if null, it uses the default min. LogLevel Default is DEBUG + * + * @param diagnosticLevel the log level + */ + public void setDiagnosticLevel(@Nullable final SentryLevel diagnosticLevel) { + this.diagnosticLevel = (diagnosticLevel != null) ? diagnosticLevel : DEFAULT_DIAGNOSTIC_LEVEL; + } + + /** + * Returns the shutdown timeout in Millis + * + * @return the timeout in Millis + */ + public long getShutdownTimeout() { + return shutdownTimeout; + } + + /** + * Sets the shutdown timeout in Millis Default is 2000 = 2s + * + * @param shutdownTimeoutMillis the shutdown timeout in millis + */ + public void setShutdownTimeout(long shutdownTimeoutMillis) { + this.shutdownTimeout = shutdownTimeoutMillis; + } + + /** + * Returns the max Breadcrumbs Default is 100 + * + * @return the max breadcrumbs + */ + public int getMaxBreadcrumbs() { + return maxBreadcrumbs; + } + + /** + * Sets the max breadcrumbs Default is 100 + * + * @param maxBreadcrumbs the max breadcrumbs + */ + public void setMaxBreadcrumbs(int maxBreadcrumbs) { + this.maxBreadcrumbs = maxBreadcrumbs; + } + + /** + * Returns the release + * + * @return the release or null if not set + */ + public @Nullable String getRelease() { + return release; + } + + /** + * Sets the release + * + * @param release the release + */ + public void setRelease(@Nullable String release) { + this.release = release; + } + + /** + * Returns the environment + * + * @return the environment or null if not set + */ + public @Nullable String getEnvironment() { + return environment; + } + + /** + * Sets the environment + * + * @param environment the environment + */ + public void setEnvironment(@Nullable String environment) { + this.environment = environment; + } + + /** + * Returns the sample rate Default is null (disabled) + * + * @return the sample rate + */ + public @Nullable Double getSampleRate() { + return sampleRate; + } + + /** + * Sets the sampleRate Can be anything between 0.01 and 1.0 or null (default), to disable it. + * + * @param sampleRate the sample rate + */ + public void setSampleRate(Double sampleRate) { + if (sampleRate != null && (sampleRate > 1.0 || sampleRate <= 0.0)) { + throw new IllegalArgumentException( + "The value " + + sampleRate + + " is not valid. Use null to disable or values between 0.01 (inclusive) and 1.0 (exclusive)."); + } + this.sampleRate = sampleRate; + } + + /** + * the list of inApp excludes + * + * @return the inApp excludes list + */ + public @NotNull List getInAppExcludes() { + return inAppExcludes; + } + + public void setInAppExcludes(List inAppExcludes) { + this.inAppExcludes = new CopyOnWriteArrayList<>(inAppExcludes); + } + + /** + * Adds an inApp exclude + * + * @param exclude the inApp exclude module/package + */ + public void addInAppExclude(@NotNull String exclude) { + inAppExcludes.add(exclude); + } + + /** + * Returns the inApp includes list + * + * @return the inApp includes list + */ + public @NotNull List getInAppIncludes() { + return inAppIncludes; + } + + /** + * Adds an inApp include + * + * @param include the inApp include module/package + */ + public void addInAppInclude(@NotNull String include) { + inAppIncludes.add(include); + } + + public void setInAppIncludes(List inAppIncludes) { + this.inAppIncludes = new CopyOnWriteArrayList<>(inAppIncludes); + } + + /** + * Sets the distribution + * + * @return the distribution or null if not set + */ + public @Nullable String getDist() { + return dist; + } + + /** + * Sets the distribution + * + * @param dist the distribution + */ + public void setDist(@Nullable String dist) { + this.dist = dist; + } + + /** + * Checks if the AttachStacktrace is enabled or not + * + * @return true if enabled or false otherwise + */ + public boolean isAttachStacktrace() { + return attachStacktrace; + } + + /** + * Sets the attachStacktrace to enabled or disabled + * + * @param attachStacktrace true if enabled or false otherwise + */ + public void setAttachStacktrace(boolean attachStacktrace) { + this.attachStacktrace = attachStacktrace; + } + + /** + * Checks if the AttachThreads is enabled or not + * + * @return true if enabled or false otherwise + */ + public boolean isAttachThreads() { + return attachThreads; + } + + /** + * Sets the attachThreads to enabled or disabled + * + * @param attachThreads true if enabled or false otherwise + */ + public void setAttachThreads(boolean attachThreads) { + this.attachThreads = attachThreads; + } + + /** + * Gets the default server name to be used in Sentry events. + * + * @return the default server name or null if none set + */ + public @Nullable String getServerName() { + return serverName; + } + + /** + * Sets the default server name to be used in Sentry events. + * + * @param serverName the default server name or null if none should be used + */ + public void setServerName(@Nullable String serverName) { + this.serverName = serverName; + } + + /** + * Returns the flush timeout in millis + * + * @return the timeout in millis + */ + public long getFlushTimeoutMillis() { + return flushTimeoutMillis; + } + + /** + * Sets the flush timeout in millis + * + * @param flushTimeoutMillis the timeout in millis + */ + public void setFlushTimeoutMillis(long flushTimeoutMillis) { + this.flushTimeoutMillis = flushTimeoutMillis; + } + + /** + * Returns the connection timeout in milliseconds. + * + * @return the connectionTimeoutMillis + */ + public int getConnectionTimeoutMillis() { + return connectionTimeoutMillis; + } + + /** + * Sets the connection timeout in milliseconds. + * + * @param connectionTimeoutMillis the connectionTimeoutMillis + */ + public void setConnectionTimeoutMillis(int connectionTimeoutMillis) { + this.connectionTimeoutMillis = connectionTimeoutMillis; + } + + /** + * Returns the read timeout in milliseconds + * + * @return the readTimeoutMillis + */ + public int getReadTimeoutMillis() { + return readTimeoutMillis; + } + + /** + * Sets the read timeout in milliseconds + * + * @param readTimeoutMillis the readTimeoutMillis + */ + public void setReadTimeoutMillis(int readTimeoutMillis) { + this.readTimeoutMillis = readTimeoutMillis; + } + + /** + * Returns whether to ignore TLS errors + * + * @return the bypassSecurity + */ + public boolean isBypassSecurity() { + return bypassSecurity; + } + + /** + * Sets whether to ignore TLS errors + * + * @param bypassSecurity the bypassSecurity + */ + public void setBypassSecurity(boolean bypassSecurity) { + this.bypassSecurity = bypassSecurity; + } +} diff --git a/sentry-core/src/main/java/io/sentry/core/SentryCommonOptions.java b/sentry-core/src/main/java/io/sentry/core/SentryCommonOptions.java deleted file mode 100644 index 48ef1d114..000000000 --- a/sentry-core/src/main/java/io/sentry/core/SentryCommonOptions.java +++ /dev/null @@ -1,263 +0,0 @@ -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 inAppExcludes = new ArrayList<>(); - - /** @see SentryOptions#inAppIncludes */ - private List 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; - } - - 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 getInAppExcludes() { - return inAppExcludes; - } - - public void setInAppExcludes(List inAppExcludes) { - this.inAppExcludes = inAppExcludes; - } - - public List getInAppIncludes() { - return inAppIncludes; - } - - public void setInAppIncludes(List 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; - } -} diff --git a/sentry-core/src/main/java/io/sentry/core/SentryOptions.java b/sentry-core/src/main/java/io/sentry/core/SentryOptions.java index c3246f8d3..64e81d273 100644 --- a/sentry-core/src/main/java/io/sentry/core/SentryOptions.java +++ b/sentry-core/src/main/java/io/sentry/core/SentryOptions.java @@ -20,7 +20,7 @@ /** Sentry SDK options */ @Open -public class SentryOptions { +public class SentryOptions extends SentryBindableOptions { /** Default Log level if not specified Default is DEBUG */ static final SentryLevel DEFAULT_DIAGNOSTIC_LEVEL = SentryLevel.DEBUG; @@ -37,41 +37,12 @@ public class SentryOptions { */ private final @NotNull List integrations = new CopyOnWriteArrayList<>(); - /** - * The DSN tells the SDK where to send the events to. If this value is not provided, the SDK will - * just not send any events. - */ - private @Nullable String dsn; - - /** - * Controls how many seconds to wait before shutting down. Sentry SDKs send events from a - * background queue and this queue is given a certain amount to drain pending events Default is - * 2000 = 2s - */ - private long shutdownTimeoutMillis = 2000; // 2s - - /** - * Controls how many seconds to wait before flushing down. Sentry SDKs cache events from a - * background queue and this queue is given a certain amount to drain pending events Default is - * 15000 = 15s - */ - private long flushTimeoutMillis = 15000; // 15s - - /** - * Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging - * information if something goes wrong. Default is disabled. - */ - private boolean debug; - /** Turns NDK on or off. Default is enabled. */ private boolean enableNdk = true; /** Logger interface to log useful debugging information if debug is enabled */ private @NotNull ILogger logger = NoOpLogger.getInstance(); - /** minimum LogLevel to be used if debug is enabled */ - private @NotNull SentryLevel diagnosticLevel = DEFAULT_DIAGNOSTIC_LEVEL; - /** Serializer interface to serialize/deserialize json events */ private @NotNull ISerializer serializer = NoOpSerializer.getInstance(); @@ -107,47 +78,12 @@ public class SentryOptions { /** Max. queue size before flushing events/envelopes to the disk */ private int maxQueueSize = cacheDirSize + sessionsDirSize; - /** - * This variable controls the total amount of breadcrumbs that should be captured Default is 100 - */ - private int maxBreadcrumbs = 100; - - /** Sets the release. SDK will try to automatically configure a release out of the box */ - private @Nullable String release; - - /** - * Sets the environment. This string is freeform and not set by default. A release can be - * associated with more than one environment to separate them in the UI Think staging vs prod or - * similar. - */ - private @Nullable String environment; - /** * When set, a proxy can be configured that should be used for outbound requests. This is also * used for HTTPS requests */ private @Nullable Proxy proxy; - /** - * Configures the sample rate as a percentage of events to be sent in the range of 0.0 to 1.0. if - * 1.0 is set it means that 100% of events are sent. If set to 0.1 only 10% of events will be - * sent. Events are picked randomly. Default is null (disabled) - */ - private @Nullable Double sampleRate; - - /** - * A list of string prefixes of module names that do not belong to the app, but rather third-party - * packages. Modules considered not to be part of the app will be hidden from stack traces by - * default. - */ - private final @NotNull List inAppExcludes = new CopyOnWriteArrayList<>(); - - /** - * A list of string prefixes of module names that belong to the app. This option takes precedence - * over inAppExcludes. - */ - private final @NotNull List inAppIncludes = new CopyOnWriteArrayList<>(); - /** The transport is an internal construct of the client that abstracts away the event sending. */ private @NotNull ITransport transport = NoOpTransport.getInstance(); @@ -157,18 +93,6 @@ public class SentryOptions { */ private @NotNull ITransportGate transportGate = NoOpTransportGate.getInstance(); - /** Sets the distribution. Think about it together with release and environment */ - private @Nullable String dist; - - /** When enabled, threads are automatically attached to all logged events. */ - private boolean attachThreads = true; - - /** - * When enabled, stack traces are automatically attached to all threads logged. Stack traces are - * always attached to exceptions but when this is set stack traces are also sent with threads - */ - private boolean attachStacktrace; - /** Whether to enable automatic session tracking. */ private boolean enableSessionTracking; @@ -181,9 +105,6 @@ public class SentryOptions { /** The distinct Id (generated Guid) used for session tracking */ private String distinctId; - /** The server name used in the Sentry messages. */ - private String serverName; - /* When enabled, Sentry installs UncaughtExceptionHandlerIntegration. */ @@ -192,15 +113,6 @@ public class SentryOptions { /** Sentry Executor Service that sends cached events and envelopes on App. start. */ private @NotNull ISentryExecutorService executorService; - /** connection timeout in milliseconds. */ - private int connectionTimeoutMillis = 5000; - - /** read timeout in milliseconds */ - private int readTimeoutMillis = 5000; - - /** whether to ignore TLS errors */ - private boolean bypassSecurity = false; - /** Reads and caches event json files in the disk */ private @NotNull IEventCache eventDiskCache = NoOpEventCache.getInstance(); @@ -246,42 +158,6 @@ public void addIntegration(@NotNull Integration integration) { return integrations; } - /** - * Returns the DSN - * - * @return the DSN or null if not set - */ - public @Nullable String getDsn() { - return dsn; - } - - /** - * Sets the DSN - * - * @param dsn the DSN - */ - public void setDsn(@Nullable String dsn) { - this.dsn = dsn; - } - - /** - * Check if debug mode is ON Default is OFF - * - * @return true if ON or false otherwise - */ - public boolean isDebug() { - return debug; - } - - /** - * Sets the debug mode to ON or OFF Default is OFF - * - * @param debug true if ON or false otherwise - */ - public void setDebug(boolean debug) { - this.debug = debug; - } - /** * Returns the Logger interface * @@ -300,24 +176,6 @@ public void setLogger(final @Nullable ILogger logger) { this.logger = (logger == null) ? NoOpLogger.getInstance() : new DiagnosticLogger(this, logger); } - /** - * Returns the minimum LogLevel - * - * @return the log level - */ - public @NotNull SentryLevel getDiagnosticLevel() { - return diagnosticLevel; - } - - /** - * Sets the minimum LogLevel if null, it uses the default min. LogLevel Default is DEBUG - * - * @param diagnosticLevel the log level - */ - public void setDiagnosticLevel(@Nullable final SentryLevel diagnosticLevel) { - this.diagnosticLevel = (diagnosticLevel != null) ? diagnosticLevel : DEFAULT_DIAGNOSTIC_LEVEL; - } - /** * Returns the Serializer interface * @@ -363,24 +221,6 @@ public void setEnableNdk(boolean enableNdk) { this.enableNdk = enableNdk; } - /** - * Returns the shutdown timeout in Millis - * - * @return the timeout in Millis - */ - public long getShutdownTimeout() { - return shutdownTimeoutMillis; - } - - /** - * Sets the shutdown timeout in Millis Default is 2000 = 2s - * - * @param shutdownTimeoutMillis the shutdown timeout in millis - */ - public void setShutdownTimeout(long shutdownTimeoutMillis) { - this.shutdownTimeoutMillis = shutdownTimeoutMillis; - } - /** * Returns the Sentry client name * @@ -495,60 +335,6 @@ public void setCacheDirSize(int cacheDirSize) { this.cacheDirSize = cacheDirSize; } - /** - * Returns the max Breadcrumbs Default is 100 - * - * @return the max breadcrumbs - */ - public int getMaxBreadcrumbs() { - return maxBreadcrumbs; - } - - /** - * Sets the max breadcrumbs Default is 100 - * - * @param maxBreadcrumbs the max breadcrumbs - */ - public void setMaxBreadcrumbs(int maxBreadcrumbs) { - this.maxBreadcrumbs = maxBreadcrumbs; - } - - /** - * Returns the release - * - * @return the release or null if not set - */ - public @Nullable String getRelease() { - return release; - } - - /** - * Sets the release - * - * @param release the release - */ - public void setRelease(@Nullable String release) { - this.release = release; - } - - /** - * Returns the environment - * - * @return the environment or null if not set - */ - public @Nullable String getEnvironment() { - return environment; - } - - /** - * Sets the environment - * - * @param environment the environment - */ - public void setEnvironment(@Nullable String environment) { - this.environment = environment; - } - /** * Returns the proxy if set * @@ -567,66 +353,6 @@ public void setProxy(@Nullable Proxy proxy) { this.proxy = proxy; } - /** - * Returns the sample rate Default is null (disabled) - * - * @return the sample rate - */ - public @Nullable Double getSampleRate() { - return sampleRate; - } - - /** - * Sets the sampleRate Can be anything between 0.01 and 1.0 or null (default), to disable it. - * - * @param sampleRate the sample rate - */ - public void setSampleRate(Double sampleRate) { - if (sampleRate != null && (sampleRate > 1.0 || sampleRate <= 0.0)) { - throw new IllegalArgumentException( - "The value " - + sampleRate - + " is not valid. Use null to disable or values between 0.01 (inclusive) and 1.0 (exclusive)."); - } - this.sampleRate = sampleRate; - } - - /** - * the list of inApp excludes - * - * @return the inApp excludes list - */ - public @NotNull List getInAppExcludes() { - return inAppExcludes; - } - - /** - * Adds an inApp exclude - * - * @param exclude the inApp exclude module/package - */ - public void addInAppExclude(@NotNull String exclude) { - inAppExcludes.add(exclude); - } - - /** - * Returns the inApp includes list - * - * @return the inApp includes list - */ - public @NotNull List getInAppIncludes() { - return inAppIncludes; - } - - /** - * Adds an inApp include - * - * @param include the inApp include module/package - */ - public void addInAppInclude(@NotNull String include) { - inAppIncludes.add(include); - } - /** * Returns the Transport interface * @@ -645,24 +371,6 @@ public void setTransport(@Nullable ITransport transport) { this.transport = transport != null ? transport : NoOpTransport.getInstance(); } - /** - * Sets the distribution - * - * @return the distribution or null if not set - */ - public @Nullable String getDist() { - return dist; - } - - /** - * Sets the distribution - * - * @param dist the distribution - */ - public void setDist(@Nullable String dist) { - this.dist = dist; - } - /** * Returns the TransportGate interface * @@ -681,42 +389,6 @@ public void setTransportGate(@Nullable ITransportGate transportGate) { this.transportGate = (transportGate != null) ? transportGate : NoOpTransportGate.getInstance(); } - /** - * Checks if the AttachStacktrace is enabled or not - * - * @return true if enabled or false otherwise - */ - public boolean isAttachStacktrace() { - return attachStacktrace; - } - - /** - * Sets the attachStacktrace to enabled or disabled - * - * @param attachStacktrace true if enabled or false otherwise - */ - public void setAttachStacktrace(boolean attachStacktrace) { - this.attachStacktrace = attachStacktrace; - } - - /** - * Checks if the AttachThreads is enabled or not - * - * @return true if enabled or false otherwise - */ - public boolean isAttachThreads() { - return attachThreads; - } - - /** - * Sets the attachThreads to enabled or disabled - * - * @param attachThreads true if enabled or false otherwise - */ - public void setAttachThreads(boolean attachThreads) { - this.attachThreads = attachThreads; - } - /** * Returns if the automatic session tracking is enabled or not * @@ -735,24 +407,6 @@ public void setEnableSessionTracking(boolean enableSessionTracking) { this.enableSessionTracking = enableSessionTracking; } - /** - * Gets the default server name to be used in Sentry events. - * - * @return the default server name or null if none set - */ - public @Nullable String getServerName() { - return serverName; - } - - /** - * Sets the default server name to be used in Sentry events. - * - * @param serverName the default server name or null if none should be used - */ - public void setServerName(@Nullable String serverName) { - this.serverName = serverName; - } - /** * Returns the sessions dir size * @@ -809,24 +463,6 @@ public void setDistinctId(String distinctId) { this.distinctId = distinctId; } - /** - * Returns the flush timeout in millis - * - * @return the timeout in millis - */ - public long getFlushTimeoutMillis() { - return flushTimeoutMillis; - } - - /** - * Sets the flush timeout in millis - * - * @param flushTimeoutMillis the timeout in millis - */ - public void setFlushTimeoutMillis(long flushTimeoutMillis) { - this.flushTimeoutMillis = flushTimeoutMillis; - } - /** * Checks if the default UncaughtExceptionHandlerIntegration is enabled or not. * @@ -866,60 +502,6 @@ void setExecutorService(final @NotNull ISentryExecutorService executorService) { } } - /** - * Returns the connection timeout in milliseconds. - * - * @return the connectionTimeoutMillis - */ - public int getConnectionTimeoutMillis() { - return connectionTimeoutMillis; - } - - /** - * Sets the connection timeout in milliseconds. - * - * @param connectionTimeoutMillis the connectionTimeoutMillis - */ - public void setConnectionTimeoutMillis(int connectionTimeoutMillis) { - this.connectionTimeoutMillis = connectionTimeoutMillis; - } - - /** - * Returns the read timeout in milliseconds - * - * @return the readTimeoutMillis - */ - public int getReadTimeoutMillis() { - return readTimeoutMillis; - } - - /** - * Sets the read timeout in milliseconds - * - * @param readTimeoutMillis the readTimeoutMillis - */ - public void setReadTimeoutMillis(int readTimeoutMillis) { - this.readTimeoutMillis = readTimeoutMillis; - } - - /** - * Returns whether to ignore TLS errors - * - * @return the bypassSecurity - */ - public boolean isBypassSecurity() { - return bypassSecurity; - } - - /** - * Sets whether to ignore TLS errors - * - * @param bypassSecurity the bypassSecurity - */ - public void setBypassSecurity(boolean bypassSecurity) { - this.bypassSecurity = bypassSecurity; - } - /** * Returns the EventCache interface * diff --git a/sentry-core/src/test/java/io/sentry/core/SentryCommonOptionsTest.kt b/sentry-core/src/test/java/io/sentry/core/SentryBindableOptionsTest.kt similarity index 83% rename from sentry-core/src/test/java/io/sentry/core/SentryCommonOptionsTest.kt rename to sentry-core/src/test/java/io/sentry/core/SentryBindableOptionsTest.kt index 4300a6b2a..7636b4458 100644 --- a/sentry-core/src/test/java/io/sentry/core/SentryCommonOptionsTest.kt +++ b/sentry-core/src/test/java/io/sentry/core/SentryBindableOptionsTest.kt @@ -4,18 +4,18 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue -class SentryCommonOptionsTest { +class SentryBindableOptionsTest { @Test fun `applies properties to SentryOptions`() { - val commonOptions = with(SentryCommonOptions()) { + val commonOptions = with(SentryBindableOptions()) { dsn = "http://key@localhost/proj" readTimeoutMillis = 10 - shutdownTimeoutMillis = 20L + shutdownTimeout = 20L flushTimeoutMillis = 30 - bypassSecurity = true - debug = true - diagnosticLevel = SentryLevel.INFO + isBypassSecurity = true + isDebug = true + setDiagnosticLevel(SentryLevel.INFO) maxBreadcrumbs = 100 release = "1.0.3" environment = "production" @@ -23,8 +23,8 @@ class SentryCommonOptionsTest { inAppExcludes = listOf("org.springframework") inAppIncludes = listOf("com.myapp") dist = "my-dist" - attachStacktrace = true - attachThreads = true + isAttachStacktrace = true + isAttachThreads = true serverName = "host-001" this } diff --git a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java index cd22c70a7..d08ad1ee8 100644 --- a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java +++ b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java @@ -6,7 +6,6 @@ import ch.qos.logback.core.UnsynchronizedAppenderBase; import io.sentry.core.DateUtils; import io.sentry.core.Sentry; -import io.sentry.core.SentryCommonOptions; import io.sentry.core.SentryEvent; import io.sentry.core.SentryLevel; import io.sentry.core.SentryOptions; @@ -28,19 +27,16 @@ /** Appender for logback in charge of sending the logged events to a Sentry server. */ public final class SentryAppender extends UnsynchronizedAppenderBase { - private @Nullable SentryCommonOptions options; + private @Nullable SentryOptions options; private @Nullable ITransport transport; @Override public void start() { if (options != null && options.getDsn() != null) { - Sentry.init( - sentryOptions -> { - options.applyTo(sentryOptions); - sentryOptions.setSentryClientName(BuildConfig.SENTRY_LOGBACK_SDK_NAME); - sentryOptions.setSdkVersion(createSdkVersion(sentryOptions)); - Optional.ofNullable(transport).ifPresent(sentryOptions::setTransport); - }); + options.setSentryClientName(BuildConfig.SENTRY_LOGBACK_SDK_NAME); + options.setSdkVersion(createSdkVersion(options)); + Optional.ofNullable(transport).ifPresent(options::setTransport); + Sentry.init(options); } super.start(); } @@ -130,7 +126,7 @@ protected void append(@NotNull ILoggingEvent eventObject) { return sdkVersion; } - public void setOptions(@Nullable SentryCommonOptions options) { + public void setOptions(@Nullable SentryOptions options) { this.options = options; } diff --git a/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt b/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt index e3934ed2c..262e4b3d9 100644 --- a/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt +++ b/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt @@ -7,9 +7,9 @@ import com.nhaarman.mockitokotlin2.check import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import io.sentry.core.SentryCommonOptions import io.sentry.core.SentryEvent import io.sentry.core.SentryLevel +import io.sentry.core.SentryOptions import io.sentry.core.transport.ITransport import io.sentry.core.transport.TransportResult import java.time.Instant @@ -37,7 +37,7 @@ class SentryAppenderTest { whenever(transport.send(any())).thenReturn(TransportResult.success()) val appender = SentryAppender() - val options = SentryCommonOptions() + val options = SentryOptions() options.dsn = "http://key@localhost/proj" appender.setOptions(options) appender.context = loggerContext diff --git a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java index 57820d14b..ee047bb81 100644 --- a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java +++ b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java @@ -30,7 +30,7 @@ public class SentryAutoConfiguration { /** Registers general purpose Sentry related beans. */ @Configuration @ConditionalOnProperty("sentry.dsn") - @EnableConfigurationProperties(SentryProperties.class) + @EnableConfigurationProperties(SentrySpringProperties.class) @Open static class HubConfiguration { @@ -57,7 +57,7 @@ static class HubConfiguration { @Bean public @NotNull SentryOptions sentryOptions( final @NotNull Sentry.OptionsConfiguration optionsConfiguration, - final @NotNull SentryProperties properties, + final @NotNull SentrySpringProperties properties, final @NotNull ObjectProvider gitProperties) { final SentryOptions options = new SentryOptions(); optionsConfiguration.configure(options); diff --git a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentrySpringProperties.java similarity index 87% rename from sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java rename to sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentrySpringProperties.java index 206d3e8ea..148148000 100644 --- a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java +++ b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentrySpringProperties.java @@ -1,13 +1,13 @@ package io.sentry.spring.boot; import com.jakewharton.nopen.annotation.Open; -import io.sentry.core.SentryCommonOptions; +import io.sentry.core.SentryBindableOptions; import org.springframework.boot.context.properties.ConfigurationProperties; /** Configuration for Sentry integration. */ @ConfigurationProperties(prefix = "sentry") @Open -public class SentryProperties extends SentryCommonOptions { +public class SentrySpringProperties extends SentryBindableOptions { /** Whether Sentry integration should be enabled. */ private boolean enabled = true; diff --git a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index 7009bb58d..7d02af063 100644 --- a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -87,7 +87,7 @@ class SentryAutoConfigurationTest { contextRunner.withPropertyValues( "sentry.dsn=http://key@localhost/proj", "sentry.read-timeout-millis=10", - "sentry.shutdown-timeout-millis=20", + "sentry.shutdown-timeout=20", "sentry.flush-timeout-millis=30", "sentry.bypass-security=true", "sentry.debug=true",