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

implement gradle plugin to facilitate okhttp instrumentation #137

Merged
merged 10 commits into from
Dec 5, 2024

Conversation

snowp
Copy link
Contributor

@snowp snowp commented Dec 4, 2024

This adds a gradle plugin inspired by https://github.com/getsentry/sentry-android-gradle-plugin that allows us to automatically install the OkHttpEventListener for all Okhttp clients.

@snowp snowp marked this pull request as ready for review December 4, 2024 22:54
id("dependency-license-config")
id("java-gradle-plugin")
id("maven-publish")
id("com.vanniktech.maven.publish") version "0.28.0" apply false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just reference the libs catalog we use everywhere alias(libs.plugins.maven.publish)

}

apply {
plugin("com.vanniktech.maven.publish")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why it doesn't apply it at top just to do it here, maybe some weird ordering issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo culting the upstream repo, let me see if i can simplify


id("dependency-license-config")
id("java-gradle-plugin")
id("maven-publish")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, removed

/**
* See https://github.com/getsentry/sentry/blob/c943de2afc785083554e7fdfb10c67d0c0de0f98/static/app/components/events/eventEntries.tsx#L57-L58
*/
private val MINIFIED_CLASSNAME_SENTRY_REGEX =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-12-05 at 7 53 02 AM

@@ -85,6 +85,8 @@ cargo {
targetDirectory = "../../../target"
targets = listOf("arm64", "x86_64")
pythonCommand = "python3"
rustcCommand = "/Users/snow/.cargo/bin/rustc"
cargoCommand = "/Users/snow/.cargo/bin/cargo"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a chance the gradle update broke the tool resolution but I can't seem to reproduce so will just remove this unless we run into CI issues. We can revert the gradle change / fix upstream if it becomes an issue

Yell at me if you get errors about rustc not found :)

@@ -147,7 +147,6 @@ class FirstFragment : Fragment() {

private fun provideOkHttpClient(): OkHttpClient {
return OkHttpClient.Builder()
.eventListenerFactory(CaptureOkHttpEventListenerFactory())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are multiple okhttp clients will it affect them all? e.g. if they use a separate one for apollo graphql

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the plugin will traverse all the clients in the system and add it everywhere. If using both at the same time causes issues we should figure out how to make the interoperate well, this is probably easier than trying to figure out how to make it conditional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i'm working on that pr now, i'll think about it

@@ -16,6 +16,7 @@ import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import io.bitdrift.gradletestapp.databinding.ActivityMainBinding
import okhttp3.OkHttpClient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make sure to also update bazel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do this separately

@snowp snowp merged commit 19eeac8 into main Dec 5, 2024
14 checks passed
@snowp snowp deleted the gradle-plugin branch December 5, 2024 20:02
@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants