agentsclimarketplace

Java agent bytecode instrumentation with asm

Skill kjuhwa/skills-hub/skills/backend/java-agent-bytecode-instrumentation-with-asm

Build a JVM agent using ASM's ClassFileTransformer to inject profiling/monitoring hooks into application classes via pluggable visitor chainsFrom its SKILL.md

Install
npx -y skills add kjuhwa/skills-hub --skill java-agent-bytecode-instrumentation-with-asm

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

2.2 KB, 396 tokens by cl100k_base, as published. Nobody here has run it

Java Agent Bytecode Instrumentation with ASM

Apply this skill when you need to observe or modify JVM behavior without touching application source — APM tracing, security policy enforcement, test coverage, feature flag injection.

Pattern

  1. Package as a -javaagent:<jar> premain JAR with Premain-Class in MANIFEST.MF and Can-Retransform-Classes: true.
  2. Register a ClassFileTransformer whose transform(...) dispatches per-target-class to composable ASM ClassVisitor chains (one visitor per concern: field add, method wrap, try/catch injection).
  3. Gate each visitor with a class-name / annotation / interface filter — don't visit everything; it's expensive and fragile.
  4. Handle JDK-dynamic classes separately (lambdas, method handles). Scouter uses a dedicated LambdaFormTransformer.
  5. Expose a config (flags, allow-list, hook-level) so unsafe hooks (async, lambda) can be disabled in production if they conflict with other agents.

Evidence

  • scouter.agent.java/src/main/java/scouter/agent/AgentTransformer.java — main dispatch
  • scouter.agent.java/src/main/java/scouter/agent/asm/AddFieldASM.java — visitor example
  • scouter.agent.java/src/main/java/scouter/agent/LambdaFormTransformer.java — lambda handling
  • scouter.agent.java/readme.md

Pitfalls

  • Lambda forms and synthetic classes bypass normal hooks. Always add a lambda-form transformer.
  • Spring proxy classes conflict with naive class-name matchers — use runtime interface checks.
  • Multi-agent conflicts: if your hooks wrap the same methods as another agent, order matters. Document compat.

Related knowledge

  • asm-based-classloader-instrumentation-caveats (pitfall)
  • trace-context-async-execution-propagation (pitfall)

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,144. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.