Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax install arg from OpenTelemetryRum to OpenTelemetry instance. #661

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SdkPreconfiguredRumBuilder

// Install instrumentations
for (instrumentation in getInstrumentations()) {
instrumentation.install(application, openTelemetryRum)
instrumentation.install(application, openTelemetryRum.openTelemetry)
}

return openTelemetryRum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package io.opentelemetry.android.instrumentation

import android.app.Application
import io.opentelemetry.android.OpenTelemetryRum
import io.opentelemetry.api.OpenTelemetry

/**
* This interface defines a tool that automatically generates telemetry for a specific use-case,
Expand All @@ -30,10 +31,10 @@ interface AndroidInstrumentation {
* to use for generating telemetry.
*
* @param application The Android application being instrumented.
* @param openTelemetryRum The [OpenTelemetryRum] instance to use for creating signals.
* @param openTelemetry The [OpenTelemetry] instance to use for creating signals.
*/
fun install(
application: Application,
openTelemetryRum: OpenTelemetryRum,
openTelemetry: OpenTelemetry,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
package io.opentelemetry.android.instrumentation

import android.app.Application
import io.opentelemetry.android.OpenTelemetryRum
import io.opentelemetry.api.OpenTelemetry

class TestAndroidInstrumentation : AndroidInstrumentation {
var installed = false
private set

override fun install(
application: Application,
openTelemetryRum: OpenTelemetryRum,
openTelemetry: OpenTelemetry,
) {
installed = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ package io.opentelemetry.android.instrumentation.activity
import android.app.Application
import android.os.Build
import com.google.auto.service.AutoService
import io.opentelemetry.android.OpenTelemetryRum
import io.opentelemetry.android.instrumentation.AndroidInstrumentation
import io.opentelemetry.android.instrumentation.activity.startup.AppStartupTimer
import io.opentelemetry.android.instrumentation.common.Constants.INSTRUMENTATION_SCOPE
import io.opentelemetry.android.instrumentation.common.ScreenNameExtractor
import io.opentelemetry.android.internal.services.ServiceManager
import io.opentelemetry.android.internal.services.visiblescreen.activities.DefaultingActivityLifecycleCallbacks
import io.opentelemetry.api.OpenTelemetry
import io.opentelemetry.api.trace.Tracer

@AutoService(AndroidInstrumentation::class)
Expand All @@ -33,16 +33,16 @@ class ActivityLifecycleInstrumentation : AndroidInstrumentation {

override fun install(
application: Application,
openTelemetryRum: OpenTelemetryRum,
openTelemetry: OpenTelemetry,
) {
startupTimer.start(openTelemetryRum.openTelemetry.getTracer(INSTRUMENTATION_SCOPE))
startupTimer.start(openTelemetry.getTracer(INSTRUMENTATION_SCOPE))
application.registerActivityLifecycleCallbacks(startupTimer.createLifecycleCallback())
application.registerActivityLifecycleCallbacks(buildActivityLifecycleTracer(openTelemetryRum))
application.registerActivityLifecycleCallbacks(buildActivityLifecycleTracer(openTelemetry))
}

private fun buildActivityLifecycleTracer(openTelemetryRum: OpenTelemetryRum): DefaultingActivityLifecycleCallbacks {
private fun buildActivityLifecycleTracer(openTelemetry: OpenTelemetry): DefaultingActivityLifecycleCallbacks {
val visibleScreenService = ServiceManager.get().getVisibleScreenService()
val delegateTracer: Tracer = openTelemetryRum.openTelemetry.getTracer(INSTRUMENTATION_SCOPE)
val delegateTracer: Tracer = openTelemetry.getTracer(INSTRUMENTATION_SCOPE)
val tracers =
ActivityTracerCache(
tracerCustomizer.invoke(delegateTracer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class ActivityInstrumentationTest {
fun setUp() {
application = RuntimeEnvironment.getApplication()
openTelemetry = mockk()
openTelemetryRum = mockk()
every { openTelemetryRum.openTelemetry }.returns(openTelemetry)
activityLifecycleInstrumentation = ActivityLifecycleInstrumentation()

Companion.initialize(application)
Expand All @@ -54,7 +52,7 @@ class ActivityInstrumentationTest {
)
every { startupSpanBuilder.startSpan() }.returns(startupSpan)

activityLifecycleInstrumentation.install(application, openTelemetryRum)
activityLifecycleInstrumentation.install(application, openTelemetry)

verify {
tracer.spanBuilder("AppStart")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import android.os.Looper;
import androidx.annotation.NonNull;
import com.google.auto.service.AutoService;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.instrumentation.AndroidInstrumentation;
import io.opentelemetry.android.internal.services.ServiceManager;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -47,15 +47,14 @@ AnrInstrumentation setScheduler(ScheduledExecutorService scheduler) {
}

@Override
public void install(
@NonNull Application application, @NonNull OpenTelemetryRum openTelemetryRum) {
public void install(@NonNull Application application, @NonNull OpenTelemetry openTelemetry) {
AnrDetector anrDetector =
new AnrDetector(
additionalExtractors,
mainLooper,
scheduler,
ServiceManager.get().getAppLifecycleService(),
openTelemetryRum.getOpenTelemetry());
openTelemetry);
anrDetector.start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import android.app.Application;
import androidx.annotation.NonNull;
import com.google.auto.service.AutoService;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.RuntimeDetailsExtractor;
import io.opentelemetry.android.instrumentation.AndroidInstrumentation;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import java.util.ArrayList;
Expand All @@ -28,10 +28,9 @@ public void addAttributesExtractor(AttributesExtractor<CrashDetails, Void> extra
}

@Override
public void install(
@NonNull Application application, @NonNull OpenTelemetryRum openTelemetryRum) {
public void install(@NonNull Application application, @NonNull OpenTelemetry openTelemetry) {
addAttributesExtractor(RuntimeDetailsExtractor.create(application));
CrashReporter crashReporter = new CrashReporter(additionalExtractors);
crashReporter.install((OpenTelemetrySdk) openTelemetryRum.getOpenTelemetry());
crashReporter.install((OpenTelemetrySdk) openTelemetry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor.constant;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
Expand Down Expand Up @@ -58,12 +55,9 @@ public void tearDown() {

@Test
public void integrationTest() throws InterruptedException {
OpenTelemetryRum openTelemetryRum = mock();
when(openTelemetryRum.getOpenTelemetry()).thenReturn(openTelemetrySdk);

CrashReporterInstrumentation instrumentation = new CrashReporterInstrumentation();
instrumentation.addAttributesExtractor(constant(stringKey("test.key"), "abc"));
instrumentation.install(RuntimeEnvironment.getApplication(), openTelemetryRum);
instrumentation.install(RuntimeEnvironment.getApplication(), openTelemetrySdk);

String exceptionMessage = "boooom!";
RuntimeException crash = new RuntimeException(exceptionMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import android.app.Application
import android.app.Application.ActivityLifecycleCallbacks
import android.os.Build
import com.google.auto.service.AutoService
import io.opentelemetry.android.OpenTelemetryRum
import io.opentelemetry.android.instrumentation.AndroidInstrumentation
import io.opentelemetry.android.instrumentation.common.Constants.INSTRUMENTATION_SCOPE
import io.opentelemetry.android.instrumentation.common.ScreenNameExtractor
import io.opentelemetry.android.internal.services.ServiceManager
import io.opentelemetry.android.internal.services.visiblescreen.fragments.RumFragmentActivityRegisterer
import io.opentelemetry.api.OpenTelemetry
import io.opentelemetry.api.trace.Tracer

@AutoService(AndroidInstrumentation::class)
Expand All @@ -32,14 +32,14 @@ class FragmentLifecycleInstrumentation : AndroidInstrumentation {

override fun install(
application: Application,
openTelemetryRum: OpenTelemetryRum,
openTelemetry: OpenTelemetry,
) {
application.registerActivityLifecycleCallbacks(buildFragmentRegisterer(openTelemetryRum))
application.registerActivityLifecycleCallbacks(buildFragmentRegisterer(openTelemetry))
}

private fun buildFragmentRegisterer(openTelemetryRum: OpenTelemetryRum): ActivityLifecycleCallbacks {
private fun buildFragmentRegisterer(openTelemetry: OpenTelemetry): ActivityLifecycleCallbacks {
val visibleScreenService = ServiceManager.get().getVisibleScreenService()
val delegateTracer: Tracer = openTelemetryRum.openTelemetry.getTracer(INSTRUMENTATION_SCOPE)
val delegateTracer: Tracer = openTelemetry.getTracer(INSTRUMENTATION_SCOPE)
val fragmentLifecycle =
RumFragmentLifecycleCallbacks(
tracerCustomizer.invoke(delegateTracer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import android.app.Application;
import com.google.auto.service.AutoService;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.instrumentation.AndroidInstrumentation;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceResolver;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.library.httpurlconnection.internal.HttpUrlConnectionSingletons;
Expand Down Expand Up @@ -123,9 +123,8 @@ public boolean emitExperimentalHttpClientMetrics() {
}

@Override
public void install(
@NotNull Application application, @NotNull OpenTelemetryRum openTelemetryRum) {
HttpUrlConnectionSingletons.configure(this, openTelemetryRum.getOpenTelemetry());
public void install(@NotNull Application application, @NotNull OpenTelemetry openTelemetry) {
HttpUrlConnectionSingletons.configure(this, openTelemetry);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import android.app.Application;
import androidx.annotation.NonNull;
import com.google.auto.service.AutoService;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.instrumentation.AndroidInstrumentation;
import io.opentelemetry.android.internal.services.ServiceManager;
import io.opentelemetry.android.internal.services.network.data.CurrentNetwork;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -31,11 +31,10 @@ public NetworkChangeInstrumentation addAttributesExtractor(
}

@Override
public void install(
@NonNull Application application, @NonNull OpenTelemetryRum openTelemetryRum) {
public void install(@NonNull Application application, @NonNull OpenTelemetry openTelemetry) {
NetworkChangeMonitor networkChangeMonitor =
new NetworkChangeMonitor(
openTelemetryRum.getOpenTelemetry(),
openTelemetry,
ServiceManager.get().getAppLifecycleService(),
ServiceManager.get().getCurrentNetworkProvider(),
Collections.unmodifiableList(additionalExtractors));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import android.app.Application;
import com.google.auto.service.AutoService;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.instrumentation.AndroidInstrumentation;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceResolver;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.library.okhttp.v3_0.internal.OkHttp3Singletons;
Expand Down Expand Up @@ -123,8 +123,7 @@ public boolean emitExperimentalHttpClientMetrics() {
}

@Override
public void install(
@NotNull Application application, @NotNull OpenTelemetryRum openTelemetryRum) {
OkHttp3Singletons.configure(this, openTelemetryRum.getOpenTelemetry());
public void install(@NotNull Application application, @NotNull OpenTelemetry openTelemetry) {
OkHttp3Singletons.configure(this, openTelemetry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import com.google.auto.service.AutoService;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.common.RumConstants;
import io.opentelemetry.android.instrumentation.AndroidInstrumentation;
import io.opentelemetry.api.OpenTelemetry;
import java.time.Duration;

/** Entrypoint for installing the slow rendering detection instrumentation. */
Expand Down Expand Up @@ -43,8 +43,7 @@ public SlowRenderingInstrumentation setSlowRenderingDetectionPollInterval(Durati

@RequiresApi(Build.VERSION_CODES.N)
@Override
public void install(
@NonNull Application application, @NonNull OpenTelemetryRum openTelemetryRum) {
public void install(@NonNull Application application, @NonNull OpenTelemetry openTelemetry) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
Log.w(
RumConstants.OTEL_RUM_LOG_TAG,
Expand All @@ -54,9 +53,7 @@ public void install(

SlowRenderListener detector =
new SlowRenderListener(
openTelemetryRum
.getOpenTelemetry()
.getTracer("io.opentelemetry.slow-rendering"),
openTelemetry.getTracer("io.opentelemetry.slow-rendering"),
slowRenderingDetectionPollInterval);

application.registerActivityLifecycleCallbacks(detector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.slot
import io.mockk.verify
import io.opentelemetry.android.OpenTelemetryRum
import io.opentelemetry.sdk.OpenTelemetrySdk
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
Expand All @@ -27,15 +26,12 @@ import java.time.Duration
class SlowRenderingInstrumentationTest {
private lateinit var slowRenderingInstrumentation: SlowRenderingInstrumentation
private lateinit var application: Application
private lateinit var openTelemetryRum: OpenTelemetryRum
private lateinit var openTelemetry: OpenTelemetrySdk

@Before
fun setUp() {
application = mockk()
openTelemetry = mockk()
openTelemetryRum = mockk()
every { openTelemetryRum.openTelemetry }.returns(openTelemetry)
slowRenderingInstrumentation = SlowRenderingInstrumentation()
}

Expand Down Expand Up @@ -67,13 +63,13 @@ class SlowRenderingInstrumentationTest {
@Config(sdk = [23])
@Test
fun `Not installing instrumentation on devices with API level lower than 24`() {
slowRenderingInstrumentation.install(application, openTelemetryRum)
slowRenderingInstrumentation.install(application, openTelemetry)

verify {
application wasNot Called
}
verify {
openTelemetryRum wasNot Called
openTelemetry wasNot Called
}
}

Expand All @@ -84,7 +80,7 @@ class SlowRenderingInstrumentationTest {
every { openTelemetry.getTracer(any()) }.returns(mockk())
every { application.registerActivityLifecycleCallbacks(any()) } just Runs

slowRenderingInstrumentation.install(application, openTelemetryRum)
slowRenderingInstrumentation.install(application, openTelemetry)

verify { openTelemetry.getTracer("io.opentelemetry.slow-rendering") }
verify { application.registerActivityLifecycleCallbacks(capture(capturedListener)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ package io.opentelemetry.android.instrumentation.startup

import android.app.Application
import com.google.auto.service.AutoService
import io.opentelemetry.android.OpenTelemetryRum
import io.opentelemetry.android.instrumentation.AndroidInstrumentation
import io.opentelemetry.android.internal.initialization.InitializationEvents
import io.opentelemetry.api.OpenTelemetry

@AutoService(AndroidInstrumentation::class)
class StartupInstrumentation : AndroidInstrumentation {
override fun install(
application: Application,
openTelemetryRum: OpenTelemetryRum,
openTelemetry: OpenTelemetry,
) {
val events = InitializationEvents.get()
if (events is SdkInitializationEvents) {
events.finish(openTelemetryRum.openTelemetry)
events.finish(openTelemetry)
}
}
}
Loading