Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Drop reflection, bind to SentryOptions in Logback integration.
  • Loading branch information
maciejwalkowiak committed Aug 28, 2020
commit ff1e1d50f6ed955468c2c056793019fc348e378f
38 changes: 36 additions & 2 deletions sentry-core/src/main/java/io/sentry/core/SentryCommonOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static io.sentry.core.SentryOptions.DEFAULT_DIAGNOSTIC_LEVEL;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.core.util.ReflectionUtils;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -107,7 +106,42 @@ public class SentryCommonOptions {
* @param options the instance of {@link SentryOptions} to apply the configuration to
*/
public void applyTo(SentryOptions options) {
ReflectionUtils.copyNonNullFields(this, 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);
}

/**
Expand Down
63 changes: 0 additions & 63 deletions sentry-core/src/main/java/io/sentry/core/util/ReflectionUtils.java

This file was deleted.

16 changes: 6 additions & 10 deletions sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,19 +27,16 @@

/** Appender for logback in charge of sending the logged events to a Sentry server. */
public final class SentryAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
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();
}
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,7 +37,7 @@ class SentryAppenderTest {
whenever(transport.send(any<SentryEvent>())).thenReturn(TransportResult.success())

val appender = SentryAppender()
val options = SentryCommonOptions()
val options = SentryOptions()
options.dsn = "http://key@localhost/proj"
appender.setOptions(options)
appender.context = loggerContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -57,7 +57,7 @@ static class HubConfiguration {
@Bean
public @NotNull SentryOptions sentryOptions(
final @NotNull Sentry.OptionsConfiguration<SentryOptions> optionsConfiguration,
final @NotNull SentryProperties properties,
final @NotNull SentrySpringProperties properties,
final @NotNull ObjectProvider<GitProperties> gitProperties) {
final SentryOptions options = new SentryOptions();
optionsConfiguration.configure(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/** Configuration for Sentry integration. */
@ConfigurationProperties(prefix = "sentry")
@Open
public class SentryProperties extends SentryCommonOptions {
public class SentrySpringProperties extends SentryCommonOptions {
/** Whether Sentry integration should be enabled. */
private boolean enabled = true;

Expand Down