-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathOtelRumConfig.java
192 lines (165 loc) · 6.3 KB
/
OtelRumConfig.java
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
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.android.config;
import io.opentelemetry.android.ScreenAttributesSpanProcessor;
import io.opentelemetry.android.features.diskbuffering.DiskBufferingConfiguration;
import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider;
import io.opentelemetry.api.common.Attributes;
import java.time.Duration;
import java.util.function.Supplier;
/**
* Configuration object for OpenTelemetry Android. The configuration items in this class will be
* used in the OpenTelemetryRumBuilder to wire up and enable/disable various mobile instrumentation
* components.
*/
public class OtelRumConfig {
private static final Duration DEFAULT_SLOW_RENDERING_DETECTION_POLL_INTERVAL =
Duration.ofSeconds(1);
private Supplier<Attributes> globalAttributesSupplier = Attributes::empty;
private boolean includeNetworkAttributes = true;
private boolean generateSdkInitializationEvents = true;
private boolean includeScreenAttributes = true;
private DiskBufferingConfiguration diskBufferingConfiguration =
DiskBufferingConfiguration.builder().build();
private boolean networkChangeMonitoringEnabled = true;
private boolean anrDetectionEnabled = true;
private boolean slowRenderingDetectionEnabled = true;
private Duration slowRenderingDetectionPollInterval =
DEFAULT_SLOW_RENDERING_DETECTION_POLL_INTERVAL;
private boolean crashReportingEnabled = true;
/**
* Configures the set of global attributes to emit with every span and event. Any existing
* configured attributes will be dropped. Default = none.
*/
public OtelRumConfig setGlobalAttributes(Attributes attributes) {
return setGlobalAttributes(() -> attributes);
}
public OtelRumConfig setGlobalAttributes(Supplier<Attributes> globalAttributesSupplier) {
this.globalAttributesSupplier = globalAttributesSupplier;
return this;
}
public boolean hasGlobalAttributes() {
Attributes attributes = globalAttributesSupplier.get();
return attributes != null && !attributes.isEmpty();
}
public Supplier<Attributes> getGlobalAttributesSupplier() {
return globalAttributesSupplier;
}
/**
* Disables the collection of runtime network attributes. See {@link CurrentNetworkProvider} for
* more information. Default = true.
*
* @return this
*/
public OtelRumConfig disableNetworkAttributes() {
includeNetworkAttributes = false;
return this;
}
/** Returns true if runtime network attributes are enabled, false otherwise. */
public boolean shouldIncludeNetworkAttributes() {
return includeNetworkAttributes;
}
/**
* Disables the collection of events related to the initialization of the OTel Android SDK
* itself. Default = true.
*
* @return this
*/
public OtelRumConfig disableSdkInitializationEvents() {
generateSdkInitializationEvents = false;
return this;
}
/** Returns true if the SDK is configured to generate initialization events, false otherwise. */
public boolean shouldGenerateSdkInitializationEvents() {
return generateSdkInitializationEvents;
}
/**
* Call this to disable the collection of screen attributes. See {@link
* ScreenAttributesSpanProcessor} for more information. Default = true.
*
* @return this
*/
public OtelRumConfig disableScreenAttributes() {
includeScreenAttributes = false;
return this;
}
/** Return true if the SDK should be configured to report screen attributes. */
public boolean shouldIncludeScreenAttributes() {
return includeScreenAttributes;
}
public DiskBufferingConfiguration getDiskBufferingConfiguration() {
return diskBufferingConfiguration;
}
/**
* Sets the parameters for caching signals in disk in order to export them later.
*
* @return this
*/
public OtelRumConfig setDiskBufferingConfiguration(
DiskBufferingConfiguration diskBufferingConfiguration) {
this.diskBufferingConfiguration = diskBufferingConfiguration;
return this;
}
/**
* Sets the configuration so that network change monitoring, which is enabled by default, will
* not be started.
*/
public OtelRumConfig disableNetworkChangeMonitoring() {
networkChangeMonitoringEnabled = false;
return this;
}
/** Returns true if network change monitoring is enabled (default = true). */
public boolean isNetworkChangeMonitoringEnabled() {
return networkChangeMonitoringEnabled;
}
/** Returns true if ANR (application not responding) detection is enabled (default = true). */
public boolean isAnrDetectionEnabled() {
return anrDetectionEnabled;
}
/**
* Call this method to disable ANR (application not responding) detection.
*
* @return this
*/
public OtelRumConfig disableAnrDetection() {
anrDetectionEnabled = false;
return this;
}
/** Returns true if the slow rendering detection instrumentation is enabled. */
public boolean isSlowRenderingDetectionEnabled() {
return slowRenderingDetectionEnabled;
}
/**
* Call this method to disable the slow rendering detection instrumentation.
*
* @return this
*/
public OtelRumConfig disableSlowRenderingDetection() {
slowRenderingDetectionEnabled = false;
return this;
}
/** Returns the Duration at which slow renders are polled. Default = 1s. */
public Duration getSlowRenderingDetectionPollInterval() {
return slowRenderingDetectionPollInterval;
}
/**
* Call this to configure the duration for polling for slow renders.
*
* @return this
*/
public OtelRumConfig setSlowRenderingDetectionPollInterval(Duration duration) {
slowRenderingDetectionPollInterval = duration;
return this;
}
/** Returns true if crash reporting is enabled. */
public boolean isCrashReportingEnabled() {
return crashReportingEnabled;
}
/** Call this method to disable crash reporting. */
public OtelRumConfig disableCrashReporting() {
crashReportingEnabled = false;
return this;
}
}