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 .SentryId ;
1619import java .io .Closeable ;
1720import java .io .IOException ;
1821import java .util .ArrayList ;
19- import java .util .Arrays ;
2022import java .util .Collection ;
2123import java .util .Collections ;
2224import java .util .Comparator ;
@@ -36,6 +38,7 @@ public final class SentryClient implements ISentryClient {
3638 private final @ NotNull SentryOptions options ;
3739 private final @ NotNull ITransport transport ;
3840 private final @ NotNull SortBreadcrumbsByDate sortBreadcrumbsByDate = new SortBreadcrumbsByDate ();
41+ private final @ NotNull ILoggerBatchProcessor loggerBatchProcessor ;
3942
4043 @ Override
4144 public boolean isEnabled () {
@@ -55,6 +58,11 @@ public SentryClient(final @NotNull SentryOptions options) {
5558
5659 final RequestDetailsResolver requestDetailsResolver = new RequestDetailsResolver (options );
5760 transport = transportFactory .create (options , requestDetailsResolver .resolve ());
61+ if (options .getExperimental ().getLogs ().isEnabled ()) {
62+ loggerBatchProcessor = new LoggerBatchProcessor (options , this );
63+ } else {
64+ loggerBatchProcessor = NoOpLoggerBatchProcessor .getInstance ();
65+ }
5866 }
5967
6068 private boolean shouldApplyScopeData (
@@ -625,16 +633,15 @@ public void captureUserFeedback(final @NotNull UserFeedback userFeedback) {
625633 return new SentryEnvelope (envelopeHeader , envelopeItems );
626634 }
627635
628- private @ NotNull SentryEnvelope buildEnvelope (
629- final @ NotNull SentryLogEvents logEvents , final @ Nullable TraceContext traceContext ) {
636+ private @ NotNull SentryEnvelope buildEnvelope (final @ NotNull SentryLogEvents logEvents ) {
630637 final List <SentryEnvelopeItem > envelopeItems = new ArrayList <>();
631638
632639 final SentryEnvelopeItem logItem =
633640 SentryEnvelopeItem .fromLogs (options .getSerializer (), logEvents );
634641 envelopeItems .add (logItem );
635642
636643 final SentryEnvelopeHeader envelopeHeader =
637- new SentryEnvelopeHeader (null , options .getSdkVersion (), traceContext );
644+ new SentryEnvelopeHeader (null , options .getSdkVersion (), null );
638645
639646 return new SentryEnvelope (envelopeHeader , envelopeItems );
640647 }
@@ -1018,17 +1025,17 @@ public void captureLog(
10181025 hint = new Hint ();
10191026 }
10201027
1021- @ Nullable TraceContext traceContext = null ;
1022- if (scope != null ) {
1023- final @ Nullable ITransaction transaction = scope .getTransaction ();
1024- if (transaction != null ) {
1025- traceContext = transaction .traceContext ();
1026- } else {
1027- final @ NotNull PropagationContext propagationContext =
1028- TracingUtils .maybeUpdateBaggage (scope , options );
1029- traceContext = propagationContext .traceContext ();
1030- }
1031- }
1028+ // @Nullable TraceContext traceContext = null;
1029+ // if (scope != null) {
1030+ // final @Nullable ITransaction transaction = scope.getTransaction();
1031+ // if (transaction != null) {
1032+ // traceContext = transaction.traceContext();
1033+ // } else {
1034+ // final @NotNull PropagationContext propagationContext =
1035+ // TracingUtils.maybeUpdateBaggage(scope, options);
1036+ // traceContext = propagationContext.traceContext();
1037+ // }
1038+ // }
10321039
10331040 if (logEvent != null ) {
10341041 logEvent = executeBeforeSendLog (logEvent , hint );
@@ -1040,15 +1047,18 @@ public void captureLog(
10401047 .recordLostEvent (DiscardReason .BEFORE_SEND , DataCategory .LogItem );
10411048 return ;
10421049 }
1050+
1051+ loggerBatchProcessor .add (logEvent );
10431052 }
10441053
1045- try {
1046- final @ NotNull SentryEnvelope envelope =
1047- buildEnvelope (new SentryLogEvents (Arrays .asList (logEvent )), traceContext );
1054+ hint .clear ();
1055+ }
10481056
1049- hint .clear ();
1050- // TODO buffer
1051- sendEnvelope (envelope , hint );
1057+ @ Override
1058+ public void captureBatchedLogEvents (final @ NotNull SentryLogEvents logEvents ) {
1059+ try {
1060+ final @ NotNull SentryEnvelope envelope = buildEnvelope (logEvents );
1061+ sendEnvelope (envelope , null );
10521062 } catch (IOException e ) {
10531063 options .getLogger ().log (SentryLevel .WARNING , e , "Capturing log failed." );
10541064 }
@@ -1307,6 +1317,7 @@ public void close(final boolean isRestarting) {
13071317 options .getLogger ().log (SentryLevel .INFO , "Closing SentryClient." );
13081318 try {
13091319 flush (isRestarting ? 0 : options .getShutdownTimeoutMillis ());
1320+ loggerBatchProcessor .close (isRestarting );
13101321 transport .close (isRestarting );
13111322 } catch (IOException e ) {
13121323 options
0 commit comments