-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Instrumentation API part 2 (#408) * Moving network provider tools to services * Moving network service related tests * Moving network attr init feature to the agent * Making network instrumentation depend on the agent * Initializing CurrentNetworkProvider as service * Clean up config * Created NetworkChangeInstrumentation * Updated network monitor tests * Clean up * Renaming installOn by start * Adding internal class docs * Fixing visible for tests comment * Rename .java to .kt * Removing Carrier.Builder * Transforming lifecycle tools to a service * Updating tests * Registering AppLifecycleService * Rename .java to .kt * Updating OpenTelemetryRumBuilderTest * Updating network change instrumentation * Adding internal comments * Reverting back to instantiating OpenTelemetryRumBuilder using the static OpenTelemetryRum.builder function * Updating tests * Using AndroidJUnit4 instead of robolectric runner
- Loading branch information
1 parent
ec6a22a
commit 53896cf
Showing
20 changed files
with
306 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
android-agent/src/main/java/io/opentelemetry/android/ApplicationStateWatcher.java
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
android-agent/src/main/java/io/opentelemetry/android/InstrumentedApplicationImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
android-agent/src/main/java/io/opentelemetry/android/SdkPreconfiguredRumBuilder.java
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
android-agent/src/main/java/io/opentelemetry/android/SdkPreconfiguredRumBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android | ||
|
||
import android.app.Application | ||
import io.opentelemetry.android.instrumentation.common.InstrumentedApplication | ||
import io.opentelemetry.android.internal.services.ServiceManager | ||
import io.opentelemetry.android.internal.services.applifecycle.AppLifecycleService | ||
import io.opentelemetry.sdk.OpenTelemetrySdk | ||
import java.util.function.Consumer | ||
|
||
class SdkPreconfiguredRumBuilder | ||
@JvmOverloads | ||
internal constructor( | ||
private val application: Application, | ||
private val sdk: OpenTelemetrySdk, | ||
private val sessionId: SessionId = | ||
SessionId( | ||
SessionIdTimeoutHandler(), | ||
), | ||
appLifecycleServiceProvider: () -> AppLifecycleService = { | ||
ServiceManager.get().getAppLifecycleService() | ||
}, | ||
) { | ||
private val instrumentationInstallers: MutableList<Consumer<InstrumentedApplication>> = | ||
ArrayList() | ||
private val appLifecycleService by lazy { appLifecycleServiceProvider.invoke() } | ||
|
||
/** | ||
* Adds an instrumentation installer function that will be run on an [ ] instance as a part of the [.build] method call. | ||
* | ||
* @return `this` | ||
*/ | ||
fun addInstrumentation(instrumentationInstaller: Consumer<InstrumentedApplication>): SdkPreconfiguredRumBuilder { | ||
instrumentationInstallers.add(instrumentationInstaller) | ||
return this | ||
} | ||
|
||
/** | ||
* Creates a new instance of [OpenTelemetryRum] with the settings of this [ ]. | ||
* | ||
* | ||
* This method uses a preconfigured OpenTelemetry SDK and install built-in system | ||
* instrumentations in the passed Android [Application]. | ||
* | ||
* @return A new [OpenTelemetryRum] instance. | ||
*/ | ||
fun build(): OpenTelemetryRum { | ||
// 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 | ||
appLifecycleService.registerListener(sessionId.timeoutHandler) | ||
|
||
val tracer = sdk.getTracer(OpenTelemetryRum::class.java.simpleName) | ||
sessionId.setSessionIdChangeListener(SessionIdChangeTracer(tracer)) | ||
|
||
// InstrumentedApplication instrumentedApplication = | ||
// new InstrumentedApplicationImpl(application, sdk, | ||
// applicationStateWatcher); | ||
// for (Consumer<InstrumentedApplication> installer : instrumentationInstallers) { | ||
// installer.accept(instrumentedApplication); TODO to be replaced by calls to | ||
// AndroidInstrumentation.install | ||
// } | ||
return OpenTelemetryRumImpl(sdk, sessionId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../main/java/io/opentelemetry/android/internal/services/applifecycle/AppLifecycleService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.internal.services.applifecycle | ||
|
||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.ProcessLifecycleOwner | ||
import io.opentelemetry.android.internal.services.Startable | ||
|
||
/** | ||
* This class is internal and not for public use. Its APIs are unstable and can change at any time. | ||
*/ | ||
class AppLifecycleService internal constructor( | ||
private val applicationStateWatcher: ApplicationStateWatcher, | ||
private val appLifecycle: Lifecycle, | ||
) : Startable { | ||
companion object { | ||
@JvmStatic | ||
fun create(): AppLifecycleService { | ||
return AppLifecycleService( | ||
ApplicationStateWatcher(), | ||
ProcessLifecycleOwner.get().lifecycle, | ||
) | ||
} | ||
} | ||
|
||
fun registerListener(listener: ApplicationStateListener) { | ||
applicationStateWatcher.registerListener(listener) | ||
} | ||
|
||
override fun start() { | ||
appLifecycle.addObserver(applicationStateWatcher) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ava/io/opentelemetry/android/internal/services/applifecycle/ApplicationStateListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.internal.services.applifecycle; | ||
|
||
/** | ||
* Listener interface that is called whenever the instrumented application is brought to foreground | ||
* from the background, or vice versa. | ||
* | ||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
* at any time. | ||
*/ | ||
public interface ApplicationStateListener { | ||
|
||
/** | ||
* Called whenever the application is brought to the foreground (i.e. first activity starts). | ||
*/ | ||
void onApplicationForegrounded(); | ||
|
||
/** Called whenever the application is brought to the background (i.e. last activity stops). */ | ||
void onApplicationBackgrounded(); | ||
} |
Oops, something went wrong.