Skip to content

[Logs 12] Logs review feedback #4392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0627186
Add Log feature to Java SDK
adinauer May 6, 2025
27a24ec
Rate limit for log items
adinauer May 6, 2025
0c75319
Add options for logs
adinauer May 7, 2025
bc8caf7
Add batch processor for logs
adinauer May 8, 2025
38c3dcd
Use a separate ExecutorService for log batching
adinauer May 8, 2025
c639bfc
Reduce locking when log event is created
adinauer May 8, 2025
217f7c7
Add system tests for Logs
adinauer May 12, 2025
fef4582
Separate enum for SentryLogLevel
adinauer May 12, 2025
ac2bce7
Remove logsSampleRate option
adinauer May 12, 2025
50078d0
Move logs options out of experimental namespace
adinauer May 12, 2025
d0fef91
Add severity_number to SentryLogItem
adinauer May 12, 2025
60dc14b
Logs review feedback
adinauer May 12, 2025
69d6a81
mark captureBatchedLogEvents internal
adinauer May 13, 2025
88f4c96
remove hint for logs
adinauer May 13, 2025
e7c9212
Allow null for log event attribute value
adinauer May 13, 2025
5ba33fd
Merge branch 'main' into feat/logs-e2e-tests
adinauer May 13, 2025
a7afc9d
Merge branch 'feat/logs-e2e-tests' into feat/separate-log-level-enum
adinauer May 13, 2025
164f210
Merge branch 'main' into feat/separate-log-level-enum
adinauer May 13, 2025
893b67c
Merge branch 'feat/separate-log-level-enum' into feat/remove-logs-sam…
adinauer May 13, 2025
80e5bb9
Merge branch 'main' into feat/remove-logs-sample-rate-option
adinauer May 13, 2025
c1ca9be
Merge branch 'feat/remove-logs-sample-rate-option' into feat/logs-not…
adinauer May 13, 2025
808b4e6
Merge branch 'main' into feat/logs-not-experimental
adinauer May 13, 2025
e167f1b
Merge branch 'feat/logs-not-experimental' into feat/logs-severity-number
adinauer May 13, 2025
c07e44c
Merge branch 'main' into feat/logs-severity-number
adinauer May 13, 2025
888ab48
Merge branch 'feat/logs-severity-number' into feat/logs-review-feedback
adinauer May 13, 2025
7894f55
Merge branch 'main' into feat/logs-review-feedback
adinauer May 13, 2025
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 @@ -192,7 +192,7 @@ class SessionTrackingIntegrationTest {
TODO("Not yet implemented")
}

override fun captureLog(event: SentryLogEvent, scope: IScope?, hint: Hint?) {
override fun captureLog(event: SentryLogEvent, scope: IScope?) {
TODO("Not yet implemented")
}

Expand Down
12 changes: 6 additions & 6 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ public abstract interface class io/sentry/ISentryClient {
public fun captureException (Ljava/lang/Throwable;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
public fun captureException (Ljava/lang/Throwable;Lio/sentry/IScope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public abstract fun captureFeedback (Lio/sentry/protocol/Feedback;Lio/sentry/Hint;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
public abstract fun captureLog (Lio/sentry/SentryLogEvent;Lio/sentry/IScope;Lio/sentry/Hint;)V
public abstract fun captureLog (Lio/sentry/SentryLogEvent;Lio/sentry/IScope;)V
public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId;
public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
public abstract fun captureProfileChunk (Lio/sentry/ProfileChunk;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
Expand Down Expand Up @@ -2738,7 +2738,7 @@ public final class io/sentry/SentryClient : io/sentry/ISentryClient {
public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/IScope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureFeedback (Lio/sentry/protocol/Feedback;Lio/sentry/Hint;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
public fun captureLog (Lio/sentry/SentryLogEvent;Lio/sentry/IScope;Lio/sentry/Hint;)V
public fun captureLog (Lio/sentry/SentryLogEvent;Lio/sentry/IScope;)V
public fun captureProfileChunk (Lio/sentry/ProfileChunk;Lio/sentry/IScope;)Lio/sentry/protocol/SentryId;
public fun captureReplayEvent (Lio/sentry/SentryReplayEvent;Lio/sentry/IScope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureSession (Lio/sentry/Session;Lio/sentry/Hint;)V
Expand Down Expand Up @@ -3464,7 +3464,7 @@ public final class io/sentry/SentryOptions$Logs {
}

public abstract interface class io/sentry/SentryOptions$Logs$BeforeSendLogCallback {
public abstract fun execute (Lio/sentry/SentryLogEvent;Lio/sentry/Hint;)Lio/sentry/SentryLogEvent;
public abstract fun execute (Lio/sentry/SentryLogEvent;)Lio/sentry/SentryLogEvent;
}

public abstract interface class io/sentry/SentryOptions$ProfilesSamplerCallback {
Expand Down Expand Up @@ -4703,7 +4703,7 @@ public abstract interface class io/sentry/logger/ILoggerApi {
public abstract fun error (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun fatal (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
Expand All @@ -4720,7 +4720,7 @@ public final class io/sentry/logger/LoggerApi : io/sentry/logger/ILoggerApi {
public fun error (Ljava/lang/String;[Ljava/lang/Object;)V
public fun fatal (Ljava/lang/String;[Ljava/lang/Object;)V
public fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
Expand All @@ -4740,7 +4740,7 @@ public final class io/sentry/logger/NoOpLoggerApi : io/sentry/logger/ILoggerApi
public fun fatal (Ljava/lang/String;[Ljava/lang/Object;)V
public static fun getInstance ()Lio/sentry/logger/NoOpLoggerApi;
public fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/ISentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ SentryId captureProfileChunk(
SentryId captureCheckIn(@NotNull CheckIn checkIn, @Nullable IScope scope, @Nullable Hint hint);

@ApiStatus.Experimental
void captureLog(@NotNull SentryLogEvent logEvent, @Nullable IScope scope, @Nullable Hint hint);
void captureLog(@NotNull SentryLogEvent logEvent, @Nullable IScope scope);

@ApiStatus.Experimental
@ApiStatus.Internal
void captureBatchedLogEvents(@NotNull SentryLogEvents logEvents);

@ApiStatus.Internal
Expand Down
5 changes: 2 additions & 3 deletions sentry/src/main/java/io/sentry/NoOpSentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ public SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint

@ApiStatus.Experimental
@Override
public void captureLog(
@NotNull SentryLogEvent logEvent, @Nullable IScope scope, @Nullable Hint hint) {
public void captureLog(@NotNull SentryLogEvent logEvent, @Nullable IScope scope) {
// do nothing
}

@ApiStatus.Experimental
@ApiStatus.Internal
@Override
public void captureBatchedLogEvents(@NotNull SentryLogEvents logEvents) {
// do nothing
Expand Down
28 changes: 5 additions & 23 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1132,26 +1132,10 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint

@ApiStatus.Experimental
@Override
public void captureLog(
@Nullable SentryLogEvent logEvent, @Nullable IScope scope, @Nullable Hint hint) {
if (hint == null) {
hint = new Hint();
}

// @Nullable TraceContext traceContext = null;
// if (scope != null) {
// final @Nullable ITransaction transaction = scope.getTransaction();
// if (transaction != null) {
// traceContext = transaction.traceContext();
// } else {
// final @NotNull PropagationContext propagationContext =
// TracingUtils.maybeUpdateBaggage(scope, options);
// traceContext = propagationContext.traceContext();
// }
// }
public void captureLog(@Nullable SentryLogEvent logEvent, @Nullable IScope scope) {

if (logEvent != null) {
logEvent = executeBeforeSendLog(logEvent, hint);
logEvent = executeBeforeSendLog(logEvent);

if (logEvent == null) {
options.getLogger().log(SentryLevel.DEBUG, "Log Event was dropped by beforeSendLog");
Expand All @@ -1163,10 +1147,9 @@ public void captureLog(

loggerBatchProcessor.add(logEvent);
}

hint.clear();
}

@ApiStatus.Internal
@Override
public void captureBatchedLogEvents(final @NotNull SentryLogEvents logEvents) {
try {
Expand Down Expand Up @@ -1453,13 +1436,12 @@ private void sortBreadcrumbsByDate(
return event;
}

private @Nullable SentryLogEvent executeBeforeSendLog(
@NotNull SentryLogEvent event, final @NotNull Hint hint) {
private @Nullable SentryLogEvent executeBeforeSendLog(@NotNull SentryLogEvent event) {
final SentryOptions.Logs.BeforeSendLogCallback beforeSendLog =
options.getLogs().getBeforeSend();
if (beforeSendLog != null) {
try {
event = beforeSendLog.execute(event, hint);
event = beforeSendLog.execute(event);
} catch (Throwable e) {
options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
public final class SentryLogEventAttributeValue implements JsonUnknown, JsonSerializable {

private @NotNull String type;
private @NotNull Object value;
private @Nullable Object value;
private @Nullable Map<String, Object> unknown;

public SentryLogEventAttributeValue(final @NotNull String type, final @NotNull Object value) {
public SentryLogEventAttributeValue(final @NotNull String type, final @Nullable Object value) {
this.type = type;
this.value = value;
}
Expand Down Expand Up @@ -88,13 +88,6 @@ public static final class Deserializer implements JsonDeserializer<SentryLogEven
throw exception;
}

if (value == null) {
String message = "Missing required field \"" + JsonKeys.VALUE + "\"";
Exception exception = new IllegalStateException(message);
logger.log(SentryLevel.ERROR, message, exception);
throw exception;
}

final SentryLogEventAttributeValue logEvent = new SentryLogEventAttributeValue(type, value);

logEvent.setUnknown(unknown);
Expand Down
3 changes: 1 addition & 2 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3430,11 +3430,10 @@ public interface BeforeSendLogCallback {
* Mutates or drop a log event before being sent
*
* @param event the event
* @param hint the hints
* @return the original log event or the mutated event or null if event was dropped
*/
@Nullable
SentryLogEvent execute(@NotNull SentryLogEvent event, @NotNull Hint hint);
SentryLogEvent execute(@NotNull SentryLogEvent event);
}
}

Expand Down
2 changes: 0 additions & 2 deletions sentry/src/main/java/io/sentry/logger/ILoggerApi.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.sentry.logger;

import io.sentry.Hint;
import io.sentry.SentryDate;
import io.sentry.SentryLogLevel;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -28,6 +27,5 @@ void log(
@NotNull SentryLogLevel level,
@Nullable SentryDate timestamp,
@Nullable String message,
final @Nullable Hint hint,
@Nullable Object... args);
}
24 changes: 13 additions & 11 deletions sentry/src/main/java/io/sentry/logger/LoggerApi.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.sentry.logger;

import io.sentry.Hint;
import io.sentry.IScope;
import io.sentry.ISpan;
import io.sentry.PropagationContext;
import io.sentry.Scopes;
Expand All @@ -13,6 +13,7 @@
import io.sentry.SpanId;
import io.sentry.protocol.SdkVersion;
import io.sentry.protocol.SentryId;
import io.sentry.util.TracingUtils;
import java.util.HashMap;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -29,8 +30,7 @@ public LoggerApi(final @NotNull Scopes scopes) {

@Override
public void trace(final @Nullable String message, final @Nullable Object... args) {
// TODO SentryLevel.TRACE does not exists yet so we just report it as DEBUG for now
log(SentryLogLevel.DEBUG, message, args);
log(SentryLogLevel.TRACE, message, args);
}

@Override
Expand Down Expand Up @@ -63,24 +63,22 @@ public void log(
final @NotNull SentryLogLevel level,
final @Nullable String message,
final @Nullable Object... args) {
log(level, null, message, null, args);
log(level, null, message, args);
}

@Override
public void log(
final @NotNull SentryLogLevel level,
final @Nullable SentryDate timestamp,
final @Nullable String message,
final @Nullable Hint hint,
final @Nullable Object... args) {
captureLog(level, timestamp, hint, message, args);
captureLog(level, timestamp, message, args);
}

@SuppressWarnings("AnnotateFormatMethod")
private void captureLog(
final @NotNull SentryLogLevel level,
final @Nullable SentryDate timestamp,
final @Nullable Hint hint,
final @Nullable String message,
final @Nullable Object... args) {
final @NotNull SentryOptions options = scopes.getOptions();
Expand All @@ -106,9 +104,13 @@ private void captureLog(
final @NotNull SentryDate timestampToUse =
timestamp == null ? options.getDateProvider().now() : timestamp;
final @NotNull String messageToUse = args == null ? message : String.format(message, args);
final @NotNull PropagationContext propagationContext =
scopes.getCombinedScopeView().getPropagationContext();
final @Nullable ISpan span = scopes.getCombinedScopeView().getSpan();

final @NotNull IScope combinedScope = scopes.getCombinedScopeView();
final @NotNull PropagationContext propagationContext = combinedScope.getPropagationContext();
final @Nullable ISpan span = combinedScope.getSpan();
if (span == null) {
TracingUtils.maybeUpdateBaggage(combinedScope, options);
}
final @NotNull SentryId traceId =
span == null ? propagationContext.getTraceId() : span.getSpanContext().getTraceId();
final @NotNull SpanId spanId =
Expand All @@ -118,7 +120,7 @@ private void captureLog(
logEvent.setAttributes(createAttributes(message, spanId, args));
logEvent.setSeverityNumber(level.getSeverityNumber());

scopes.getClient().captureLog(logEvent, scopes.getCombinedScopeView(), hint);
scopes.getClient().captureLog(logEvent, combinedScope);
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error while capturing log event", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ private void flush() {
}

private void flushInternal() {
flushBatch();
if (queue.size() >= MAX_BATCH_SIZE) {
flushInternal();
}
do {
flushBatch();
} while (queue.size() >= MAX_BATCH_SIZE);
}

private void flushBatch() {
Expand Down
2 changes: 0 additions & 2 deletions sentry/src/main/java/io/sentry/logger/NoOpLoggerApi.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.sentry.logger;

import io.sentry.Hint;
import io.sentry.SentryDate;
import io.sentry.SentryLogLevel;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -59,7 +58,6 @@ public void log(
@NotNull SentryLogLevel level,
@Nullable SentryDate timestamp,
@Nullable String message,
final @Nullable Hint hint,
@Nullable Object... args) {
// do nothing
}
Expand Down
Loading