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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

## Unreleased

### Performance

- Most SDK log calls no longer allocate when `debug` is off ([#6600](https://github.com/getsentry/sentry-java/pull/6600))

### Fixes

- Android: Count deep sleep in breadcrumb, screenshot and view hierarchy debounce windows, so the first low-memory or battery breadcrumb after a long Doze is no longer dropped ([#6590](https://github.com/getsentry/sentry-java/pull/6590))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public boolean onScroll(
} else {
options
.getLogger()
.log(SentryLevel.DEBUG, "Scroll target found: " + target.getIdentifier());
.log(SentryLevel.DEBUG, "Scroll target found: %s", target.getIdentifier());
}

scrollState.setTarget(target);
Expand Down Expand Up @@ -226,9 +226,8 @@ private void startTracing(final @NotNull UiElement target, final @NotNull Gestur
.getLogger()
.log(
SentryLevel.DEBUG,
"The view with id: "
+ viewIdentifier
+ " already has an ongoing transaction assigned. Rescheduling finish");
"The view with id: %s already has an ongoing transaction assigned. Rescheduling finish",
viewIdentifier);

final Long idleTimeout = options.getIdleTimeout();
if (idleTimeout != null) {
Expand Down Expand Up @@ -351,23 +350,23 @@ void applyScope(final @NotNull IScope scope, final @NotNull ITransaction transac
if (activity == null) {
options
.getLogger()
.log(SentryLevel.DEBUG, "Activity is null in " + caller + ". No breadcrumb captured.");
.log(SentryLevel.DEBUG, "Activity is null in %s. No breadcrumb captured.", caller);
return null;
}

final Window window = activity.getWindow();
if (window == null) {
options
.getLogger()
.log(SentryLevel.DEBUG, "Window is null in " + caller + ". No breadcrumb captured.");
.log(SentryLevel.DEBUG, "Window is null in %s. No breadcrumb captured.", caller);
return null;
}

final View decorView = window.peekDecorView();
if (decorView == null) {
options
.getLogger()
.log(SentryLevel.DEBUG, "DecorView is null in " + caller + ". No breadcrumb captured.");
.log(SentryLevel.DEBUG, "DecorView is null in %s. No breadcrumb captured.", caller);
return null;
}
return decorView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.junit.Rule
import org.junit.rules.TemporaryFolder
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.anyVararg
import org.mockito.kotlin.argThat
import org.mockito.kotlin.atMost
import org.mockito.kotlin.check
Expand Down Expand Up @@ -172,7 +171,7 @@ abstract class ApplicationExitIntegrationTestBase<THint : Any> {

verify(fixture.scopes).captureEvent(any(), anyOrNull<Hint>())
verify(fixture.logger, never())
.log(any(), argThat { startsWith(config.flushLogPrefix) }, anyVararg<Any>())
.log(any(), argThat { startsWith(config.flushLogPrefix) }, any<Any>(), any<Any>())
}

@Test
Expand All @@ -185,7 +184,7 @@ abstract class ApplicationExitIntegrationTestBase<THint : Any> {

verify(fixture.scopes).captureEvent(any(), anyOrNull<Hint>())
verify(fixture.logger, never())
.log(any(), argThat { startsWith(config.flushLogPrefix) }, anyVararg<Any>())
.log(any(), argThat { startsWith(config.flushLogPrefix) }, any<Any>(), any<Any>())
}

@Test
Expand Down Expand Up @@ -317,7 +316,6 @@ abstract class ApplicationExitIntegrationTestBase<THint : Any> {
.log(
any(),
argThat { startsWith("Timed out waiting to flush previous session to its own file.") },
anyVararg<Any>(),
)
}

Expand All @@ -338,7 +336,6 @@ abstract class ApplicationExitIntegrationTestBase<THint : Any> {
.log(
any(),
argThat { startsWith("Timed out waiting to flush previous session to its own file.") },
anyVararg<Any>(),
)
verify(fixture.scopes).captureEvent(any(), any<Hint>())
}
Expand All @@ -355,7 +352,6 @@ abstract class ApplicationExitIntegrationTestBase<THint : Any> {
.log(
any(),
argThat { startsWith("Timed out waiting to flush previous session to its own file.") },
anyVararg<Any>(),
)
assertTrue((fixture.options.envelopeDiskCache as EnvelopeCache).waitPreviousSessionFlush())
}
Expand Down
9 changes: 9 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ public final class io/sentry/DiagnosticLogger : io/sentry/ILogger {
public fun <init> (Lio/sentry/SentryOptions;Lio/sentry/ILogger;)V
public fun getLogger ()Lio/sentry/ILogger;
public fun isEnabled (Lio/sentry/SentryLevel;)Z
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Throwable;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/Throwable;Ljava/lang/String;[Ljava/lang/Object;)V
Expand Down Expand Up @@ -944,6 +947,9 @@ public abstract interface class io/sentry/IHub : io/sentry/IScopes {

public abstract interface class io/sentry/ILogger {
public abstract fun isEnabled (Lio/sentry/SentryLevel;)Z
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Throwable;)V
public abstract fun log (Lio/sentry/SentryLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLevel;Ljava/lang/Throwable;Ljava/lang/String;[Ljava/lang/Object;)V
Expand Down Expand Up @@ -1804,6 +1810,9 @@ public final class io/sentry/NoOpHub : io/sentry/IHub {
public final class io/sentry/NoOpLogger : io/sentry/ILogger {
public static fun getInstance ()Lio/sentry/NoOpLogger;
public fun isEnabled (Lio/sentry/SentryLevel;)Z
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;Ljava/lang/Throwable;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/Throwable;Ljava/lang/String;[Ljava/lang/Object;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void onSpanFinished(@NotNull ISpan span) {
SentryLevel.DEBUG,
"stop collecting performance info for transactions %s (%s)",
transaction.getName(),
transaction.getSpanContext().getTraceId().toString());
transaction.getSpanContext().getTraceId());

for (final @NotNull IPerformanceContinuousCollector collector : continuousCollectors) {
collector.onSpanFinished(transaction);
Expand All @@ -180,7 +180,7 @@ public void onSpanFinished(@NotNull ISpan span) {
@Override
public @Nullable List<PerformanceCollectionData> stop(final @NotNull String id) {
final @Nullable CompositeData data = compositeDataMap.remove(id);
options.getLogger().log(SentryLevel.DEBUG, "stop collecting performance info for " + id);
options.getLogger().log(SentryLevel.DEBUG, "stop collecting performance info for %s", id);

// close if there are no more running requests
if (compositeDataMap.isEmpty()) {
Expand Down
26 changes: 26 additions & 0 deletions sentry/src/main/java/io/sentry/DiagnosticLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ public void log(
}
}

@Override
public void log(final @NotNull SentryLevel level, final @NotNull String message) {
if (logger != null && isEnabled(level)) {
logger.log(level, message);
}
}

@Override
public void log(
final @NotNull SentryLevel level, final @NotNull String message, final @Nullable Object arg) {
if (logger != null && isEnabled(level)) {
logger.log(level, message, arg);
}
}

@Override
public void log(
final @NotNull SentryLevel level,
final @NotNull String message,
final @Nullable Object arg1,
final @Nullable Object arg2) {
if (logger != null && isEnabled(level)) {
logger.log(level, message, arg1, arg2);
}
}

/**
* Logs a message with the specified level, message and throwable.
*
Expand Down
39 changes: 39 additions & 0 deletions sentry/src/main/java/io/sentry/ILogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,45 @@ public interface ILogger {
*/
void log(@NotNull SentryLevel level, @NotNull String message, @Nullable Object... args);

/**
* Logs a message without arguments. This overload and the overloads with one and two arguments do
* not allocate a varargs array at the call site. Thus, a disabled logger costs nothing.
*
* @param level The SentryLevel.
* @param message The message.
*/
default void log(final @NotNull SentryLevel level, final @NotNull String message) {
log(level, message, new Object[0]);
}

/**
* Logs a message with one formatting argument.
*
* @param level The SentryLevel.
* @param message The message.
* @param arg The argument to format the message.
*/
default void log(
final @NotNull SentryLevel level, final @NotNull String message, final @Nullable Object arg) {
log(level, message, new Object[] {arg});
}

/**
* Logs a message with two formatting arguments.
*
* @param level The SentryLevel.
* @param message The message.
* @param arg1 The first argument to format the message.
* @param arg2 The second argument to format the message.
*/
default void log(
final @NotNull SentryLevel level,
final @NotNull String message,
final @Nullable Object arg1,
final @Nullable Object arg2) {
log(level, message, new Object[] {arg1, arg2});
}

/**
* Logs a message with the specified level, message and optional arguments.
*
Expand Down
13 changes: 13 additions & 0 deletions sentry/src/main/java/io/sentry/NoOpLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ private NoOpLogger() {}
@Override
public void log(@NotNull SentryLevel level, @NotNull String message, @Nullable Object... args) {}

@Override
public void log(@NotNull SentryLevel level, @NotNull String message) {}

@Override
public void log(@NotNull SentryLevel level, @NotNull String message, @Nullable Object arg) {}

@Override
public void log(
@NotNull SentryLevel level,
@NotNull String message,
@Nullable Object arg1,
@Nullable Object arg2) {}

@Override
public void log(
@NotNull SentryLevel level, @NotNull String message, @Nullable Throwable throwable) {}
Expand Down
17 changes: 14 additions & 3 deletions sentry/src/test/java/io/sentry/OutboxSenderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import org.mockito.kotlin.any
import org.mockito.kotlin.anyVararg
import org.mockito.kotlin.argWhere
import org.mockito.kotlin.check
import org.mockito.kotlin.eq
Expand Down Expand Up @@ -310,7 +309,13 @@ class OutboxSenderTest {
sut.processEnvelopeFile(path, hints)

// Additionally make sure we have no errors logged
verify(fixture.logger).log(eq(SentryLevel.ERROR), any(), anyVararg<Any>())
verify(fixture.logger)
.log(
eq(SentryLevel.ERROR),
eq("Item %d of type %s returned null by the parser."),
any<Any>(),
any<Any>(),
)
verify(fixture.scopes, never()).captureEvent(any())
assertFalse(File(path).exists())
}
Expand All @@ -328,7 +333,13 @@ class OutboxSenderTest {
sut.processEnvelopeFile(path, hints)

// Additionally make sure we have no errors logged
verify(fixture.logger).log(eq(SentryLevel.ERROR), any(), anyVararg<Any>())
verify(fixture.logger)
.log(
eq(SentryLevel.ERROR),
eq("Item %d of type %s returned null by the parser."),
any<Any>(),
any<Any>(),
)
verify(fixture.scopes, never()).captureEvent(any())
assertFalse(File(path).exists())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.mockito.kotlin.any
import org.mockito.kotlin.anyVararg
import org.mockito.kotlin.argThat
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
Expand Down Expand Up @@ -281,7 +280,6 @@ class PreviousSessionFinalizerTest {
"Timed out waiting to flush previous session to its own file in session finalizer."
)
},
anyVararg<Any>(),
)
verify(fixture.scopes, never()).captureEnvelope(any())
}
Expand Down
Loading