-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathIScopes.java
More file actions
781 lines (690 loc) · 22.2 KB
/
IScopes.java
File metadata and controls
781 lines (690 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
package io.sentry;
import io.sentry.logger.ILoggerApi;
import io.sentry.metrics.IMetricsApi;
import io.sentry.protocol.Feedback;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.SentryTransaction;
import io.sentry.protocol.User;
import io.sentry.transport.RateLimiter;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface IScopes {
/**
* Check if Sentry is enabled/active.
*
* @return true if its enabled or false otherwise.
*/
boolean isEnabled();
/**
* Captures the event.
*
* @param event the event
* @param hint SDK specific but provides high level information about the origin of the event
* @return The Id (SentryId object) of the event
*/
@NotNull
SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hint hint);
/**
* Captures the event.
*
* @param event the event
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureEvent(@NotNull SentryEvent event) {
return captureEvent(event, new Hint());
}
/**
* Captures the event.
*
* @param event the event
* @param callback The callback to configure the scope for a single invocation.
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureEvent(
@NotNull SentryEvent event, final @NotNull ScopeCallback callback) {
return captureEvent(event, new Hint(), callback);
}
/**
* Captures the event.
*
* @param event the event
* @param hint SDK specific but provides high level information about the origin of the event
* @param callback The callback to configure the scope for a single invocation.
* @return The Id (SentryId object) of the event
*/
@NotNull
SentryId captureEvent(
final @NotNull SentryEvent event,
final @Nullable Hint hint,
final @NotNull ScopeCallback callback);
/**
* Captures the message.
*
* @param message The message to send.
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureMessage(@NotNull String message) {
return captureMessage(message, SentryLevel.INFO);
}
/**
* Captures the message.
*
* @param message The message to send.
* @param level The message level.
* @return The Id (SentryId object) of the event
*/
@NotNull
SentryId captureMessage(@NotNull String message, @NotNull SentryLevel level);
/**
* Captures the message.
*
* @param message The message to send.
* @param level The message level.
* @param callback The callback to configure the scope for a single invocation.
* @return The Id (SentryId object) of the event
*/
@NotNull
SentryId captureMessage(
@NotNull String message, @NotNull SentryLevel level, @NotNull ScopeCallback callback);
/**
* Captures the message.
*
* @param message The message to send.
* @param callback The callback to configure the scope for a single invocation.
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureMessage(
@NotNull String message, @NotNull ScopeCallback callback) {
return captureMessage(message, SentryLevel.INFO, callback);
}
/**
* Captures the feedback.
*
* @param feedback The feedback to send.
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureFeedback(final @NotNull Feedback feedback) {
return captureFeedback(feedback, null);
}
/**
* Captures the feedback.
*
* @param feedback The feedback to send.
* @param hint An optional hint to be applied to the event.
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureFeedback(
final @NotNull Feedback feedback, final @Nullable Hint hint) {
return captureFeedback(feedback, hint, null);
}
/**
* Captures the feedback.
*
* @param feedback The feedback to send.
* @param hint An optional hint to be applied to the event.
* @param callback The callback to configure the scope for a single invocation.
* @return The Id (SentryId object) of the event
*/
@NotNull
SentryId captureFeedback(
final @NotNull Feedback feedback,
final @Nullable Hint hint,
final @Nullable ScopeCallback callback);
/**
* Captures an envelope.
*
* @param envelope the SentryEnvelope to send.
* @param hint SDK specific but provides high level information about the origin of the event
* @return The Id (SentryId object) of the event
*/
@NotNull
SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint hint);
/**
* Captures an envelope.
*
* @param envelope the SentryEnvelope to send.
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureEnvelope(@NotNull SentryEnvelope envelope) {
return captureEnvelope(envelope, new Hint());
}
/**
* Captures the exception.
*
* @param throwable The exception.
* @param hint SDK specific but provides high level information about the origin of the event
* @return The Id (SentryId object) of the event
*/
@NotNull
SentryId captureException(@NotNull Throwable throwable, @Nullable Hint hint);
/**
* Captures the exception.
*
* @param throwable The exception.
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureException(@NotNull Throwable throwable) {
return captureException(throwable, new Hint());
}
/**
* Captures the exception.
*
* @param throwable The exception.
* @param callback The callback to configure the scope for a single invocation.
* @return The Id (SentryId object) of the event
*/
default @NotNull SentryId captureException(
@NotNull Throwable throwable, final @NotNull ScopeCallback callback) {
return captureException(throwable, new Hint(), callback);
}
/**
* Captures the exception.
*
* @param throwable The exception.
* @param hint SDK specific but provides high level information about the origin of the event
* @param callback The callback to configure the scope for a single invocation.
* @return The Id (SentryId object) of the event
*/
@NotNull
SentryId captureException(
final @NotNull Throwable throwable,
final @Nullable Hint hint,
final @NotNull ScopeCallback callback);
/**
* Captures a manually created user feedback and sends it to Sentry.
*
* @param userFeedback The user feedback to send to Sentry.
*/
void captureUserFeedback(@NotNull UserFeedback userFeedback);
/** Starts a new session. If there's a running session, it ends it before starting the new one. */
void startSession();
/** Ends the current session */
void endSession();
/** Flushes out the queue for up to timeout seconds and disable the Scopes. */
void close();
/**
* Flushes out the queue for up to timeout seconds and disable the Scopes.
*
* @param isRestarting if true, avoids locking the main thread when finishing the queue.
*/
void close(boolean isRestarting);
/**
* Adds a breadcrumb to the current Scope
*
* @param breadcrumb the breadcrumb
* @param hint SDK specific but provides high level information about the origin of the event
*/
void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hint hint);
/**
* Adds a breadcrumb to the current Scope
*
* @param breadcrumb the breadcrumb
*/
void addBreadcrumb(@NotNull Breadcrumb breadcrumb);
/**
* Adds a breadcrumb to the current Scope
*
* @param message rendered as text and the whitespace is preserved.
*/
default void addBreadcrumb(@NotNull String message) {
addBreadcrumb(new Breadcrumb(message));
}
/**
* Adds a breadcrumb to the current Scope
*
* @param message rendered as text and the whitespace is preserved.
* @param category Categories are dotted strings that indicate what the crumb is or where it comes
* from.
*/
default void addBreadcrumb(@NotNull String message, @NotNull String category) {
Breadcrumb breadcrumb = new Breadcrumb(message);
breadcrumb.setCategory(category);
addBreadcrumb(breadcrumb);
}
/**
* Sets the level of all events sent within current Scope
*
* @param level the Sentry level
*/
void setLevel(@Nullable SentryLevel level);
/**
* Sets the name of the current transaction to the current Scope.
*
* @param transaction the transaction
*/
void setTransaction(@Nullable String transaction);
/**
* Shallow merges user configuration (email, username, etc) to the current Scope.
*
* @param user the user
*/
void setUser(@Nullable User user);
/**
* Sets the fingerprint to group specific events together to the current Scope.
*
* @param fingerprint the fingerprints
*/
void setFingerprint(@NotNull List<String> fingerprint);
/** Deletes current breadcrumbs from the current scope. */
void clearBreadcrumbs();
/**
* Sets the tag to a string value to the current Scope, overwriting a potential previous value
*
* @param key the key
* @param value the value
*/
void setTag(@Nullable String key, @Nullable String value);
/**
* Removes the tag to a string value to the current Scope
*
* @param key the key
*/
void removeTag(@Nullable String key);
/**
* Sets the extra key to an arbitrary value to the current Scope, overwriting a potential previous
* value
*
* @param key the key
* @param value the value
*/
void setExtra(@Nullable String key, @Nullable String value);
/**
* Removes the extra key to an arbitrary value to the current Scope
*
* @param key the key
*/
void removeExtra(@Nullable String key);
/**
* Last event id recorded in the current scope
*
* @return last SentryId
*/
@NotNull
SentryId getLastEventId();
/** Pushes a new scope while inheriting the current scope's data. */
@NotNull
ISentryLifecycleToken pushScope();
@NotNull
ISentryLifecycleToken pushIsolationScope();
/**
* Removes the first scope and restores its parent.
*
* @deprecated please call {@link ISentryLifecycleToken#close()} on the token returned by {@link
* IScopes#pushScope()} or {@link IScopes#pushIsolationScope()} instead.
*/
@Deprecated
void popScope();
/**
* Runs the callback with a new current scope which gets dropped at the end.
*
* <p>If you're using the Sentry SDK in globalHubMode (defaults to true on Android) {@link
* Sentry#init(Sentry.OptionsConfiguration, boolean)} calling withScope is discouraged, as scope
* changes may be dropped when executed in parallel. Use {@link
* IScopes#configureScope(ScopeCallback)} instead.
*
* @param callback the callback
*/
void withScope(@NotNull ScopeCallback callback);
/**
* Runs the callback with a new isolation scope which gets dropped at the end. Current scope is
* also forked.
*
* <p>If you're using the Sentry SDK in globalHubMode (defaults to true on Android) {@link
* Sentry#init(Sentry.OptionsConfiguration, boolean)} calling withScope is discouraged, as scope
* changes may be dropped when executed in parallel. Use {@link IScopes#configureScope(ScopeType,
* ScopeCallback)} instead.
*
* @param callback the callback
*/
void withIsolationScope(@NotNull ScopeCallback callback);
/**
* Configures the scope through the callback.
*
* @param callback The configure scope callback.
*/
default void configureScope(@NotNull ScopeCallback callback) {
configureScope(null, callback);
}
/**
* Configures the scope through the callback.
*
* @param callback The configure scope callback.
*/
void configureScope(@Nullable ScopeType scopeType, @NotNull ScopeCallback callback);
/**
* Binds a different client to the scopes
*
* @param client the client.
*/
void bindClient(@NotNull ISentryClient client);
/**
* Whether the transport is healthy.
*
* @return true if the transport is healthy
*/
boolean isHealthy();
/**
* Flushes events queued up, but keeps the scopes enabled.
*
* @param timeoutMillis time in milliseconds
*/
void flush(long timeoutMillis);
/**
* Clones the Hub
*
* @deprecated please use {@link IScopes#forkedScopes(String)} or {@link
* IScopes#forkedCurrentScope(String)} instead.
* @return the cloned Hub
*/
@NotNull
@Deprecated
IHub clone();
/**
* Creates a fork of both current and isolation scope from current scopes.
*
* @param creator debug information to see why scopes where forked
* @return forked Scopes
*/
@NotNull
IScopes forkedScopes(final @NotNull String creator);
/**
* Creates a fork of current scope without forking isolation scope.
*
* @param creator debug information to see why scopes where forked
* @return forked Scopes
*/
@NotNull
IScopes forkedCurrentScope(final @NotNull String creator);
/**
* Creates a fork of both current and isolation scope from root scopes.
*
* @param creator debug information to see why scopes where forked
* @return forked Scopes
*/
@NotNull
IScopes forkedRootScopes(final @NotNull String creator);
/**
* Stores this Scopes in store, making it the current one that is used by static API.
*
* @return a token you should call .close() on when you're done.
*/
@NotNull
ISentryLifecycleToken makeCurrent();
/**
* Returns the current scope of this Scopes.
*
* @return scope
*/
@ApiStatus.Internal
@NotNull
IScope getScope();
/**
* Returns the isolation scope of this Scopes.
*
* @return isolation scope
*/
@ApiStatus.Internal
@NotNull
IScope getIsolationScope();
/**
* Returns the global scope.
*
* @return global scope
*/
@ApiStatus.Internal
@NotNull
IScope getGlobalScope();
/**
* Returns the parent of this Scopes instance or null, if it does not have a parent. The parent is
* the Scopes instance this instance was forked from.
*
* @return parent Scopes or null
*/
@ApiStatus.Internal
@Nullable
IScopes getParentScopes();
/**
* Checks whether this Scopes instance is direct or indirect parent of the other Scopes instance.
*
* @param otherScopes Scopes instance that could be a direct or indirect child.
* @return true if this Scopes instance is a direct or indirect parent of the other Scopes.
*/
@ApiStatus.Internal
boolean isAncestorOf(final @Nullable IScopes otherScopes);
/**
* Captures the transaction and enqueues it for sending to Sentry server.
*
* @param transaction the transaction
* @param traceContext the trace context
* @param hint the hints
* @param profilingTraceData the profiling trace data
* @return transaction's id
*/
@ApiStatus.Internal
@NotNull
SentryId captureTransaction(
@NotNull SentryTransaction transaction,
@Nullable TraceContext traceContext,
@Nullable Hint hint,
@Nullable ProfilingTraceData profilingTraceData);
/**
* Captures the transaction and enqueues it for sending to Sentry server.
*
* @param transaction the transaction
* @param traceContext the trace context
* @param hint the hints
* @return transaction's id
*/
@ApiStatus.Internal
@NotNull
default SentryId captureTransaction(
@NotNull SentryTransaction transaction,
@Nullable TraceContext traceContext,
@Nullable Hint hint) {
return captureTransaction(transaction, traceContext, hint, null);
}
@ApiStatus.Internal
@NotNull
default SentryId captureTransaction(@NotNull SentryTransaction transaction, @Nullable Hint hint) {
return captureTransaction(transaction, null, hint);
}
/**
* Captures the transaction and enqueues it for sending to Sentry server.
*
* @param transaction the transaction
* @param traceContext the trace context
* @return transaction's id
*/
@ApiStatus.Internal
default @NotNull SentryId captureTransaction(
@NotNull SentryTransaction transaction, @Nullable TraceContext traceContext) {
return captureTransaction(transaction, traceContext, null);
}
/**
* Captures the profile chunk and enqueues it for sending to Sentry server.
*
* @param profileChunk the continuous profiling payload
* @return the profile chunk id
*/
@ApiStatus.Internal
@NotNull
SentryId captureProfileChunk(final @NotNull ProfileChunk profileChunk);
/**
* Creates a Transaction and returns the instance.
*
* @param transactionContexts the transaction contexts
* @return created transaction
*/
default @NotNull ITransaction startTransaction(@NotNull TransactionContext transactionContexts) {
return startTransaction(transactionContexts, new TransactionOptions());
}
/**
* Creates a Transaction and returns the instance. Based on the {@link
* SentryOptions#getTracesSampleRate()} the decision if transaction is sampled will be taken by
* {@link TracesSampler}.
*
* @param name the transaction name
* @param operation the operation
* @return created transaction
*/
default @NotNull ITransaction startTransaction(
final @NotNull String name, final @NotNull String operation) {
return startTransaction(name, operation, new TransactionOptions());
}
/**
* Creates a Transaction and returns the instance. Based on the {@link
* SentryOptions#getTracesSampleRate()} the decision if transaction is sampled will be taken by
* {@link TracesSampler}.
*
* @param name the transaction name
* @param operation the operation
* @param transactionOptions the transaction options
* @return created transaction
*/
default @NotNull ITransaction startTransaction(
final @NotNull String name,
final @NotNull String operation,
final @NotNull TransactionOptions transactionOptions) {
return startTransaction(new TransactionContext(name, operation), transactionOptions);
}
/**
* Creates a Transaction and returns the instance. Based on the passed transaction context and
* transaction options the decision if transaction is sampled will be taken by {@link
* TracesSampler}.
*
* @param transactionContext the transaction context
* @param transactionOptions the transaction options
* @return created transaction.
*/
@NotNull
ITransaction startTransaction(
final @NotNull TransactionContext transactionContext,
final @NotNull TransactionOptions transactionOptions);
void startProfiler();
void stopProfiler();
/**
* Associates {@link ISpan} and the transaction name with the {@link Throwable}. Used to determine
* in which trace the exception has been thrown in framework integrations.
*
* @param throwable the throwable
* @param span the span context
* @param transactionName the transaction name
*/
@ApiStatus.Internal
void setSpanContext(
@NotNull Throwable throwable, @NotNull ISpan span, @NotNull String transactionName);
/**
* Gets the current active transaction or span.
*
* @return the active span or null when no active transaction is running
*/
@Nullable
ISpan getSpan();
@ApiStatus.Internal
void setActiveSpan(@Nullable ISpan span);
/**
* Returns the transaction.
*
* @return the transaction or null when no active transaction is running.
*/
@ApiStatus.Internal
@Nullable
ITransaction getTransaction();
/**
* Gets the {@link SentryOptions} attached to current scope.
*
* @return the options attached to current scope.
*/
@NotNull
SentryOptions getOptions();
/**
* Returns if the App has crashed (Process has terminated) during the last run. It only returns
* true or false if offline caching {{@link SentryOptions#getCacheDirPath()} } is set with a valid
* dir.
*
* <p>If the call to this method is early in the App lifecycle and the SDK could not check if the
* App has crashed in the background, the check is gonna do IO in the calling thread.
*
* @return true if App has crashed, false otherwise, and null if not evaluated yet
*/
@Nullable
Boolean isCrashedLastRun();
/**
* Report a screen has been fully loaded. That means all data needed by the UI was loaded. If
* time-to-full-display tracing {{@link SentryOptions#isEnableTimeToFullDisplayTracing()} } is
* disabled this call is ignored.
*
* <p>This method is safe to be called multiple times. If the time-to-full-display span is already
* finished, this call will be ignored.
*/
void reportFullyDisplayed();
/**
* Continue a trace based on HTTP header values. If no "sentry-trace" header is provided a random
* trace ID and span ID is created.
*
* @param sentryTrace "sentry-trace" header
* @param baggageHeaders "baggage" headers
* @return a transaction context for starting a transaction or null if performance is disabled
*/
@Nullable
TransactionContext continueTrace(
final @Nullable String sentryTrace, final @Nullable List<String> baggageHeaders);
/**
* Returns the "sentry-trace" header that allows tracing across services. Can also be used in
* <meta> HTML tags. Also see {@link IScopes#getBaggage()}.
*
* @return sentry trace header or null
*/
@Nullable
SentryTraceHeader getTraceparent();
/**
* Returns the "baggage" header that allows tracing across services. Can also be used in
* <meta> HTML tags. Also see {@link IScopes#getTraceparent()}.
*
* @return baggage header or null
*/
@Nullable
BaggageHeader getBaggage();
@NotNull
SentryId captureCheckIn(final @NotNull CheckIn checkIn);
@ApiStatus.Internal
@Nullable
RateLimiter getRateLimiter();
default boolean isNoOp() {
return false;
}
@NotNull
SentryId captureReplay(@NotNull SentryReplayEvent replay, @Nullable Hint hint);
@NotNull
ILoggerApi logger();
@NotNull
IMetricsApi metrics();
/**
* Sets an attribute.
*
* @param key the key
* @param value the value
*/
void setAttribute(final @Nullable String key, final @Nullable Object value);
/**
* Sets an attribute.
*
* @param attribute the attribute
*/
void setAttribute(final @Nullable SentryAttribute attribute);
/**
* Sets multiple attributes.
*
* @param attributes the attributes
*/
void setAttributes(final @Nullable SentryAttributes attributes);
/**
* Removes an attribute.
*
* @param key the key
*/
void removeAttribute(final @Nullable String key);
void addFeatureFlag(final @Nullable String flag, final @Nullable Boolean result);
}