Skip to content

Commit 01ef395

Browse files
refactor: convert OtelRumConfig to kotlin (#1356)
1 parent 61c7701 commit 01ef395

File tree

4 files changed

+166
-194
lines changed

4 files changed

+166
-194
lines changed

core/api/core.api

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@ public final class io/opentelemetry/android/SessionIdRatioBasedSampler : io/open
6262
public fun shouldSample (Lio/opentelemetry/context/Context;Ljava/lang/String;Ljava/lang/String;Lio/opentelemetry/api/trace/SpanKind;Lio/opentelemetry/api/common/Attributes;Ljava/util/List;)Lio/opentelemetry/sdk/trace/samplers/SamplingResult;
6363
}
6464

65-
public class io/opentelemetry/android/config/OtelRumConfig {
65+
public final class io/opentelemetry/android/config/OtelRumConfig {
6666
public fun <init> ()V
67-
public fun allowInstrumentation (Ljava/lang/String;)Lio/opentelemetry/android/config/OtelRumConfig;
68-
public fun disableInstrumentationDiscovery ()Lio/opentelemetry/android/config/OtelRumConfig;
69-
public fun disableNetworkAttributes ()Lio/opentelemetry/android/config/OtelRumConfig;
70-
public fun disableScreenAttributes ()Lio/opentelemetry/android/config/OtelRumConfig;
71-
public fun disableSdkInitializationEvents ()Lio/opentelemetry/android/config/OtelRumConfig;
72-
public fun getDiskBufferingConfig ()Lio/opentelemetry/android/features/diskbuffering/DiskBufferingConfig;
73-
public fun getGlobalAttributesSupplier ()Ljava/util/function/Supplier;
74-
public fun hasGlobalAttributes ()Z
75-
public fun isSuppressed (Ljava/lang/String;)Z
76-
public fun setDiskBufferingConfig (Lio/opentelemetry/android/features/diskbuffering/DiskBufferingConfig;)Lio/opentelemetry/android/config/OtelRumConfig;
77-
public fun setGlobalAttributes (Lio/opentelemetry/api/common/Attributes;)Lio/opentelemetry/android/config/OtelRumConfig;
78-
public fun setGlobalAttributes (Ljava/util/function/Supplier;)Lio/opentelemetry/android/config/OtelRumConfig;
79-
public fun shouldDiscoverInstrumentations ()Z
80-
public fun shouldGenerateSdkInitializationEvents ()Z
81-
public fun shouldIncludeNetworkAttributes ()Z
82-
public fun shouldIncludeScreenAttributes ()Z
83-
public fun suppressInstrumentation (Ljava/lang/String;)Lio/opentelemetry/android/config/OtelRumConfig;
67+
public final fun allowInstrumentation (Ljava/lang/String;)Lio/opentelemetry/android/config/OtelRumConfig;
68+
public final fun disableInstrumentationDiscovery ()Lio/opentelemetry/android/config/OtelRumConfig;
69+
public final fun disableNetworkAttributes ()Lio/opentelemetry/android/config/OtelRumConfig;
70+
public final fun disableScreenAttributes ()Lio/opentelemetry/android/config/OtelRumConfig;
71+
public final fun disableSdkInitializationEvents ()Lio/opentelemetry/android/config/OtelRumConfig;
72+
public final fun getDiskBufferingConfig ()Lio/opentelemetry/android/features/diskbuffering/DiskBufferingConfig;
73+
public final fun getGlobalAttributesSupplier ()Ljava/util/function/Supplier;
74+
public final fun hasGlobalAttributes ()Z
75+
public final fun isSuppressed (Ljava/lang/String;)Z
76+
public final fun setDiskBufferingConfig (Lio/opentelemetry/android/features/diskbuffering/DiskBufferingConfig;)Lio/opentelemetry/android/config/OtelRumConfig;
77+
public final fun setGlobalAttributes (Lio/opentelemetry/api/common/Attributes;)Lio/opentelemetry/android/config/OtelRumConfig;
78+
public final fun setGlobalAttributes (Ljava/util/function/Supplier;)Lio/opentelemetry/android/config/OtelRumConfig;
79+
public final fun shouldDiscoverInstrumentations ()Z
80+
public final fun shouldGenerateSdkInitializationEvents ()Z
81+
public final fun shouldIncludeNetworkAttributes ()Z
82+
public final fun shouldIncludeScreenAttributes ()Z
83+
public final fun suppressInstrumentation (Ljava/lang/String;)Lio/opentelemetry/android/config/OtelRumConfig;
8484
}
8585

8686
public final class io/opentelemetry/android/export/AttributeModifyingSpanExporter : io/opentelemetry/sdk/trace/export/SpanExporter {

core/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java

Lines changed: 0 additions & 160 deletions
This file was deleted.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.android.config
7+
8+
import io.opentelemetry.android.features.diskbuffering.DiskBufferingConfig
9+
import io.opentelemetry.android.features.diskbuffering.DiskBufferingConfig.Companion.create
10+
import io.opentelemetry.api.common.Attributes
11+
import java.util.function.Supplier
12+
13+
/**
14+
* Configuration object for OpenTelemetry Android. The configuration items in this class will be
15+
* used in the OpenTelemetryRumBuilder to wire up and enable/disable various mobile instrumentation
16+
* components.
17+
*/
18+
class OtelRumConfig {
19+
private var globalAttributesSupplierImpl: Supplier<Attributes>? = null
20+
private var includeNetworkAttributes = true
21+
private var generateSdkInitializationEvents = true
22+
private var includeScreenAttributes = true
23+
private var discoverInstrumentations = true
24+
private val suppressedInstrumentations: MutableList<String> = mutableListOf()
25+
private var diskBufferingConfigImpl: DiskBufferingConfig = create()
26+
27+
/**
28+
* Configures the set of global attributes to emit with every span and event. Any existing
29+
* configured attributes will be dropped. Default = none.
30+
*/
31+
fun setGlobalAttributes(attributes: Attributes): OtelRumConfig {
32+
if (attributes.isEmpty) {
33+
return this
34+
}
35+
return setGlobalAttributes { attributes }
36+
}
37+
38+
fun setGlobalAttributes(globalAttributesSupplier: Supplier<Attributes>?): OtelRumConfig {
39+
this.globalAttributesSupplierImpl = globalAttributesSupplier
40+
return this
41+
}
42+
43+
fun hasGlobalAttributes(): Boolean = globalAttributesSupplierImpl != null
44+
45+
fun getGlobalAttributesSupplier(): Supplier<Attributes> = globalAttributesSupplierImpl ?: Supplier { Attributes.empty() }
46+
47+
/**
48+
* Disables the collection of runtime network attributes. See [CurrentNetworkProvider] for
49+
* more information. Default = true.
50+
*
51+
* @return this
52+
*/
53+
fun disableNetworkAttributes(): OtelRumConfig {
54+
includeNetworkAttributes = false
55+
return this
56+
}
57+
58+
/** Returns true if runtime network attributes are enabled, false otherwise. */
59+
fun shouldIncludeNetworkAttributes(): Boolean = includeNetworkAttributes
60+
61+
/**
62+
* Disables the collection of events related to the initialization of the OTel Android SDK
63+
* itself. Default = true.
64+
*
65+
* @return this
66+
*/
67+
fun disableSdkInitializationEvents(): OtelRumConfig {
68+
generateSdkInitializationEvents = false
69+
return this
70+
}
71+
72+
/** Returns true if the SDK is configured to generate initialization events, false otherwise. */
73+
fun shouldGenerateSdkInitializationEvents(): Boolean = generateSdkInitializationEvents
74+
75+
/**
76+
* Call this to disable the collection of screen attributes. See [ ] for more information. Default = true.
77+
*
78+
* @return this
79+
*/
80+
fun disableScreenAttributes(): OtelRumConfig {
81+
includeScreenAttributes = false
82+
return this
83+
}
84+
85+
/** Return true if the SDK should be configured to report screen attributes. */
86+
fun shouldIncludeScreenAttributes(): Boolean = includeScreenAttributes
87+
88+
/**
89+
* Return true if the RUM initialization should look for instrumentations in the
90+
* classpath and apply them automatically.
91+
*/
92+
fun shouldDiscoverInstrumentations(): Boolean = discoverInstrumentations
93+
94+
/**
95+
* Call this to disable the automatic search for instrumentations in the classpath.
96+
*
97+
* @return this
98+
*/
99+
fun disableInstrumentationDiscovery(): OtelRumConfig {
100+
discoverInstrumentations = false
101+
return this
102+
}
103+
104+
/**
105+
* Adds an instrumentation name to the list of suppressed instrumentations. Instrumentations
106+
* that have been suppressed will not be installed at startup.
107+
*/
108+
fun suppressInstrumentation(instrumentationName: String): OtelRumConfig {
109+
suppressedInstrumentations.add(instrumentationName)
110+
return this
111+
}
112+
113+
/**
114+
* Removes an instrumentation name from the list of suppressed instrumentations.
115+
* Instrumentations that have been suppressed will not be installed at startup.
116+
*/
117+
fun allowInstrumentation(instrumentationName: String): OtelRumConfig {
118+
suppressedInstrumentations.remove(instrumentationName)
119+
return this
120+
}
121+
122+
/** Returns false when the given instrumentation has been suppressed. True otherwise. */
123+
fun isSuppressed(instrumentationName: String): Boolean = suppressedInstrumentations.contains(instrumentationName)
124+
125+
fun getDiskBufferingConfig(): DiskBufferingConfig = diskBufferingConfigImpl
126+
127+
/**
128+
* Sets the parameters for caching signals in disk in order to export them later.
129+
*
130+
* @return this
131+
*/
132+
fun setDiskBufferingConfig(diskBufferingConfig: DiskBufferingConfig): OtelRumConfig {
133+
this.diskBufferingConfigImpl = diskBufferingConfig
134+
return this
135+
}
136+
}

0 commit comments

Comments
 (0)