66import io .sentry .hints .Backfillable ;
77import io .sentry .hints .DiskFlushNotification ;
88import io .sentry .hints .TransactionEnd ;
9+ import io .sentry .logger .ILoggerBatchProcessor ;
10+ import io .sentry .logger .LoggerBatchProcessor ;
11+ import io .sentry .logger .NoOpLoggerBatchProcessor ;
912import io .sentry .protocol .Contexts ;
1013import io .sentry .protocol .DebugMeta ;
1114import io .sentry .protocol .Feedback ;
1720import java .io .Closeable ;
1821import java .io .IOException ;
1922import java .util .ArrayList ;
20- import java .util .Arrays ;
2123import java .util .Collection ;
2224import java .util .Collections ;
2325import java .util .Comparator ;
@@ -37,6 +39,7 @@ public final class SentryClient implements ISentryClient {
3739 private final @ NotNull SentryOptions options ;
3840 private final @ NotNull ITransport transport ;
3941 private final @ NotNull SortBreadcrumbsByDate sortBreadcrumbsByDate = new SortBreadcrumbsByDate ();
42+ private final @ NotNull ILoggerBatchProcessor loggerBatchProcessor ;
4043
4144 @ Override
4245 public boolean isEnabled () {
@@ -56,6 +59,11 @@ public SentryClient(final @NotNull SentryOptions options) {
5659
5760 final RequestDetailsResolver requestDetailsResolver = new RequestDetailsResolver (options );
5861 transport = transportFactory .create (options , requestDetailsResolver .resolve ());
62+ if (options .getExperimental ().getLogs ().isEnabled ()) {
63+ loggerBatchProcessor = new LoggerBatchProcessor (options , this );
64+ } else {
65+ loggerBatchProcessor = NoOpLoggerBatchProcessor .getInstance ();
66+ }
5967 }
6068
6169 private boolean shouldApplyScopeData (
@@ -631,16 +639,15 @@ public void captureUserFeedback(final @NotNull UserFeedback userFeedback) {
631639 return new SentryEnvelope (envelopeHeader , envelopeItems );
632640 }
633641
634- private @ NotNull SentryEnvelope buildEnvelope (
635- final @ NotNull SentryLogEvents logEvents , final @ Nullable TraceContext traceContext ) {
642+ private @ NotNull SentryEnvelope buildEnvelope (final @ NotNull SentryLogEvents logEvents ) {
636643 final List <SentryEnvelopeItem > envelopeItems = new ArrayList <>();
637644
638645 final SentryEnvelopeItem logItem =
639646 SentryEnvelopeItem .fromLogs (options .getSerializer (), logEvents );
640647 envelopeItems .add (logItem );
641648
642649 final SentryEnvelopeHeader envelopeHeader =
643- new SentryEnvelopeHeader (null , options .getSdkVersion (), traceContext );
650+ new SentryEnvelopeHeader (null , options .getSdkVersion (), null );
644651
645652 return new SentryEnvelope (envelopeHeader , envelopeItems );
646653 }
@@ -1131,17 +1138,17 @@ public void captureLog(
11311138 hint = new Hint ();
11321139 }
11331140
1134- @ Nullable TraceContext traceContext = null ;
1135- if (scope != null ) {
1136- final @ Nullable ITransaction transaction = scope .getTransaction ();
1137- if (transaction != null ) {
1138- traceContext = transaction .traceContext ();
1139- } else {
1140- final @ NotNull PropagationContext propagationContext =
1141- TracingUtils .maybeUpdateBaggage (scope , options );
1142- traceContext = propagationContext .traceContext ();
1143- }
1144- }
1141+ // @Nullable TraceContext traceContext = null;
1142+ // if (scope != null) {
1143+ // final @Nullable ITransaction transaction = scope.getTransaction();
1144+ // if (transaction != null) {
1145+ // traceContext = transaction.traceContext();
1146+ // } else {
1147+ // final @NotNull PropagationContext propagationContext =
1148+ // TracingUtils.maybeUpdateBaggage(scope, options);
1149+ // traceContext = propagationContext.traceContext();
1150+ // }
1151+ // }
11451152
11461153 if (logEvent != null ) {
11471154 logEvent = executeBeforeSendLog (logEvent , hint );
@@ -1153,15 +1160,18 @@ public void captureLog(
11531160 .recordLostEvent (DiscardReason .BEFORE_SEND , DataCategory .LogItem );
11541161 return ;
11551162 }
1163+
1164+ loggerBatchProcessor .add (logEvent );
11561165 }
11571166
1158- try {
1159- final @ NotNull SentryEnvelope envelope =
1160- buildEnvelope (new SentryLogEvents (Arrays .asList (logEvent )), traceContext );
1167+ hint .clear ();
1168+ }
11611169
1162- hint .clear ();
1163- // TODO buffer
1164- sendEnvelope (envelope , hint );
1170+ @ Override
1171+ public void captureBatchedLogEvents (final @ NotNull SentryLogEvents logEvents ) {
1172+ try {
1173+ final @ NotNull SentryEnvelope envelope = buildEnvelope (logEvents );
1174+ sendEnvelope (envelope , null );
11651175 } catch (IOException e ) {
11661176 options .getLogger ().log (SentryLevel .WARNING , e , "Capturing log failed." );
11671177 }
@@ -1475,6 +1485,7 @@ public void close(final boolean isRestarting) {
14751485 options .getLogger ().log (SentryLevel .INFO , "Closing SentryClient." );
14761486 try {
14771487 flush (isRestarting ? 0 : options .getShutdownTimeoutMillis ());
1488+ loggerBatchProcessor .close (isRestarting );
14781489 transport .close (isRestarting );
14791490 } catch (IOException e ) {
14801491 options
0 commit comments