Skip to content

feat(javaagent): servlet doctor status follows the agent state - #817

Open
nik13 wants to merge 1 commit into
devfrom
feat/javaagent-servlet-doctor-status
Open

nik13 wants to merge 1 commit into
devfrom
feat/javaagent-servlet-doctor-status

Conversation

@nik13

@nik13 nik13 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

  1. Aligns servlet and integration doctor status with agent startup state. In traceai-javaagent, when TraceAIAuto.start fails after installing transformers, every integration instrumented by this agent copy (and any still pending class load) is reported as "disabled (agent inactive)" rather than "instrumented" or "pending", and classes loaded later keep that inactive status. Entries held by another copy of the agent in the same JVM keep their status. IncomingRequests.enter also checks TraceAIAuto.currentRuntime() != null so incoming servlet requests join a caller's trace only while the agent runtime is active.
  2. Caches servlet advice lookup handles once per JVM. IncomingRequests.publishAdvice resolves IncomingRequests.enter and IncomingRequests.exit through the system class loader and publishes the two Method handles in system property traceai.auto.servlet.advice (putIfAbsent) while the servlet integration is enabled. ServiceAdvice reads those handles directly and falls back to the class-loader lookup when the entry is absent.

Why?

When agent startup failed after bytecode transformers were already registered, doctor() could report integrations as active or pending even though the runtime had been torn down, and IncomingRequests.ServiceAdvice performed reflective class-loader and method lookups on every servlet request.

How was it tested?

  • New ServletDoctorStatusTest (11/11 pass): covers disabled SDK (OTEL_SDK_DISABLED=true), active control, failed start after transformer installation marking servlet and pending integrations as "disabled (agent inactive)", late class load after failed start, IncomingRequests.enter returning null while inactive, and traceai.auto.servlet.advice handle publication and fallback.

  • Extended IncomingRequestsE2ETest (13/13 pass) and ServletApp: covers async dispatch and forward propagation in the packaged child-JVM agent.

  • Full mvn -B -ntp -f java/pom.xml -pl traceai-javaagent -am verify (maven:3.9.9-eclipse-temurin-21): traceai-java-core, traceai-java-annotations, traceai-java-google-adk, and traceai-javaagent all succeed — 825 unit tests (0 failures, 0 errors, 1 skipped) and 303/303 child-JVM failsafe E2E tests pass.

  • Unit tests added / updated (JUnit 5)

  • Integration / child-JVM E2E tests pass (maven-failsafe-plugin)

Checklist

  • Commit messages follow Conventional Commits
  • No TODOs or commented-out code left in
  • No real API keys or secrets in the diff
  • If prose was added or changed: checked against docs/VOCABULARY.md

Notes for reviewers

Targets dev. The per-JVM advice cache is stored as a Method[] value under system property traceai.auto.servlet.advice only while the servlet integration is enabled.

When a start fails after the transformers are installed, the doctor lists
the integrations they serve, and the ones waiting for a class to load, as
"disabled (agent inactive)", and classes loaded later keep that entry.
Incoming servlet requests join the caller's trace only while the agent is
active.

The servlet advice resolves IncomingRequests.enter and exit once per JVM:
the agent publishes the handles in a system property while the servlet
integration is enabled, and the advice falls back to the class-loader
lookup when the entry is absent.

Tests cover the doctor entries after a failed start, the published
handles, and async dispatch and forward in the packaged agent.

This branch has not been deployed

No deployments
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.

1 participant