DataDog / dd-sdk-android-gradle-plugin

The Datadog Gradle Plugin for Android
Apache License 2.0
14 stars 9 forks source link

Variant is not set up when uploading mapping file #205

Closed orafaaraujo closed 4 months ago

orafaaraujo commented 10 months ago

Describe what happened Hello, I'm trying to upload the mapping file by using the steps on Android Crash Reporting and Error Tracking , but apparently, the variant is not being set.

On my app/build.gradle file, I'm setting up the site.

datadog {
    site = "EU1"
}

I'm also setting up a dynamic way to call the task uploadMapping[Variant]:

android {
    applicationVariants.configureEach { variant ->
        if (variant.getBuildType().minifyEnabled) {
            tasks.named("minify${variant.name.capitalize()}WithR8").configure {
                finalizedBy tasks.named("uploadMapping${variant.name.capitalize()}")
            }
        }
    }
}

Which is working as expected.

For tests, I'm calling uploadMapping[Variant] directly.

➜  MyApp git:(develop) ✗ ./gradlew uploadMappingQa
Configuration on demand is an incubating feature.
Reusing configuration cache.

> Task :app:uploadMappingQa
Mapping file upload successful with tags `service:com.myapp`, `version:3.0.0`, `variant:`. 
Make sure the SDK is initialized with the same values to ensure proper deobfuscation. Mapping files will be processed and ready within the next five minutes.

BUILD SUCCESSFUL in 6s
1 actionable task: 1 executed
Configuration cache entry reused.

In short: service:com.myapp: correct ✔️ version:3.0.0: correct ✔️ variant:: empty ❌

I believe because it is missing the variant, I still can not check deobfuscated classes on Datadog.

I also tried setting up the variants as mentioned in the docs

which is missing variants { }

datadog {
    site = "EU1"
    variants {
        debug { versionName = "debug" }
        qa { versionName = "qa" }
        qaautomation { versionName = "qaautomation" }
        release { versionName = "release" }
    }
}

But in this case, I'm only replacing the version, not adding the variant. No deobfuscation is happening in the Dashboard.

For clarification, except for the debug build type, all others are obfuscated. The names of the build types match with the variant on the Datadog dashboard.

Screenshot 2023-11-03 at 16 13 12

Steps to reproduce the issue:

Having multiple variants in the setup, try to upload the mapping file.

Describe what you expected:

Have the deobfuscation on the Datadog dashboard.

Let me know if you need any extra information.

Thanks!

Additional context

xgouchet commented 9 months ago

Hi @orafaaraujo and thanks for submiting this issue.

Indeed it seems your mapping file is uploaded without its variants, and without it it can't be matched with stacktraces captured at runtime. The output should read:

Mapping file upload successful with tags service:com.myapp, version:3.0.0, variant:qa.

Can you share your build.gradle[.kts](including the part where you define your variants) to help us reproduce this issue on our side please?

orafaaraujo commented 9 months ago

Hey @xgouchet Thanks for the response!

I agree, the variant it's missing... below you can find my setup.

app/build.gradle

apply plugin: "com.android.application"
apply plugin: "com.datadoghq.dd-sdk-android-gradle-plugin"

android { 
    buildTypes {
        debug {
            debuggable true
            signingConfig signingConfigs.signDebug
        }
        qa {
            debuggable false
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.signProd
        }
        qaautomation {
            debuggable false
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.signProd
        }
        release {
            debuggable false
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.signProd
    }

    applicationVariants.configureEach { variant ->
        if (variant.getBuildType().minifyEnabled) {
            tasks.named("minify${variant.name.capitalize()}WithR8").configure {
                finalizedBy tasks.named("uploadMapping${variant.name.capitalize()}")
            }
        }
    }
}

datadog {
    site = "EU1"
}

We also bumped the version to the latest 1.12.0

build.gradle

buildscript {
    dependencies {
        classpath "com.datadoghq:dd-sdk-android-gradle-plugin:1.12.0"
    }
}

I'm omitting some parts that I think it's not relevant, but please let me know if there is something that you could consider important.

xgouchet commented 9 months ago

Oh I get it, the main issue is that you're using the buildType as variant, instead of using flavors. The general assumption is that the build type is usually debug/release, and that flavors will be added to have, for example a dev/qa/staging/prod variants (where the backend endpoints, or some features will change).

We will add a task in our roadmap to allow taking the buildType into account. In the meantime, can you try using flavors (like the example below)? That way you can build a qaRelease, qaAutomationRelease and prodRelease versions with independent mapping files.

android {
    // …

    flavorDimensions  "version"
    productFlavors {
        dev {
            dimension "version"
        }
        qa {
            dimension "version"
        }
        qaAutomation {
            dimension "version"
        }
        prod {
            dimension "version"
        }=
    }
orafaaraujo commented 9 months ago

Hey @xgouchet

Oh, I see it. Is it possible to enable it at least for release? Otherwise, we'll wait for the update. I prefer to not add new flavors for now.

Thanks once again.

xgouchet commented 9 months ago

If you only upload the mapping for your release build, you can pass in an empty string in the variant when initializing the SDK, and it'll use the release mapping files :

    val config = Configuration.Builder(
            clientToken = BuildConfig.DD_CLIENT_TOKEN,
            env = BuildConfig.BUILD_TYPE,
            variant = ""
        )
orafaaraujo commented 9 months ago

Hey @xgouchet

I appreciate your inputs on this, but unfortunately this would not be possible us too as we have dedicate board to build types today.

We'll wait for the final solution, let me know if I can help with anything else.

Thanks!

orafaaraujo commented 9 months ago

Hey @xgouchet

One last question. Is it possible to manually upload the mapping file?

Thanks

xgouchet commented 9 months ago

Unfortunately so far no it's not possible.

0xnm commented 4 months ago

Hello @orafaaraujo!

We changed the way the match for the deobfuscation happens between the event and mapping file in 1.13.x version of our Gradle Plugin, now mechanism relies on the unique Build ID, so it means the difference in the variant doesn't matter for the deobfuscation process.

To try it out you also need to have out Android SDK version 2.8.0 or above.

With that said, I'm closing this issue. Feel free to re-open it if needed.