Skip to content

feat(instrumentation): allow disabling instrumentation for specific variants - #1409

Closed
ansman wants to merge 2 commits into
getsentry:mainfrom
openai-oss-forks:nicklas/issue-1407-variant-instrumentation
Closed

feat(instrumentation): allow disabling instrumentation for specific variants#1409
ansman wants to merge 2 commits into
getsentry:mainfrom
openai-oss-forks:nicklas/issue-1407-variant-instrumentation

Conversation

@ansman

@ansman ansman commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

📜 Description

Add ignoredVariants, ignoredBuildTypes, and ignoredFlavors to both tracingInstrumentation and runtimeOptimizations.

sentry {
    tracingInstrumentation {
        ignoredBuildTypes.add("debug")
    }
    runtimeOptimizations {
        ignoredBuildTypes.add("debug")
    }
}

All exclusions default to empty, preserving existing behavior. Other plugin features, including mapping uploads, remain enabled for excluded variants.

💡 Motivation and Context

Bytecode instrumentation disables incremental compilation, increasing build times during development. Existing variant exclusions disable the entire Sentry plugin, including unrelated functionality such as mapping uploads. This change allows instrumentation and runtime optimizations to be disabled independently for selected variants while preserving other plugin features and release behavior.

Fixes #1407.

💚 How did you test it?

./gradlew :plugin-build:spotlessApply :plugin-build:test :plugin-build:integrationTest --tests io.sentry.android.gradle.integration.SentryPluginVariantTest

All 429 unit tests and 13 variant integration tests pass. Integration coverage includes exclusions by variant, build type, and flavor; preserved mapping uploads; unaffected variants; and disabling both instrumentation visitors together.

I also tested it in our project and confirmed that the bytecode transforms did not run for disabled variants.

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

🔮 Next steps

Decide if debug builds should be excluded by default.

@ansman
ansman marked this pull request as ready for review August 20, 2026 01:06

@0xadam-brown 0xadam-brown left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Backward compatible + a sane extension of our current API + worth exposing ASM off-switches. Lgtm – and thanks 💯

@0xadam-brown
0xadam-brown self-requested a review August 21, 2026 11:56
@0xadam-brown

Copy link
Copy Markdown
Member

...removed my approval as it looks like folks are discussing the precise API internally atm. We'll get back with you shortly...

@romtsn

romtsn commented Aug 27, 2026

Copy link
Copy Markdown
Member

hey @ansman thanks a bunch for your contribution -- we've discussed this internally and have come up with an inverse approach where you'd specify the variant name as the sub-DSL of sentry and configure each variant respectively (#1420):

sentry {
  variants {
    create("fullDebug") {
      tracingInstrumentation { enabled = false }
      runtimeOptimizations { enabled = false }
    }
    create("qaDebug") {
      tracingInstrumentation { enabled = false }
      runtimeOptimizations { enabled = false }
    }
  }
}

// or if you want a bit of sugar on top to disable it for all `debug` variants
androidComponents.beforeVariants(selector().withBuildType("debug")) { vb ->
  sentry.variants.maybeCreate(vb.name).with {
    tracingInstrumentation { enabled = false }
    runtimeOptimizations { enabled = false }
  }
}

let us know if it's not gonna work for your case, we can revisit it later! For now I'm gonna supersede it

@romtsn romtsn closed this Aug 27, 2026
@romtsn

romtsn commented Aug 27, 2026

Copy link
Copy Markdown
Member

oh and btw, it only exposes bytecode stuff now (tracingInstrumentation and runtimeOptimizations that is), let us know if you'd want more things to have configured that way.

@ansman

ansman commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@romtsn That works fine too, though I'm not exactly sure what the sentry variants would be used for. I think doing something like this would feel more natural to me:

androidComponents.onVariants(selector().withBuildType("debug")) { variant ->
  variant.sentry {
    tracingInstrumentation { enabled = false }
    runtimeOptimizations { enabled = false }
  }
}

Personally I just wanted to disable the bytecode transforms because they prohibit incremental compilation.

@ansman
ansman deleted the nicklas/issue-1407-variant-instrumentation branch August 28, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow tracing instrumentation to be disabled per variant, independently of ignoredVariants / ignoredFlavors

3 participants