-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathConfigBuilder.java
More file actions
779 lines (698 loc) · 21.1 KB
/
Copy pathConfigBuilder.java
File metadata and controls
779 lines (698 loc) · 21.1 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
package com.rollbar.reactivestreams.notifier.config;
import com.rollbar.api.payload.data.Client;
import com.rollbar.api.payload.data.Level;
import com.rollbar.api.payload.data.Notifier;
import com.rollbar.api.payload.data.Person;
import com.rollbar.api.payload.data.Request;
import com.rollbar.api.payload.data.Server;
import com.rollbar.notifier.Rollbar;
import com.rollbar.notifier.config.DefaultLevels;
import com.rollbar.notifier.filter.Filter;
import com.rollbar.notifier.fingerprint.FingerprintGenerator;
import com.rollbar.notifier.provider.Provider;
import com.rollbar.notifier.provider.notifier.NotifierProvider;
import com.rollbar.notifier.provider.timestamp.TimestampProvider;
import com.rollbar.notifier.sender.SyncSender;
import com.rollbar.notifier.sender.json.JsonSerializer;
import com.rollbar.notifier.telemetry.RollbarTelemetryEventTracker;
import com.rollbar.notifier.telemetry.TelemetryEventTracker;
import com.rollbar.notifier.transformer.Transformer;
import com.rollbar.notifier.uuid.UuidGenerator;
import com.rollbar.reactivestreams.notifier.sender.AsyncSender;
import com.rollbar.reactivestreams.notifier.sender.Sender;
import com.rollbar.reactivestreams.notifier.sender.http.AsyncHttpClient;
import com.rollbar.reactivestreams.notifier.sender.http.AsyncHttpClientFactory;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Configuration builder to build the {@link Config configuration} of the {@link Rollbar rollbar}
* notifier.
*/
public final class ConfigBuilder {
private String accessToken;
private String endpoint;
private String environment;
private String codeVersion;
private String platform;
private String language;
private String framework;
private Provider<String> context;
private Provider<Request> request;
private Provider<Person> person;
private Provider<Server> server;
private Provider<Client> client;
private Provider<Map<String, Object>> custom;
private Provider<Notifier> notifier;
private Provider<Long> timestamp;
private Filter filter;
private Transformer transformer;
private FingerprintGenerator fingerPrintGenerator;
private UuidGenerator uuidGenerator;
private AsyncHttpClient httpClient;
private Sender asyncSender;
private JsonSerializer jsonSerializer;
private List<String> appPackages;
private boolean handleUncaughtErrors;
private boolean enabled;
private DefaultLevels defaultLevels;
private boolean truncateLargePayloads;
private boolean compressPayload;
private int maximumTelemetryData =
RollbarTelemetryEventTracker.MAXIMUM_CAPACITY_FOR_TELEMETRY_EVENTS;
private TelemetryEventTracker telemetryEventTracker;
/**
* Constructor with an access token.
*/
protected ConfigBuilder(String accessToken) {
// Defaults
this.accessToken = accessToken;
this.handleUncaughtErrors = true;
this.enabled = true;
this.compressPayload = true;
this.defaultLevels = new DefaultLevels();
}
/**
* Constructor from another Config.
*/
private ConfigBuilder(Config config) {
this.accessToken = config.accessToken();
this.environment = config.environment();
this.codeVersion = config.codeVersion();
this.platform = config.platform();
this.language = config.language();
this.framework = config.framework();
this.context = config.context();
this.request = config.request();
this.person = config.person();
this.server = config.server();
this.client = config.client();
this.custom = config.custom();
this.notifier = config.notifier();
this.timestamp = config.timestamp();
this.filter = config.filter();
this.transformer = config.transformer();
this.fingerPrintGenerator = config.fingerPrintGenerator();
this.uuidGenerator = config.uuidGenerator();
this.asyncSender = config.asyncSender();
this.handleUncaughtErrors = config.handleUncaughtErrors();
this.enabled = config.isEnabled();
this.endpoint = config.endpoint();
this.appPackages = config.appPackages();
this.defaultLevels = new DefaultLevels(config);
this.truncateLargePayloads = config.truncateLargePayloads();
this.compressPayload = config.compressPayload();
this.maximumTelemetryData = config.maximumTelemetryData();
this.telemetryEventTracker = config.telemetryEventTracker();
}
private ConfigBuilder(Sender sender) {
this((String)null);
this.asyncSender = sender;
}
/**
* Initializes a config builder instance with the access token supplied.
* @param accessToken the access token.
* @return the builder instance.
*/
public static ConfigBuilder withAccessToken(String accessToken) {
return new ConfigBuilder(accessToken);
}
/**
* Initializes a config builder instance with the sender supplied.
* @param sender the AsyncSender
* @return the builder instance.
*/
public static ConfigBuilder withSender(Sender sender) {
return new ConfigBuilder(sender);
}
/**
* Initializes a config builder instance with the values set in the supplied config.
* @param config an object conforming to the {@link Config} interface.
* @return the builder instance.
*/
public static ConfigBuilder withConfig(Config config) {
return new ConfigBuilder(config);
}
/**
* The access token to use.
*
* @param accessToken the access token.
* @return the builder instance.
*/
public ConfigBuilder accessToken(String accessToken) {
this.accessToken = accessToken;
return this;
}
/**
* The Rollbar endpoint to use.
*
* @param endpoint the Rollbar endpoint url.
* @return the builder instance.
*/
public ConfigBuilder endpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}
/**
* Represents the current environment (e.g.: production, debug, test).
*
* @param environment the environment.
* @return the builder instance.
*/
public ConfigBuilder environment(String environment) {
this.environment = environment;
return this;
}
/**
* The currently running version of the code.
*
* @param codeVersion the code version.
* @return the builder instance.
*/
public ConfigBuilder codeVersion(String codeVersion) {
this.codeVersion = codeVersion;
return this;
}
/**
* The platform running (most likely JVM and a version).
*
* @param platform the platform.
* @return the builder instance.
*/
public ConfigBuilder platform(String platform) {
this.platform = platform;
return this;
}
/**
* The language running (most likely java, but any JVM language might be here).
*
* @param language the language.
* @return the builder instance.
*/
public ConfigBuilder language(String language) {
this.language = language;
return this;
}
/**
* The framework being run (e.g. Play, Spring, etc).
*
* @param framework the framework.
* @return the builder instance.
*/
public ConfigBuilder framework(String framework) {
this.framework = framework;
return this;
}
/**
* The provider to retrieve the context.
*
* @param context the context provider.
* @return the builder instance.
*/
public ConfigBuilder context(Provider<String> context) {
this.context = context;
return this;
}
/**
* The provider to retrieve the {@link Request request}.
*
* @param request the request provider.
* @return the builder instance.
*/
public ConfigBuilder request(Provider<Request> request) {
this.request = request;
return this;
}
/**
* The provider to retrieve the {@link Person person}.
*
* @param person the person provider.
* @return the builder instance.
*/
public ConfigBuilder person(Provider<Person> person) {
this.person = person;
return this;
}
/**
* The provider to retrieve the {@link Server server}.
*
* @param server the server provider.
* @return the builder instance.
*/
public ConfigBuilder server(Provider<Server> server) {
this.server = server;
return this;
}
/**
* The provider to retrieve the {@link Client client}.
*
* @param client the client provider.
* @return the builder instance.
*/
public ConfigBuilder client(Provider<Client> client) {
this.client = client;
return this;
}
/**
* The provider to retrieve the custom.
*
* @param custom the custom provider.
* @return the builder instance.
*/
public ConfigBuilder custom(Provider<Map<String, Object>> custom) {
this.custom = custom;
return this;
}
/**
* The provider to retrieve the {@link Notifier notifier}.
*
* @param notifier the notifier provider.
* @return the builder instance.
*/
public ConfigBuilder notifier(Provider<Notifier> notifier) {
this.notifier = notifier;
return this;
}
/**
* The provider to retrieve the timestamp.
*
* @param timestamp the timestamp.
* @return the builder instance.
*/
public ConfigBuilder timestamp(Provider<Long> timestamp) {
this.timestamp = timestamp;
return this;
}
/**
* The provider to retrieve the {@link Filter filter}.
*
* @param filter the filter provider.
* @return the builder instance.
*/
public ConfigBuilder filter(Filter filter) {
this.filter = filter;
return this;
}
/**
* The provider to retrieve the {@link Transformer transformer}.
*
* @param transformer the transformer provider.
* @return the builder instance.
*/
public ConfigBuilder transformer(Transformer transformer) {
this.transformer = transformer;
return this;
}
/**
* The provider to retrieve the {@link FingerprintGenerator fingerprint generator}.
*
* @param fingerPrintGenerator the fingerprint generator provider.
* @return the builder instance.
*/
public ConfigBuilder fingerPrintGenerator(FingerprintGenerator fingerPrintGenerator) {
this.fingerPrintGenerator = fingerPrintGenerator;
return this;
}
/**
* The provider to retrieve the {@link UuidGenerator uuid generator}.
*
* @param uuidGenerator the uuid generator provider.
* @return the builder instance.
*/
public ConfigBuilder uuidGenerator(UuidGenerator uuidGenerator) {
this.uuidGenerator = uuidGenerator;
return this;
}
/**
* The {@link AsyncHttpClient HTTP client}.
*
* @param httpClient the HTTP client.
* @return the builder instance.
*/
public ConfigBuilder httpClient(AsyncHttpClient httpClient) {
this.httpClient = httpClient;
return this;
}
/**
* The {@link Sender sender}.
* <p>
* Note: Setting the sender overrides the {@link #httpClient(AsyncHttpClient)} and
* {@link #accessToken(String)} settings.
* </p>
* @param sender the sender.
* @return the builder instance.
*/
public ConfigBuilder sender(Sender sender) {
this.asyncSender = sender;
return this;
}
/**
* The JsonSerializer to use with the default Sender if no other
* sender is specified. If a sender is specified then this
* parameter is ignored.
*
* @param jsonSerializer the json serializer.
* @return the builder instance.
*/
public ConfigBuilder jsonSerializer(JsonSerializer jsonSerializer) {
this.jsonSerializer = jsonSerializer;
return this;
}
/**
* The list of packages to be considered in your app.
*
* @param appPackages the list of packages.
* @return the builder instance.
*/
public ConfigBuilder appPackages(List<String> appPackages) {
this.appPackages = appPackages;
return this;
}
/**
* Flag to set the default handler for uncaught errors,
* see {@link UncaughtExceptionHandler}.
*
* @param handleUncaughtErrors true to handle uncaught errors otherwise false.
* @return the builder instance.
*/
public ConfigBuilder handleUncaughtErrors(boolean handleUncaughtErrors) {
this.handleUncaughtErrors = handleUncaughtErrors;
return this;
}
/**
* Flag to indicate that the Rollbar notifier should enabled/disabled.
*
* @param enabled true to enable the notifier.
* @return the builder instance.
*/
public ConfigBuilder enabled(boolean enabled) {
this.enabled = enabled;
return this;
}
/**
* Level to use as the default for messages if one is not otherwise specified.
*
* @param level the level.
* @return the builder instance.
*/
public ConfigBuilder defaultMessageLevel(Level level) {
this.defaultLevels.setMessage(level);
return this;
}
/**
* Level to use as the default for Errors if one is not otherwise specified.
*
* @param level the level.
* @return the builder instance.
*/
public ConfigBuilder defaultErrorLevel(Level level) {
this.defaultLevels.setError(level);
return this;
}
/**
* Level to use as the default for non-Error Throwables if one is not otherwise specified.
*
* @param level the level.
* @return the builder instance.
*/
public ConfigBuilder defaultThrowableLevel(Level level) {
this.defaultLevels.setThrowable(level);
return this;
}
/**
* <p>
* If set to true, the notifier will attempt to truncate payloads that are larger than the
* maximum size Rollbar allows. Default: false.
* </p>
* @param truncate true to enable truncation.
* @return the builder instance.
*/
public ConfigBuilder truncateLargePayloads(boolean truncate) {
this.truncateLargePayloads = truncate;
return this;
}
/**
* <p>
* If set to false, payloads will not be gzip-compressed before sending. Default: true.
* </p>
* @param compress true to gzip-compress payloads.
* @return the builder instance.
*/
public ConfigBuilder compressPayload(boolean compress) {
this.compressPayload = compress;
return this;
}
/**
* <p>
* Maximum Telemetry events sent in a payload, only for the default TelemetryEventTracker, if
* a custom implementation is used this value will be ignored. Default is
* {@value RollbarTelemetryEventTracker#MAXIMUM_CAPACITY_FOR_TELEMETRY_EVENTS}.
* </p>
* @param maximumTelemetryData max quantity of telemetry events sent.
* @return the builder instance.
*/
public ConfigBuilder maximumTelemetryData(int maximumTelemetryData) {
this.maximumTelemetryData = maximumTelemetryData;
return this;
}
/**
* <p>
* Set a {@link TelemetryEventTracker} implementation.
* Default: {@link RollbarTelemetryEventTracker} with a {@link TimestampProvider}.
* </p>
* @param telemetryEventTracker the TelemetryEventTracker implementation.
* @return the builder instance.
*/
public ConfigBuilder telemetryEventTracker(TelemetryEventTracker telemetryEventTracker) {
this.telemetryEventTracker = telemetryEventTracker;
return this;
}
/**
* Builds the {@link Config config}.
*
* @return the config.
*/
public Config build() {
if (this.language == null) {
this.language = "java";
}
if (this.endpoint == null) {
this.endpoint = SyncSender.DEFAULT_API_ENDPOINT;
}
if (this.notifier == null) {
this.notifier = new NotifierProvider();
}
if (this.asyncSender == null) {
AsyncHttpClient httpClient = this.httpClient;
if (httpClient == null) {
httpClient = AsyncHttpClientFactory.defaultClient();
}
AsyncSender.Builder senderBuilder = new AsyncSender.Builder(httpClient, this.endpoint)
.accessToken(accessToken)
.compressPayload(this.compressPayload);
if (this.jsonSerializer != null) {
senderBuilder.jsonSerializer(this.jsonSerializer);
}
this.asyncSender = senderBuilder.build();
}
if (this.timestamp == null) {
this.timestamp = new TimestampProvider();
}
if (telemetryEventTracker == null) {
telemetryEventTracker =
new RollbarTelemetryEventTracker(new TimestampProvider(), maximumTelemetryData);
}
return new ConfigImpl(this);
}
private static class ConfigImpl implements Config {
private final String accessToken;
private final String endpoint;
private final String environment;
private final String codeVersion;
private final String platform;
private final String language;
private final String framework;
private final Provider<String> context;
private final Provider<Request> request;
private final Provider<Person> person;
private final Provider<Server> server;
private final Provider<Client> client;
private final Provider<Map<String, Object>> custom;
private final Provider<Notifier> notifier;
private final Provider<Long> timestamp;
private final Filter filter;
private final Transformer transformer;
private final FingerprintGenerator fingerPrintGenerator;
private final UuidGenerator uuidGenerator;
private final Sender asyncSender;
private final List<String> appPackages;
private final boolean handleUncaughtErrors;
private final boolean enabled;
private final DefaultLevels defaultLevels;
private final JsonSerializer jsonSerializer;
private final boolean truncateLargePayloads;
private final boolean compressPayload;
private final int maximumTelemetryData;
private final TelemetryEventTracker telemetryEventTracker;
ConfigImpl(ConfigBuilder builder) {
this.accessToken = builder.accessToken;
this.endpoint = builder.endpoint;
this.environment = builder.environment;
this.codeVersion = builder.codeVersion;
this.platform = builder.platform;
this.language = builder.language;
this.framework = builder.framework;
this.context = builder.context;
this.request = builder.request;
this.person = builder.person;
this.server = builder.server;
this.client = builder.client;
this.custom = builder.custom;
this.notifier = builder.notifier;
this.timestamp = builder.timestamp;
this.filter = builder.filter;
this.transformer = builder.transformer;
this.fingerPrintGenerator = builder.fingerPrintGenerator;
this.uuidGenerator = builder.uuidGenerator;
this.asyncSender = builder.asyncSender;
if (builder.appPackages == null) {
this.appPackages = Collections.emptyList();
} else {
this.appPackages = builder.appPackages;
}
this.handleUncaughtErrors = builder.handleUncaughtErrors;
this.enabled = builder.enabled;
this.defaultLevels = builder.defaultLevels;
this.jsonSerializer = builder.jsonSerializer;
this.truncateLargePayloads = builder.truncateLargePayloads;
this.compressPayload = builder.compressPayload;
this.maximumTelemetryData = builder.maximumTelemetryData;
this.telemetryEventTracker = builder.telemetryEventTracker;
}
@Override
public String accessToken() {
return accessToken;
}
@Override
public String endpoint() {
return endpoint;
}
@Override
public String environment() {
return environment;
}
@Override
public String codeVersion() {
return codeVersion;
}
@Override
public String platform() {
return platform;
}
@Override
public String language() {
return language;
}
@Override
public String framework() {
return framework;
}
@Override
public Provider<String> context() {
return context;
}
@Override
public Provider<Request> request() {
return request;
}
@Override
public Provider<Person> person() {
return person;
}
@Override
public Provider<Server> server() {
return server;
}
@Override
public Provider<Client> client() {
return client;
}
@Override
public Provider<Map<String, Object>> custom() {
return custom;
}
@Override
public Provider<Notifier> notifier() {
return notifier;
}
@Override
public Provider<Long> timestamp() {
return timestamp;
}
@Override
public Filter filter() {
return filter;
}
@Override
public Transformer transformer() {
return transformer;
}
@Override
public FingerprintGenerator fingerPrintGenerator() {
return fingerPrintGenerator;
}
@Override
public UuidGenerator uuidGenerator() {
return uuidGenerator;
}
@Override
public JsonSerializer jsonSerializer() {
return jsonSerializer;
}
@Override
public Sender asyncSender() {
return asyncSender;
}
@Override
public List<String> appPackages() {
return appPackages;
}
@Override
public boolean handleUncaughtErrors() {
return handleUncaughtErrors;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public Level defaultMessageLevel() {
return defaultLevels.getMessage();
}
@Override
public Level defaultErrorLevel() {
return defaultLevels.getError();
}
@Override
public Level defaultThrowableLevel() {
return defaultLevels.getThrowable();
}
@Override
public boolean truncateLargePayloads() {
return truncateLargePayloads;
}
@Override
public boolean compressPayload() {
return compressPayload;
}
@Override
public int maximumTelemetryData() {
return this.maximumTelemetryData;
}
@Override
public TelemetryEventTracker telemetryEventTracker() {
return this.telemetryEventTracker;
}
}
}