forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentryEvent.java
More file actions
366 lines (311 loc) · 9.25 KB
/
SentryEvent.java
File metadata and controls
366 lines (311 loc) · 9.25 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
package io.sentry;
import io.sentry.protocol.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
public final class SentryEvent extends SentryBaseEvent implements IUnknownPropertiesConsumer {
/**
* Timestamp when the event was created.
*
* <p>Indicates when the event was created in the Sentry SDK. The format is either a string as
* defined in [RFC 3339](https://tools.ietf.org/html/rfc3339) or a numeric (integer or float)
* value representing the number of seconds that have elapsed since the [Unix
* epoch](https://en.wikipedia.org/wiki/Unix_time).
*
* <p>Sub-microsecond precision is not preserved with numeric values due to precision limitations
* with floats (at least in our systems). With that caveat in mind, just send whatever is easiest
* to produce.
*
* <p>All timestamps in the event protocol are formatted this way.
*
* <p>```json { "timestamp": "2011-05-02T17:41:36Z" } { "timestamp": 1304358096.0 } ```
*/
private final Date timestamp;
private Message message;
/**
* Server or device name the event was generated on.
*
* <p>This is supposed to be a hostname.
*/
private String serverName;
/**
* Platform identifier of this event (defaults to "other").
*
* <p>A string representing the platform the SDK is submitting from. This will be used by the
* Sentry interface to customize various components in the interface, but also to enter or skip
* stacktrace processing.
*
* <p>Acceptable values are: `as3`, `c`, `cfml`, `cocoa`, `csharp`, `elixir`, `haskell`, `go`,
* `groovy`, `java`, `javascript`, `native`, `node`, `objc`, `other`, `perl`, `php`, `python`,
* `ruby`
*/
private String platform;
/**
* Program's distribution identifier.
*
* <p>The distribution of the application.
*
* <p>Distributions are used to disambiguate build or deployment variants of the same release of
* an application. For example, the dist can be the build number of an XCode build or the version
* code of an Android build.
*/
private String dist;
/** Logger that created the event. */
private String logger;
/** Threads that were active when the event occurred. */
private SentryValues<SentryThread> threads;
/** One or multiple chained (nested) exceptions. */
private SentryValues<SentryException> exception;
/**
* Severity level of the event. Defaults to `error`.
*
* <p>Example:
*
* <p>```json {"level": "warning"} ```
*/
private SentryLevel level;
/**
* Transaction name of the event.
*
* <p>For example, in a web app, this might be the route name (`"/users/<username>/"` or
* `UserView`), in a task queue it might be the function + module name.
*/
private String transaction;
/** Information about the user who triggered this event. */
private User user;
/**
* Manual fingerprint override.
*
* <p>A list of strings used to dictate how this event is supposed to be grouped with other events
* into issues. For more information about overriding grouping see [Customize Grouping with
* Fingerprints](https://docs.sentry.io/data-management/event-grouping/).
*
* <p>```json { "fingerprint": ["myrpc", "POST", "/foo.bar"] }
*/
private List<String> fingerprint;
/** List of breadcrumbs recorded before this event. */
private List<Breadcrumb> breadcrumbs;
/**
* Arbitrary extra information set by the user.
*
* <p>```json { "extra": { "my_key": 1, "some_other_value": "foo bar" } }```
*/
private Map<String, Object> extra;
private Map<String, Object> unknown;
/**
* Name and versions of all installed modules/packages/dependencies in the current
* environment/application.
*
* <p>```json { "django": "3.0.0", "celery": "4.2.1" } ```
*
* <p>In Python this is a list of installed packages as reported by `pkg_resources` together with
* their reported version string.
*
* <p>This is primarily used for suggesting to enable certain SDK integrations from within the UI
* and for making informed decisions on which frameworks to support in future development efforts.
*/
private Map<String, String> modules;
/** Meta data for event processing and debugging. */
private DebugMeta debugMeta;
SentryEvent(SentryId eventId, final Date timestamp) {
super(eventId);
this.timestamp = timestamp;
}
/**
* SentryEvent ctor with the captured Throwable
*
* @param throwable the Throwable or null
*/
public SentryEvent(final @Nullable Throwable throwable) {
this();
this.throwable = throwable;
}
public SentryEvent() {
this(new SentryId(), DateUtils.getCurrentDateTime());
}
@TestOnly
public SentryEvent(final Date timestamp) {
this(new SentryId(), timestamp);
}
@SuppressWarnings("JdkObsolete")
public Date getTimestamp() {
return (Date) timestamp.clone();
}
public Message getMessage() {
return message;
}
public void setMessage(Message message) {
this.message = message;
}
public String getServerName() {
return serverName;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public String getDist() {
return dist;
}
public void setDist(String dist) {
this.dist = dist;
}
public String getLogger() {
return logger;
}
public void setLogger(String logger) {
this.logger = logger;
}
public List<SentryThread> getThreads() {
if (threads != null) {
return threads.getValues();
} else {
return null;
}
}
public void setThreads(List<SentryThread> threads) {
this.threads = new SentryValues<>(threads);
}
public List<SentryException> getExceptions() {
return exception == null ? null : exception.getValues();
}
public void setExceptions(List<SentryException> exception) {
this.exception = new SentryValues<>(exception);
}
public SentryLevel getLevel() {
return level;
}
public void setLevel(SentryLevel level) {
this.level = level;
}
public String getTransaction() {
return transaction;
}
public void setTransaction(String transaction) {
this.transaction = transaction;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<String> getFingerprints() {
return fingerprint;
}
public void setFingerprints(List<String> fingerprint) {
this.fingerprint = fingerprint;
}
public List<Breadcrumb> getBreadcrumbs() {
return breadcrumbs;
}
public void setBreadcrumbs(List<Breadcrumb> breadcrumbs) {
this.breadcrumbs = breadcrumbs;
}
public void addBreadcrumb(Breadcrumb breadcrumb) {
if (breadcrumbs == null) {
breadcrumbs = new ArrayList<>();
}
breadcrumbs.add(breadcrumb);
}
public void addBreadcrumb(final @Nullable String message) {
this.addBreadcrumb(new Breadcrumb(message));
}
Map<String, Object> getExtras() {
return extra;
}
public void setExtras(Map<String, Object> extra) {
this.extra = extra;
}
public void setExtra(String key, Object value) {
if (extra == null) {
extra = new HashMap<>();
}
extra.put(key, value);
}
public void removeExtra(@NotNull String key) {
if (extra != null) {
extra.remove(key);
}
}
public @Nullable Object getExtra(final @NotNull String key) {
if (extra != null) {
return extra.get(key);
}
return null;
}
@ApiStatus.Internal
@Override
public void acceptUnknownProperties(Map<String, Object> unknown) {
this.unknown = unknown;
}
@TestOnly
public Map<String, Object> getUnknown() {
return unknown;
}
Map<String, String> getModules() {
return modules;
}
public void setModules(Map<String, String> modules) {
this.modules = modules;
}
public void setModule(String key, String value) {
if (modules == null) {
modules = new HashMap<>();
}
modules.put(key, value);
}
public void removeModule(@NotNull String key) {
if (modules != null) {
modules.remove(key);
}
}
public @Nullable String getModule(final @NotNull String key) {
if (modules != null) {
return modules.get(key);
}
return null;
}
public DebugMeta getDebugMeta() {
return debugMeta;
}
public void setDebugMeta(DebugMeta debugMeta) {
this.debugMeta = debugMeta;
}
/**
* Returns true if any exception was unhandled by the user.
*
* @return true if its crashed or false otherwise
*/
public boolean isCrashed() {
if (exception != null) {
for (SentryException e : exception.getValues()) {
if (e.getMechanism() != null
&& e.getMechanism().isHandled() != null
&& !e.getMechanism().isHandled()) {
return true;
}
}
}
return false;
}
/**
* Returns true if this event has any sort of exception
*
* @return true if errored or false otherwise
*/
public boolean isErrored() {
return exception != null && !exception.getValues().isEmpty();
}
}