Skip to content

Commit

Permalink
Launchtime instrumentation (#387)
Browse files Browse the repository at this point in the history
* Moving plugin to catalog

* Clean up

* Creating instrumentation api

* Creating launch time instrumentation

* Updating instrumentation api

* Setting up launch tracker instrumentation

* Creating launch time plugin

* Upgrading gradlew wrapper

* Improving LaunchTimeTracker

* Fixing app test build

* Clean up

* Configuring android tests

* Setting up android tests

* Adding launch time test

* Configuring instrumentation publishing

* Configuring launchtime plugin

* Configuring dependency substitution for android tests

* Configuring instrumentation publishing

* Updating launchtime instrumentation

* Configuring launchtime service

* Installing instrumentations

* Creating android-test buildSrc

* Clean up

* Renaming compile package

* Configuring instrumentation testutils

* Using testutils

* Clean up

* Creating AgentRule

* Using AgentRule

* Creating notice files

* Clean up

* Ignoring newapi warnings
  • Loading branch information
LikeTheSalad authored Feb 3, 2025
1 parent 828efe8 commit b4a9a46
Show file tree
Hide file tree
Showing 80 changed files with 1,471 additions and 740 deletions.
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This product includes software licensed under the 'Apache License Version 2.0' l
- Byte Buddy Gradle plugin
- Core (https://developer.android.com/jetpack/androidx/releases/core#1.15.0)
- Kotlin Stdlib (https://kotlinlang.org/)
- Lifecycle Process (https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.7)
- OpenTelemetry Java (https://github.com/open-telemetry/opentelemetry-java)
- OpenTelemetry Java Contrib (https://github.com/open-telemetry/opentelemetry-java-contrib)
- OpenTelemetry Semantic Conventions Java (https://github.com/open-telemetry/semantic-conventions-java)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package co.elastic.otel.android.api.internal

import io.opentelemetry.sdk.common.CompletableResultCode

interface MetricFlusher {
fun flushMetrics(): CompletableResultCode
}
6 changes: 3 additions & 3 deletions android-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("elastic.java-library")
id("java-gradle-plugin")
id("com.github.gmazzo.buildconfig") version "3.1.0"
alias(libs.plugins.buildconfig)
}

dependencies {
Expand All @@ -22,8 +22,8 @@ licensesConfig {

gradlePlugin {
plugins {
create("androidOtelPlugin") {
id = "co.elastic.otel.android"
create("elasticAndroidAgent") {
id = "co.elastic.otel.android.agent"
implementationClass = "co.elastic.otel.android.plugin.ApmAndroidAgentPlugin"
displayName = "Elastic OTel Android Agent"
description = project.description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package co.elastic.otel.android.plugin

import co.elastic.apm.generated.BuildConfig
import co.elastic.otel.android.common.internal.logging.Elog
import co.elastic.otel.android.generated.BuildConfig
import co.elastic.otel.android.plugin.logging.GradleLoggerFactory
import net.bytebuddy.build.gradle.android.ByteBuddyAndroidPlugin
import org.gradle.api.Plugin
Expand Down
1 change: 1 addition & 0 deletions android-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ licensesConfig {

dependencies {
api(project(":android-api"))
api(project(":instrumentation:api"))
implementation(libs.stagemonitor.configuration)
implementation(project(":android-common"))
implementation(libs.opentelemetry.exporter.otlp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import co.elastic.otel.android.internal.features.conditionaldrop.ConditionalDrop
import co.elastic.otel.android.internal.features.diskbuffering.DiskBufferingConfiguration
import co.elastic.otel.android.internal.features.diskbuffering.DiskBufferingManager
import co.elastic.otel.android.internal.features.exportergate.ExporterGateManager
import co.elastic.otel.android.internal.features.instrumentation.InstrumentationManager
import co.elastic.otel.android.internal.features.sessionmanager.SessionIdGenerator
import co.elastic.otel.android.internal.features.sessionmanager.SessionManager
import co.elastic.otel.android.internal.features.sessionmanager.samplerate.SampleRateManager
Expand All @@ -47,15 +48,17 @@ import co.elastic.otel.android.logging.LoggingPolicy
import io.opentelemetry.api.OpenTelemetry
import java.util.UUID

@Suppress("CanBeParameter")
class ElasticApmAgent private constructor(
configuration: Configuration,
sampleRateManager: SampleRateManager,
private val sampleRateManager: SampleRateManager,
private val serviceManager: ServiceManager,
private val exporterGateManager: ExporterGateManager,
private val diskBufferingManager: DiskBufferingManager,
private val apmServerConnectivityManager: ApmServerConnectivityManager,
private val elasticClockManager: ElasticClockManager,
private val centralConfigurationManager: CentralConfigurationManager,
private val instrumentationManager: InstrumentationManager,
private val sessionManager: SessionManager
) : ManagedElasticOtelAgent(configuration) {
private val openTelemetry = configuration.openTelemetrySdk
Expand All @@ -67,6 +70,7 @@ class ElasticApmAgent private constructor(
sampleRateManager.initialize()
sessionManager.initialize()
exporterGateManager.initialize()
instrumentationManager.initialize(this)
}

override fun getOpenTelemetry(): OpenTelemetry {
Expand Down Expand Up @@ -262,6 +266,7 @@ class ElasticApmAgent private constructor(
apmServerConnectivityManager,
elasticClockManager,
centralConfigurationManager,
InstrumentationManager.create(application),
sessionManager
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@
package co.elastic.otel.android.internal.api

import co.elastic.otel.android.api.ElasticOtelAgent
import co.elastic.otel.android.api.internal.MetricFlusher
import io.opentelemetry.sdk.OpenTelemetrySdk
import io.opentelemetry.sdk.common.CompletableResultCode

abstract class ManagedElasticOtelAgent(
private val configuration: Configuration
) : ElasticOtelAgent {
) : ElasticOtelAgent, MetricFlusher {

final override fun close() {
onClose()
configuration.openTelemetrySdk.close()
}

override fun flushMetrics(): CompletableResultCode {
return configuration.openTelemetrySdk.sdkMeterProvider.forceFlush()
}

protected abstract fun onClose()

data class Configuration(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.internal.features.instrumentation

import android.app.Application
import co.elastic.otel.android.api.ElasticOtelAgent
import co.elastic.otel.android.instrumentation.internal.Instrumentation
import java.util.ServiceLoader

internal class InstrumentationManager(
private val application: Application,
private val instrumentations: List<Instrumentation>
) {

companion object {
internal fun create(application: Application): InstrumentationManager {
return InstrumentationManager(
application,
ServiceLoader.load(Instrumentation::class.java).toList()
)
}
}

fun initialize(agent: ElasticOtelAgent) {
instrumentations.forEach {
it.install(application, agent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ abstract class ElasticOpenTelemetryBuilder<B> {
return this as B
}

internal open fun setProcessorFactory(value: ProcessorFactory): B {
fun setProcessorFactory(value: ProcessorFactory): B {
checkNotBuilt()
processorFactory = value
return this as B
Expand Down
62 changes: 0 additions & 62 deletions android-test/app/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b4a9a46

Please sign in to comment.