diff --git a/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/OpenTelemetryRum.java b/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/OpenTelemetryRum.java index c8d1a3dc2..0851e7cfa 100644 --- a/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/OpenTelemetryRum.java +++ b/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/OpenTelemetryRum.java @@ -18,6 +18,10 @@ import android.app.Application; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.metrics.SdkMeterProvider; +import io.opentelemetry.sdk.trace.SdkTracerProvider; /** * Entrypoint for the OpenTelemetry Real User Monitoring library for Android. @@ -28,7 +32,10 @@ public interface OpenTelemetryRum { /** - * Returns a new {@link OpenTelemetryRumBuilder} for {@link OpenTelemetryRum}. + * Returns a new {@link OpenTelemetryRumBuilder} for {@link OpenTelemetryRum}. Use this version + * if you would like to configure individual aspects of the OpenTelemetry SDK but would still + * prefer to allow OpenTelemetry RUM to create the SDK for you. If you would like to "bring your + * own" SDK, call the two-argument version. * * @param application The {@link Application} that is being instrumented. */ @@ -36,6 +43,24 @@ static OpenTelemetryRumBuilder builder(Application application) { return new OpenTelemetryRumBuilder(application); } + /** + * Returns a new {@link SdkPreconfiguredRumBuilder} for {@link OpenTelemetryRum}. This version + * requires the user to preconfigure and create their own OpenTelemetrySdk instance. If you + * prefer to use the builder to configure individual aspects of the OpenTelemetry SDK and to + * create and manage it for you, call the one-argument version. + * + *
Specific consideration should be given to the creation of your provided SDK to ensure that
+ * the {@link SdkTracerProvider}, {@link SdkMeterProvider}, and {@link SdkLoggerProvider} are
+ * configured correctly for your target RUM provider.
+ *
+ * @param application The {@link Application} that is being instrumented.
+ * @param openTelemetrySdk The {@link OpenTelemetrySdk} that the user has already created.
+ */
+ static SdkPreconfiguredRumBuilder builder(
+ Application application, OpenTelemetrySdk openTelemetrySdk) {
+ return new SdkPreconfiguredRumBuilder(application, openTelemetrySdk);
+ }
+
/** Returns a no-op implementation of {@link OpenTelemetryRum}. */
static OpenTelemetryRum noop() {
return NoopOpenTelemetryRum.INSTANCE;
diff --git a/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/OpenTelemetryRumBuilder.java b/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/OpenTelemetryRumBuilder.java
index 6c4190392..12d8b7053 100644
--- a/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/OpenTelemetryRumBuilder.java
+++ b/opentelemetry-android-instrumentation/src/main/java/io/opentelemetry/rum/internal/OpenTelemetryRumBuilder.java
@@ -17,7 +17,6 @@
package io.opentelemetry.rum.internal;
import android.app.Application;
-import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.rum.internal.instrumentation.InstrumentedApplication;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
@@ -54,8 +53,8 @@ public final class OpenTelemetryRumBuilder {
private Resource resource;
OpenTelemetryRumBuilder(Application application) {
- SessionIdTimeoutHandler timeoutHandler = new SessionIdTimeoutHandler();
this.application = application;
+ SessionIdTimeoutHandler timeoutHandler = new SessionIdTimeoutHandler();
this.sessionId = new SessionId(timeoutHandler);
this.resource = AndroidResource.createDefault(application);
}
@@ -168,31 +167,17 @@ public SessionId getSessionId() {
* @return A new {@link OpenTelemetryRum} instance.
*/
public OpenTelemetryRum build() {
- // the app state listeners need to be run in the first ActivityLifecycleCallbacks since they
- // might turn off/on additional telemetry depending on whether the app is active or not
- ApplicationStateWatcher applicationStateWatcher = new ApplicationStateWatcher();
- application.registerActivityLifecycleCallbacks(applicationStateWatcher);
-
- applicationStateWatcher.registerListener(sessionId.getTimeoutHandler());
-
- OpenTelemetrySdk openTelemetrySdk =
+ OpenTelemetrySdk sdk =
OpenTelemetrySdk.builder()
.setTracerProvider(buildTracerProvider(sessionId, application))
.setMeterProvider(buildMeterProvider(application))
.setLoggerProvider(buildLoggerProvider(application))
.build();
- Tracer tracer = openTelemetrySdk.getTracer(OpenTelemetryRum.class.getSimpleName());
- sessionId.setSessionIdChangeListener(new SessionIdChangeTracer(tracer));
-
- InstrumentedApplication instrumentedApplication =
- new InstrumentedApplicationImpl(
- application, openTelemetrySdk, applicationStateWatcher);
- for (Consumer This method uses a preconfigured OpenTelemetry SDK and install built-in system
+ * instrumentations in the passed Android {@link Application}.
+ *
+ * @return A new {@link OpenTelemetryRum} instance.
+ */
+ public OpenTelemetryRum build() {
+ // the app state listeners need to be run in the first ActivityLifecycleCallbacks since they
+ // might turn off/on additional telemetry depending on whether the app is active or not
+ ApplicationStateWatcher applicationStateWatcher = new ApplicationStateWatcher();
+ application.registerActivityLifecycleCallbacks(applicationStateWatcher);
+ applicationStateWatcher.registerListener(sessionId.getTimeoutHandler());
+
+ Tracer tracer = sdk.getTracer(OpenTelemetryRum.class.getSimpleName());
+ sessionId.setSessionIdChangeListener(new SessionIdChangeTracer(tracer));
+
+ InstrumentedApplication instrumentedApplication =
+ new InstrumentedApplicationImpl(application, sdk, applicationStateWatcher);
+ for (Consumer