Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.core.env.MapPropertySource
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.scheduling.quartz.SchedulerFactoryBean
Expand Down Expand Up @@ -263,6 +264,7 @@ class SentryAutoConfigurationTest {
"sentry.ignored-checkins=slug1,slugB",
"sentry.ignored-errors=Some error,Another .*",
"sentry.ignored-transactions=transactionName1,transactionNameB",
"sentry.trace-ignore-status-codes=404,500-599",
"sentry.enable-backpressure-handling=false",
"sentry.enable-database-transaction-tracing=true",
"sentry.enable-cache-tracing=true",
Expand Down Expand Up @@ -316,6 +318,10 @@ class SentryAutoConfigurationTest {
assertThat(options.ignoredCheckIns).containsOnly("slug1", "slugB")
assertThat(options.ignoredErrors).containsOnly("Some error", "Another .*")
assertThat(options.ignoredTransactions).containsOnly("transactionName1", "transactionNameB")
assertThat(options.traceIgnoreStatusCodes).hasSize(2)
assertThat(options.traceIgnoreStatusCodes!![0].isInRange(404)).isTrue()
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(500)).isTrue()
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(599)).isTrue()
assertThat(options.isEnableBackpressureHandling).isEqualTo(false)
assertThat(options.isEnableDatabaseTransactionTracing).isEqualTo(true)
assertThat(options.isEnableCacheTracing).isEqualTo(true)
Expand All @@ -336,6 +342,42 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `YAML list binds integer ignored server HTTP status codes`() {
dsnEnabledRunner
.withInitializer { context ->
// YAML exposes unquoted numbers as Integer values in indexed property sources.
context.environment.propertySources.addFirst(
MapPropertySource(
"yaml",
mapOf<String, Any>(
"sentry.trace-ignore-status-codes[0]" to 404,
"sentry.trace-ignore-status-codes[1]" to "500-599",
),
)
)
}
.run {
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
assertThat(ranges).hasSize(2)
assertThat(ranges!![0].isInRange(404)).isTrue()
assertThat(ranges[1].isInRange(500)).isTrue()
assertThat(ranges[1].isInRange(599)).isTrue()
}
}

@Test
fun `empty ignored server HTTP status codes disable the configuration`() {
contextRunner
.withPropertyValues(
"sentry.dsn=http://key@localhost/proj",
"sentry.trace-ignore-status-codes=",
)
.run {
assertThat(it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes).isEmpty()
}
}

@Test
fun `data collection properties are applied to SentryOptions`() {
contextRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.core.env.MapPropertySource
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.scheduling.quartz.SchedulerFactoryBean
Expand Down Expand Up @@ -266,6 +267,7 @@ class SentryAutoConfigurationTest {
"sentry.ignored-checkins=slug1,slugB",
"sentry.ignored-errors=Some error,Another .*",
"sentry.ignored-transactions=transactionName1,transactionNameB",
"sentry.trace-ignore-status-codes=404,500-599",
"sentry.enable-backpressure-handling=false",
"sentry.enable-database-transaction-tracing=true",
"sentry.enable-spotlight=true",
Expand Down Expand Up @@ -321,6 +323,10 @@ class SentryAutoConfigurationTest {
assertThat(options.ignoredCheckIns).containsOnly("slug1", "slugB")
assertThat(options.ignoredErrors).containsOnly("Some error", "Another .*")
assertThat(options.ignoredTransactions).containsOnly("transactionName1", "transactionNameB")
assertThat(options.traceIgnoreStatusCodes).hasSize(2)
assertThat(options.traceIgnoreStatusCodes!![0].isInRange(404)).isTrue()
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(500)).isTrue()
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(599)).isTrue()
assertThat(options.isEnableBackpressureHandling).isEqualTo(false)
assertThat(options.isEnableDatabaseTransactionTracing).isEqualTo(true)
assertThat(options.isForceInit).isEqualTo(true)
Expand All @@ -344,6 +350,42 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `YAML list binds integer ignored server HTTP status codes`() {
dsnEnabledRunner
.withInitializer { context ->
// YAML exposes unquoted numbers as Integer values in indexed property sources.
context.environment.propertySources.addFirst(
MapPropertySource(
"yaml",
mapOf<String, Any>(
"sentry.trace-ignore-status-codes[0]" to 404,
"sentry.trace-ignore-status-codes[1]" to "500-599",
),
)
)
}
.run {
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
assertThat(ranges).hasSize(2)
assertThat(ranges!![0].isInRange(404)).isTrue()
assertThat(ranges[1].isInRange(500)).isTrue()
assertThat(ranges[1].isInRange(599)).isTrue()
}
}

@Test
fun `empty ignored server HTTP status codes disable the configuration`() {
contextRunner
.withPropertyValues(
"sentry.dsn=http://key@localhost/proj",
"sentry.trace-ignore-status-codes=",
)
.run {
assertThat(it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes).isEmpty()
}
}

@Test
fun `data collection properties are applied to SentryOptions`() {
contextRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.core.env.MapPropertySource
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.scheduling.quartz.SchedulerFactoryBean
Expand Down Expand Up @@ -264,6 +265,7 @@ class SentryAutoConfigurationTest {
"sentry.ignored-checkins=slug1,slugB",
"sentry.ignored-errors=Some error,Another .*",
"sentry.ignored-transactions=transactionName1,transactionNameB",
"sentry.trace-ignore-status-codes=404,500-599",
"sentry.enable-backpressure-handling=false",
"sentry.enable-database-transaction-tracing=true",
"sentry.enable-spotlight=true",
Expand Down Expand Up @@ -319,6 +321,10 @@ class SentryAutoConfigurationTest {
assertThat(options.ignoredCheckIns).containsOnly("slug1", "slugB")
assertThat(options.ignoredErrors).containsOnly("Some error", "Another .*")
assertThat(options.ignoredTransactions).containsOnly("transactionName1", "transactionNameB")
assertThat(options.traceIgnoreStatusCodes).hasSize(2)
assertThat(options.traceIgnoreStatusCodes!![0].isInRange(404)).isTrue()
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(500)).isTrue()
assertThat(options.traceIgnoreStatusCodes!![1].isInRange(599)).isTrue()
assertThat(options.isEnableBackpressureHandling).isEqualTo(false)
assertThat(options.isEnableDatabaseTransactionTracing).isEqualTo(true)
assertThat(options.isForceInit).isEqualTo(true)
Expand All @@ -342,6 +348,42 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `YAML list binds integer ignored server HTTP status codes`() {
dsnEnabledRunner
.withInitializer { context ->
// YAML exposes unquoted numbers as Integer values in indexed property sources.
context.environment.propertySources.addFirst(
MapPropertySource(
"yaml",
mapOf<String, Any>(
"sentry.trace-ignore-status-codes[0]" to 404,
"sentry.trace-ignore-status-codes[1]" to "500-599",
),
)
)
}
.run {
val ranges = it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes
assertThat(ranges).hasSize(2)
assertThat(ranges!![0].isInRange(404)).isTrue()
assertThat(ranges[1].isInRange(500)).isTrue()
assertThat(ranges[1].isInRange(599)).isTrue()
}
}

@Test
fun `empty ignored server HTTP status codes disable the configuration`() {
contextRunner
.withPropertyValues(
"sentry.dsn=http://key@localhost/proj",
"sentry.trace-ignore-status-codes=",
)
.run {
assertThat(it.getBean(SentryProperties::class.java).traceIgnoreStatusCodes).isEmpty()
}
}

@Test
fun `data collection properties are applied to SentryOptions`() {
contextRunner
Expand Down
6 changes: 6 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ public final class io/sentry/ExternalOptions {
public fun getShutdownTimeoutMillis ()Ljava/lang/Long;
public fun getSpotlightConnectionUrl ()Ljava/lang/String;
public fun getTags ()Ljava/util/Map;
public fun getTraceIgnoreStatusCodes ()Ljava/util/List;
public fun getTracePropagationTargets ()Ljava/util/List;
public fun getTracesSampleRate ()Ljava/lang/Double;
public fun isCaptureOpenTelemetryEvents ()Ljava/lang/Boolean;
Expand Down Expand Up @@ -644,6 +645,7 @@ public final class io/sentry/ExternalOptions {
public fun setSpotlightConnectionUrl (Ljava/lang/String;)V
public fun setStrictTraceContinuation (Ljava/lang/Boolean;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTraceIgnoreStatusCodes (Ljava/util/List;)V
public fun setTracesSampleRate (Ljava/lang/Double;)V
}

Expand Down Expand Up @@ -710,6 +712,8 @@ public final class io/sentry/HttpStatusCodeRange {
public fun <init> (I)V
public fun <init> (II)V
public fun isInRange (I)Z
public static fun valueOf (Ljava/lang/Integer;)Lio/sentry/HttpStatusCodeRange;
public static fun valueOf (Ljava/lang/String;)Lio/sentry/HttpStatusCodeRange;
}

public abstract interface class io/sentry/IAppStartExtender {
Expand Down Expand Up @@ -3616,6 +3620,7 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig {
public fun getTags ()Ljava/util/Map;
public fun getThreadChecker ()Lio/sentry/util/thread/IThreadChecker;
public fun getTimerExecutorService ()Lio/sentry/ISentryExecutorService;
public fun getTraceIgnoreStatusCodes ()Ljava/util/List;
public fun getTracePropagationTargets ()Ljava/util/List;
public fun getTracesSampleRate ()Ljava/lang/Double;
public fun getTracesSampler ()Lio/sentry/SentryOptions$TracesSamplerCallback;
Expand Down Expand Up @@ -3785,6 +3790,7 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig {
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setThreadChecker (Lio/sentry/util/thread/IThreadChecker;)V
public fun setTimerExecutorService (Lio/sentry/ISentryExecutorService;)V
public fun setTraceIgnoreStatusCodes (Ljava/util/List;)V
public fun setTraceOptionsRequests (Z)V
public fun setTracePropagationTargets (Ljava/util/List;)V
public fun setTraceSampling (Z)V
Expand Down
35 changes: 35 additions & 0 deletions sentry/src/main/java/io/sentry/ExternalOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class ExternalOptions {

private @Nullable List<String> ignoredCheckIns;
private @Nullable List<String> ignoredTransactions;
private @Nullable List<HttpStatusCodeRange> traceIgnoreStatusCodes;

private @Nullable Boolean sendModules;
private @Nullable Boolean sendDefaultPii;
Expand Down Expand Up @@ -160,6 +161,7 @@ public final class ExternalOptions {

options.setIgnoredCheckIns(propertiesProvider.getListOrNull("ignored-checkins"));
options.setIgnoredTransactions(propertiesProvider.getListOrNull("ignored-transactions"));
options.setTraceIgnoreStatusCodes(parseTraceIgnoreStatusCodes(propertiesProvider, logger));

options.setEnableBackpressureHandling(
propertiesProvider.getBooleanProperty("enable-backpressure-handling"));
Expand Down Expand Up @@ -243,6 +245,30 @@ public final class ExternalOptions {
return options;
}

private static @Nullable List<HttpStatusCodeRange> parseTraceIgnoreStatusCodes(
final @NotNull PropertiesProvider propertiesProvider, final @NotNull ILogger logger) {
final String value = propertiesProvider.getProperty("trace-ignore-status-codes");
if (value == null) {
return null;
}
if (value.trim().isEmpty()) {
return new ArrayList<>();
}

final List<HttpStatusCodeRange> ranges = new ArrayList<>();
for (final String token : value.split(",", -1)) {
try {
ranges.add(HttpStatusCodeRange.valueOf(token));
} catch (IllegalArgumentException e) {
logger.log(
SentryLevel.WARNING,
"Ignoring invalid HTTP status code range in trace-ignore-status-codes: %s",
token);
}
}
return ranges.isEmpty() ? null : ranges;
}

private static @Nullable DataCollection parseDataCollection(
final @NotNull PropertiesProvider propertiesProvider) {
final DataCollection dataCollection = new DataCollection();
Expand Down Expand Up @@ -622,6 +648,15 @@ public void setIgnoredTransactions(final @Nullable List<String> ignoredTransacti
return ignoredTransactions;
}

public void setTraceIgnoreStatusCodes(
final @Nullable List<HttpStatusCodeRange> traceIgnoreStatusCodes) {
this.traceIgnoreStatusCodes = traceIgnoreStatusCodes;
}

public @Nullable List<HttpStatusCodeRange> getTraceIgnoreStatusCodes() {
return traceIgnoreStatusCodes;
}

public void setEnableBackpressureHandling(final @Nullable Boolean enableBackpressureHandling) {
this.enableBackpressureHandling = enableBackpressureHandling;
}
Expand Down
Loading
Loading