forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIHub.java
More file actions
431 lines (381 loc) · 12.4 KB
/
IHub.java
File metadata and controls
431 lines (381 loc) · 12.4 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
package io.sentry;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.SentryTransaction;
import io.sentry.protocol.User;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** SDK API contract which combines a client and scope management */
public interface IHub {
/**
* Check if the Hub 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
*/
SentryId captureEvent(SentryEvent event, @Nullable Object hint);
/**
* Captures the event.
*
* @param event the event
* @return The Id (SentryId object) of the event
*/
default SentryId captureEvent(SentryEvent event) {
return captureEvent(event, null);
}
/**
* Captures the message.
*
* @param message The message to send.
* @return The Id (SentryId object) of the event
*/
default SentryId captureMessage(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
*/
SentryId captureMessage(String message, SentryLevel level);
/**
* 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
*/
SentryId captureEnvelope(SentryEnvelope envelope, @Nullable Object hint);
/**
* Captures an envelope.
*
* @param envelope the SentryEnvelope to send.
* @return The Id (SentryId object) of the event
*/
default SentryId captureEnvelope(SentryEnvelope envelope) {
return captureEnvelope(envelope, null);
}
/**
* 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
*/
SentryId captureException(Throwable throwable, @Nullable Object hint);
/**
* Captures the exception.
*
* @param throwable The exception.
* @return The Id (SentryId object) of the event
*/
default SentryId captureException(Throwable throwable) {
return captureException(throwable, null);
}
/**
* Captures a manually created user feedback and sends it to Sentry.
*
* @param userFeedback The user feedback to send to Sentry.
*/
void captureUserFeedback(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 Hub. */
void close();
/**
* 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(Breadcrumb breadcrumb, @Nullable Object hint);
/**
* Adds a breadcrumb to the current Scope
*
* @param breadcrumb the breadcrumb
*/
default void addBreadcrumb(Breadcrumb breadcrumb) {
addBreadcrumb(breadcrumb, null);
}
/**
* 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(SentryLevel level);
/**
* Sets the name of the current transaction to the current Scope.
*
* @param transaction the transaction
*/
void setTransaction(String transaction);
/**
* Shallow merges user configuration (email, username, etc) to the current Scope.
*
* @param user the user
*/
void setUser(User user);
/**
* Sets the fingerprint to group specific events together to the current Scope.
*
* @param fingerprint the fingerprints
*/
void setFingerprint(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(String key, String value);
/**
* Removes the tag to a string value to the current Scope
*
* @param key the key
*/
void removeTag(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(String key, String value);
/**
* Removes the extra key to an arbitrary value to the current Scope
*
* @param key the key
*/
void removeExtra(String key);
/**
* Last event id recorded in the current scope
*
* @return last SentryId
*/
SentryId getLastEventId();
/** Pushes a new scope while inheriting the current scope's data. */
void pushScope();
/** Removes the first scope */
void popScope();
/**
* Runs the callback with a new scope which gets dropped at the end
*
* @param callback the callback
*/
void withScope(ScopeCallback callback);
/**
* Configures the scope through the callback.
*
* @param callback The configure scope callback.
*/
void configureScope(ScopeCallback callback);
/**
* Binds a different client to the hub
*
* @param client the client.
*/
void bindClient(ISentryClient client);
/**
* Flushes events queued up, but keeps the Hub enabled. Not implemented yet.
*
* @param timeoutMillis time in milliseconds
*/
void flush(long timeoutMillis);
/**
* Clones the Hub
*
* @return the cloned Hub
*/
IHub clone();
/**
* Captures the transaction and enqueues it for sending to Sentry server.
*
* @param transaction the transaction
* @param hint the hint
* @return transaction's id
*/
@ApiStatus.Internal
SentryId captureTransaction(SentryTransaction transaction, Object hint);
/**
* Captures the transaction and enqueues it for sending to Sentry server.
*
* @param transaction the transaction
* @return transaction's id
*/
@ApiStatus.Internal
default SentryId captureTransaction(SentryTransaction transaction) {
return captureTransaction(transaction, null);
}
/**
* Creates a Transaction bound to the current hub and returns the instance.
*
* @param transactionContexts the transaction contexts
* @return created transaction
*/
default ITransaction startTransaction(TransactionContext transactionContexts) {
return startTransaction(transactionContexts, true);
}
/**
* Creates a Transaction bound to the current hub and returns the instance.
*
* @param transactionContexts the transaction contexts
* @param bindToScope if transaction should be bound to scope
* @return created transaction
*/
default ITransaction startTransaction(
TransactionContext transactionContexts, boolean bindToScope) {
return startTransaction(transactionContexts, null, bindToScope);
}
/**
* Creates a Transaction bound to the current hub and returns the instance. Based on the passed
* sampling context the decision if transaction is sampled will be taken by {@link TracesSampler}.
*
* @param name the transaction name
* @param operation the operation
* @param customSamplingContext the sampling context
* @return created transaction.
*/
default @NotNull ITransaction startTransaction(
String name, String operation, CustomSamplingContext customSamplingContext) {
return startTransaction(name, operation, customSamplingContext, true);
}
/**
* Creates a Transaction bound to the current hub and returns the instance. Based on the passed
* sampling context the decision if transaction is sampled will be taken by {@link TracesSampler}.
*
* @param name the transaction name
* @param operation the operation
* @param customSamplingContext the sampling context
* @param bindToScope if transaction should be bound to scope
* @return created transaction.
*/
default @NotNull ITransaction startTransaction(
String name,
String operation,
CustomSamplingContext customSamplingContext,
boolean bindToScope) {
return startTransaction(
new TransactionContext(name, operation), customSamplingContext, bindToScope);
}
/**
* Creates a Transaction bound to the current hub and returns the instance. Based on the passed
* transaction and sampling contexts the decision if transaction is sampled will be taken by
* {@link TracesSampler}.
*
* @param transactionContexts the transaction context
* @param customSamplingContext the sampling context
* @return created transaction.
*/
@NotNull
default ITransaction startTransaction(
TransactionContext transactionContexts, CustomSamplingContext customSamplingContext) {
return startTransaction(transactionContexts, customSamplingContext, true);
}
/**
* Creates a Transaction bound to the current hub and returns the instance. Based on the passed
* transaction and sampling contexts the decision if transaction is sampled will be taken by
* {@link TracesSampler}.
*
* @param transactionContexts the transaction context
* @param customSamplingContext the sampling context
* @param bindToScope if transaction should be bound to scope
* @return created transaction.
*/
@NotNull
ITransaction startTransaction(
TransactionContext transactionContexts,
CustomSamplingContext customSamplingContext,
boolean bindToScope);
/**
* Creates a Transaction bound to the current hub 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, null);
}
/**
* Creates a Transaction bound to the current hub 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 bindToScope if transaction should be bound to scope
* @return created transaction
*/
default @NotNull ITransaction startTransaction(
final @NotNull String name, final @NotNull String operation, final boolean bindToScope) {
return startTransaction(name, operation, null, bindToScope);
}
/**
* Returns trace header of active transaction or {@code null} if no transaction is active.
*
* @return trace header or null
*/
@Nullable
SentryTraceHeader traceHeaders();
/**
* Associates {@link ISpan} 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
*/
@ApiStatus.Internal
void setSpanContext(@NotNull Throwable throwable, @NotNull ISpan span);
/**
* Gets the current active transaction or span.
*
* @return the active span or null when no active transaction is running
*/
@Nullable
ISpan getSpan();
/**
* Gets the {@link SentryOptions} attached to current scope.
*
* @return the options attached to current scope.
*/
@NotNull
SentryOptions getOptions();
}