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 @@ -232,59 +232,39 @@ private void mergeOS(final @NotNull SentryBaseEvent event) {
}

private void setDevice(final @NotNull SentryLogEvent event) {
try {
event.setAttribute(
"device.brand",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND));
event.setAttribute(
"device.model",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL));
event.setAttribute(
"device.family",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue()));
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve device info", e);
}
event.setAttribute(
"device.brand", new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND));
event.setAttribute(
"device.model", new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL));
event.setAttribute(
"device.family",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue()));
}

private void setOs(final @NotNull SentryLogEvent event) {
try {
event.setAttribute(
"os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android"));
event.setAttribute(
"os.version",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE));
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve os system", e);
}
event.setAttribute(
"os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android"));
event.setAttribute(
"os.version",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE));
}

private void setDevice(final @NotNull SentryMetricsEvent event) {
try {
event.setAttribute(
"device.brand",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND));
event.setAttribute(
"device.model",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL));
event.setAttribute(
"device.family",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue()));
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve device info", e);
}
event.setAttribute(
"device.brand", new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND));
event.setAttribute(
"device.model", new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL));
event.setAttribute(
"device.family",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue()));
}

private void setOs(final @NotNull SentryMetricsEvent event) {
try {
event.setAttribute(
"os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android"));
event.setAttribute(
"os.version",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE));
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve os system", e);
}
event.setAttribute(
"os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android"));
event.setAttribute(
"os.version",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE));
}

// Data to be applied to events that was created in the running process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,35 +369,21 @@ private Device.DeviceOrientation getOrientation() {
*
* @return the total amount of internal storage, in bytes
*/
@Nullable
private Long getTotalInternalStorage(final @NotNull StatFs stat) {
try {
long blockSize = stat.getBlockSizeLong();
long totalBlocks = stat.getBlockCountLong();
return totalBlocks * blockSize;
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error getting total internal storage amount.", e);
return null;
}
private long getTotalInternalStorage(final @NotNull StatFs stat) {
long blockSize = stat.getBlockSizeLong();
long totalBlocks = stat.getBlockCountLong();
return totalBlocks * blockSize;
}

/**
* Get the unused amount of internal storage, in bytes.
*
* @return the unused amount of internal storage, in bytes
*/
@Nullable
private Long getUnusedInternalStorage(final @NotNull StatFs stat) {
try {
long blockSize = stat.getBlockSizeLong();
long availableBlocks = stat.getAvailableBlocksLong();
return availableBlocks * blockSize;
} catch (Throwable e) {
options
.getLogger()
.log(SentryLevel.ERROR, "Error getting unused internal storage amount.", e);
return null;
}
private long getUnusedInternalStorage(final @NotNull StatFs stat) {
long blockSize = stat.getBlockSizeLong();
long availableBlocks = stat.getAvailableBlocksLong();
return availableBlocks * blockSize;
}

@Nullable
Expand Down Expand Up @@ -449,16 +435,10 @@ private File getExternalStorageDep(final @Nullable File internalStorage) {
* @return the total amount of external storage, in bytes, or null if no external storage is
* mounted
*/
@Nullable
private Long getTotalExternalStorage(final @NotNull StatFs stat) {
try {
final long blockSize = stat.getBlockSizeLong();
final long totalBlocks = stat.getBlockCountLong();
return totalBlocks * blockSize;
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error getting total external storage amount.", e);
return null;
}
private long getTotalExternalStorage(final @NotNull StatFs stat) {
final long blockSize = stat.getBlockSizeLong();
final long totalBlocks = stat.getBlockCountLong();
return totalBlocks * blockSize;
}

/**
Expand All @@ -467,18 +447,10 @@ private Long getTotalExternalStorage(final @NotNull StatFs stat) {
* @return the unused amount of external storage, in bytes, or null if no external storage is
* mounted
*/
@Nullable
private Long getUnusedExternalStorage(final @NotNull StatFs stat) {
try {
final long blockSize = stat.getBlockSizeLong();
final long availableBlocks = stat.getAvailableBlocksLong();
return availableBlocks * blockSize;
} catch (Throwable e) {
options
.getLogger()
.log(SentryLevel.ERROR, "Error getting unused external storage amount.", e);
return null;
}
private long getUnusedExternalStorage(final @NotNull StatFs stat) {
final long blockSize = stat.getBlockSizeLong();
final long availableBlocks = stat.getAvailableBlocksLong();
return availableBlocks * blockSize;
}

@Nullable
Expand Down
16 changes: 5 additions & 11 deletions sentry-jdbc/src/main/java/io/sentry/jdbc/DatabaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,11 @@ public static DatabaseDetails parse(final @Nullable String databaseConnectionUrl
return parseAsUri(dbSystem, urlString);
}
if ("sqlserver".equalsIgnoreCase(dbSystem)) {
try {
String dbProperty = ";databasename=";
final int index = urlString.indexOf(dbProperty);
if (index >= 0) {
final @NotNull String dbNameAndMaybeMore =
urlString.substring(index + dbProperty.length());
return new DatabaseDetails(
dbSystem, StringUtils.substringBefore(dbNameAndMaybeMore, ";"));
}
} catch (Throwable t) {
// ignore
String dbProperty = ";databasename=";
final int index = urlString.indexOf(dbProperty);
if (index >= 0) {
final @NotNull String dbNameAndMaybeMore = urlString.substring(index + dbProperty.length());
return new DatabaseDetails(dbSystem, StringUtils.substringBefore(dbNameAndMaybeMore, ";"));
}
}
if ("oracle".equalsIgnoreCase(dbSystem)) {
Expand Down
81 changes: 37 additions & 44 deletions sentry/src/main/java/io/sentry/Baggage.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,53 +112,46 @@ public static Baggage fromHeader(
@Nullable Double sampleRand = null;

if (headerValue != null) {
try {
// see https://errorprone.info/bugpattern/StringSplitter for why limit is passed
final String[] keyValueStrings = headerValue.split(",", -1);
for (final String keyValueString : keyValueStrings) {
if (keyValueString.trim().startsWith(SENTRY_BAGGAGE_PREFIX)) {
try {
// As per spec (https://www.w3.org/TR/baggage/#value)
// a value may contain "=" signs, thus we split by the first occurrence
final int separatorIndex = keyValueString.indexOf("=");
final String key = keyValueString.substring(0, separatorIndex).trim();
final String keyDecoded = decode(key);
final String value = keyValueString.substring(separatorIndex + 1).trim();
final String valueDecoded = decode(value);

if (DSCKeys.SAMPLE_RATE.equals(keyDecoded)) {
sampleRate = toDouble(valueDecoded);
} else if (DSCKeys.SAMPLE_RAND.equals(keyDecoded)) {
sampleRand = toDouble(valueDecoded);
} else {
keyValues.put(keyDecoded, valueDecoded);
}
// Without ignoring SAMPLE_RAND here, we'd be freezing baggage that we're transporting
// via OTel span attributes.
// This is done when a transaction is created via Sentry API.
// In that case Baggage is created before the OTel span is created and we put it on
// the span attributes.
// It does however only contain the sample random value as its only value.
// The OTel code then uses it to create a propagation context from it and ends up
// freezing it,
// preventing outgoing requests (to other systems or Sentry) from adding info to
// baggage and only then freeze it.
if (!DSCKeys.SAMPLE_RAND.equalsIgnoreCase(key)) {
shouldFreeze = true;
}
} catch (Throwable e) {
logger.log(
SentryLevel.ERROR,
e,
"Unable to decode baggage key value pair %s",
keyValueString);
// see https://errorprone.info/bugpattern/StringSplitter for why limit is passed
final String[] keyValueStrings = headerValue.split(",", -1);
for (final String keyValueString : keyValueStrings) {
if (keyValueString.trim().startsWith(SENTRY_BAGGAGE_PREFIX)) {
try {
// As per spec (https://www.w3.org/TR/baggage/#value)
// a value may contain "=" signs, thus we split by the first occurrence
final int separatorIndex = keyValueString.indexOf("=");
final String key = keyValueString.substring(0, separatorIndex).trim();
final String keyDecoded = decode(key);
final String value = keyValueString.substring(separatorIndex + 1).trim();
final String valueDecoded = decode(value);

if (DSCKeys.SAMPLE_RATE.equals(keyDecoded)) {
sampleRate = toDouble(valueDecoded);
} else if (DSCKeys.SAMPLE_RAND.equals(keyDecoded)) {
sampleRand = toDouble(valueDecoded);
} else {
keyValues.put(keyDecoded, valueDecoded);
}
// Without ignoring SAMPLE_RAND here, we'd be freezing baggage that we're transporting
// via OTel span attributes.
// This is done when a transaction is created via Sentry API.
// In that case Baggage is created before the OTel span is created and we put it on
// the span attributes.
// It does however only contain the sample random value as its only value.
// The OTel code then uses it to create a propagation context from it and ends up
// freezing it,
// preventing outgoing requests (to other systems or Sentry) from adding info to
// baggage and only then freeze it.
if (!DSCKeys.SAMPLE_RAND.equalsIgnoreCase(key)) {
shouldFreeze = true;
}
} else if (includeThirdPartyValues) {
thirdPartyKeyValueStrings.add(keyValueString.trim());
} catch (Throwable e) {
logger.log(
SentryLevel.ERROR, e, "Unable to decode baggage key value pair %s", keyValueString);
}
} else if (includeThirdPartyValues) {
thirdPartyKeyValueStrings.add(keyValueString.trim());
}
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, e, "Unable to decode baggage header %s", headerValue);
}
}
final String thirdPartyHeader =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ private void sendCachedEnvelopes(
SentryLevel.ERROR,
"Failed to call the executor. Cached events will not be sent. Did you call Sentry.close()?",
e);
} catch (Throwable e) {
options
.getLogger()
.log(SentryLevel.ERROR, "Failed to call the executor. Cached events will not be sent", e);
}
}
}
8 changes: 2 additions & 6 deletions sentry/src/main/java/io/sentry/util/CheckInUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ public static boolean isIgnored(
}

for (final FilterString ignoredSlug : ignoredSlugs) {
try {
if (ignoredSlug.matches(slug)) {
return true;
}
} catch (Throwable t) {
// ignore invalid regex
if (ignoredSlug.matches(slug)) {
return true;
}
}

Expand Down
10 changes: 3 additions & 7 deletions sentry/src/main/java/io/sentry/util/SpanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,9 @@ public static boolean isIgnored(
}

for (final FilterString ignoredOrigin : ignoredOrigins) {
try {
if (ignoredOrigin.matches(origin)) {
ignoredSpanDecisionsCache.put(origin, true);
return true;
}
} catch (Throwable t) {
// ignore invalid regex
if (ignoredOrigin.matches(origin)) {
ignoredSpanDecisionsCache.put(origin, true);
return true;
}
}

Expand Down
2 changes: 0 additions & 2 deletions sentry/src/main/java/io/sentry/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ private StringUtils() {}
// For specifying wrong message digest algorithms
catch (NoSuchAlgorithmException e) {
logger.log(SentryLevel.INFO, "SHA-1 isn't available to calculate the hash.", e);
} catch (Throwable e) {
logger.log(SentryLevel.INFO, "string: %s could not calculate its hash", e, str);
}
return null;
}
Expand Down
9 changes: 2 additions & 7 deletions sentry/src/main/java/io/sentry/util/TracingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,8 @@ public static boolean isIgnored(
}

for (final FilterString ignoredTransaction : ignoredTransactions) {

try {
if (ignoredTransaction.matches(transactionName)) {
return true;
}
} catch (Throwable t) {
// ignore invalid regex
if (ignoredTransaction.matches(transactionName)) {
return true;
}
}

Expand Down
Loading