-
Notifications
You must be signed in to change notification settings - Fork 42
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
Instrumentation API part 10 #498
Merged
LikeTheSalad
merged 13 commits into
open-telemetry:main
from
LikeTheSalad:instrumentation-api-p10
Jul 31, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
37c83e2
Installing AndroidInstrumentations
LikeTheSalad b9a24bf
Validating installing instrumentations
LikeTheSalad 642c756
Clean up
LikeTheSalad a6a34e6
Improving test name
LikeTheSalad 5c50d8e
Removing common module
LikeTheSalad da57edf
Renaming android-agent to core
LikeTheSalad 9220880
Making instrumentations into services
LikeTheSalad 9a5f03d
Created android-agent module
LikeTheSalad dced3ce
Adding OtelRumConfig extensions
LikeTheSalad 2ac7205
Updating agent description
LikeTheSalad 6604d1d
Reverting core namespace change
LikeTheSalad 3ca8d44
Moving RumConstants to common package
LikeTheSalad 5e85a1d
Adding auto service annotations as implementation to avoid R8 complains
LikeTheSalad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
80 changes: 80 additions & 0 deletions
80
android-agent/src/main/kotlin/io/opentelemetry/android/agent/OtelRumConfigExtensions.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,80 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.agent | ||
|
||
import io.opentelemetry.android.config.OtelRumConfig | ||
import io.opentelemetry.android.instrumentation.AndroidInstrumentationRegistry | ||
import io.opentelemetry.android.instrumentation.activity.ActivityLifecycleInstrumentation | ||
import io.opentelemetry.android.instrumentation.anr.AnrInstrumentation | ||
import io.opentelemetry.android.instrumentation.common.ScreenNameExtractor | ||
import io.opentelemetry.android.instrumentation.crash.CrashDetails | ||
import io.opentelemetry.android.instrumentation.crash.CrashReporterInstrumentation | ||
import io.opentelemetry.android.instrumentation.fragment.FragmentLifecycleInstrumentation | ||
import io.opentelemetry.android.instrumentation.network.NetworkChangeInstrumentation | ||
import io.opentelemetry.android.instrumentation.slowrendering.SlowRenderingInstrumentation | ||
import io.opentelemetry.android.internal.services.network.data.CurrentNetwork | ||
import io.opentelemetry.api.trace.Tracer | ||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor | ||
import java.time.Duration | ||
|
||
/** | ||
* Convenience functions to allow configuring the default instrumentations through the [OtelRumConfig] object, for example: | ||
* | ||
* ``` | ||
* OtelRumConfig() | ||
* .setSessionTimeout(Duration.ofSeconds(10)) // Real OtelRumConfig function | ||
* .setSlowRenderingDetectionPollInterval(Duration.ofSeconds(5)) // Extension function | ||
* .disableScreenAttributes() // Real OtelRumConfig function | ||
* ``` | ||
*/ | ||
|
||
fun OtelRumConfig.setActivityTracerCustomizer(customizer: (Tracer) -> Tracer): OtelRumConfig { | ||
AndroidInstrumentationRegistry.get().get(ActivityLifecycleInstrumentation::class.java) | ||
?.setTracerCustomizer(customizer) | ||
return this | ||
} | ||
|
||
fun OtelRumConfig.setActivityNameExtractor(screenNameExtractor: ScreenNameExtractor): OtelRumConfig { | ||
AndroidInstrumentationRegistry.get().get(ActivityLifecycleInstrumentation::class.java) | ||
?.setScreenNameExtractor(screenNameExtractor) | ||
return this | ||
} | ||
|
||
fun OtelRumConfig.setFragmentTracerCustomizer(customizer: (Tracer) -> Tracer): OtelRumConfig { | ||
AndroidInstrumentationRegistry.get().get(FragmentLifecycleInstrumentation::class.java) | ||
?.setTracerCustomizer(customizer) | ||
return this | ||
} | ||
|
||
fun OtelRumConfig.setFragmentNameExtractor(screenNameExtractor: ScreenNameExtractor): OtelRumConfig { | ||
AndroidInstrumentationRegistry.get().get(FragmentLifecycleInstrumentation::class.java) | ||
?.setScreenNameExtractor(screenNameExtractor) | ||
return this | ||
} | ||
|
||
fun OtelRumConfig.addAnrAttributesExtractor(extractor: AttributesExtractor<Array<StackTraceElement>, Void>): OtelRumConfig { | ||
AndroidInstrumentationRegistry.get().get(AnrInstrumentation::class.java) | ||
?.addAttributesExtractor(extractor) | ||
return this | ||
} | ||
|
||
fun OtelRumConfig.addCrashAttributesExtractor(extractor: AttributesExtractor<CrashDetails, Void>): OtelRumConfig { | ||
AndroidInstrumentationRegistry.get().get(CrashReporterInstrumentation::class.java) | ||
?.addAttributesExtractor(extractor) | ||
return this | ||
} | ||
|
||
fun OtelRumConfig.addNetworkChangeAttributesExtractor(extractor: AttributesExtractor<CurrentNetwork, Void>): OtelRumConfig { | ||
AndroidInstrumentationRegistry.get().get(NetworkChangeInstrumentation::class.java) | ||
?.addAttributesExtractor(extractor) | ||
return this | ||
} | ||
|
||
fun OtelRumConfig.setSlowRenderingDetectionPollInterval(interval: Duration): OtelRumConfig { | ||
AndroidInstrumentationRegistry.get().get(SlowRenderingInstrumentation::class.java) | ||
?.setSlowRenderingDetectionPollInterval(interval) | ||
return this | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
plugins { | ||
id("otel.android-library-conventions") | ||
id("otel.publish-conventions") | ||
} | ||
|
||
android { | ||
namespace = "io.opentelemetry.android" | ||
|
||
buildToolsVersion = "34.0.0" | ||
|
||
defaultConfig { | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
buildConfigField("String", "OTEL_ANDROID_VERSION", "\"$version\"") | ||
} | ||
|
||
buildTypes { | ||
all { | ||
resValue("string", "rum.version", "${project.version}") | ||
} | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro", | ||
) | ||
} | ||
} | ||
|
||
androidComponents { | ||
onVariants { | ||
if (it.buildType == "release") { // The one we choose to release | ||
project.tasks.register("createReleaseBuild", Copy::class) { | ||
from(it.artifacts.get(com.android.build.api.artifact.SingleArtifact.AAR)) | ||
into(project.layout.buildDirectory.dir("outputs/aar")) | ||
rename(".+", "opentelemetry-android.aar") | ||
} | ||
} | ||
} | ||
} | ||
|
||
project.afterEvaluate { | ||
tasks.named("assembleRelease") { | ||
finalizedBy("createReleaseBuild") | ||
} | ||
} | ||
|
||
testOptions { | ||
unitTests.isReturnDefaultValues = true | ||
unitTests.isIncludeAndroidResources = true | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = true | ||
} | ||
|
||
sourceSets { | ||
getByName("test") { | ||
kotlin.srcDirs("src/integrationTest/kotlin") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.core) | ||
implementation(libs.androidx.navigation.fragment) | ||
implementation(libs.androidx.lifecycle.process) | ||
|
||
api(platform(libs.opentelemetry.platform)) | ||
api(libs.opentelemetry.api) | ||
implementation(libs.opentelemetry.sdk) | ||
implementation(libs.opentelemetry.exporter.logging) | ||
implementation(libs.opentelemetry.instrumentation.api) | ||
implementation(libs.opentelemetry.semconv.incubating) | ||
implementation(libs.opentelemetry.diskBuffering) | ||
testImplementation(libs.opentelemetry.api.incubator) | ||
testImplementation(libs.androidx.test.core) | ||
testImplementation(libs.awaitility) | ||
testImplementation(libs.robolectric) | ||
testImplementation(libs.androidx.junit.ktx) | ||
} | ||
|
||
extra["pomName"] = "OpenTelemetry Android Instrumentation" | ||
description = "A library for instrumenting Android applications with OpenTelemetry" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file isn't really needed, I added it because it seemed handy to have those options in
OtelRumConfig
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah interesting, I hadn't thought of doing it with extension methods.... 🤔