adityamparikh opened a new pull request, #236:
URL: https://github.com/apache/solr-mcp/pull/236

   ## Summary
   
   Logs one line per MCP tool call, so every tool call's trace has a log line 
in Loki.
   
   The services log only when something fails, so a successful `tools/call` 
wrote nothing, and a trace's **Logs for this span** link in Grafana was empty 
for every normal request. This adds an `ObservationHandler` for the 
observations the `@Observed` tool services already create:
   
   ```
   INFO  ... o.a.s.m.s.o.ToolCallLoggingHandler : SearchService#search 
completed in 47 ms
   WARN  ... o.a.s.m.s.o.ToolCallLoggingHandler : SearchService#search failed 
after 9 ms: java.lang.IllegalArgumentException: Error from server at ...
   ```
   
   - **Registration:** Spring Boot registers `ObservationHandler` beans with 
the `ObservationRegistry`, so the handler is a package-private `@Component`, 
like the reference docs' `ObservationPredicate` example. No configuration class 
or customizer.
   - **Scope:** it matches `ObservedAspect.ObservedAspectContext`, so only 
`@Observed` method observations are logged. HTTP, security and other 
observations are ignored, and the tool name comes from the join point, not from 
tag strings.
   - **Trace:** the line is written as the observation stops, under the 
request's trace. Grafana's trace-to-logs query filters on the trace ID, so it 
finds the line from any span in the trace.
   - **STDIO:** `@Observed` observations exist only in the http profile, where 
the annotations are enabled, so in STDIO the handler never runs.
   - **Docs:** `docs/observability.md` and its site copy said successful tool 
calls leave that link empty; updated to describe the new line.
   
   **Depends on #230.** This branch is stacked on it because it edits the text 
#230 adds; the first two commits in this PR are #230's and drop out once it 
merges.
   
   ## Test plan
   
   - [x] Ran the server in HTTP mode against `grafana/otel-lgtm`: a successful 
`search` logs `completed in` at INFO, a `search` on a missing collection logs 
`failed after` at WARN, `list-collections` logs its line, and `tools/list` logs 
nothing.
   - [x] Grafana's trace-to-logs query (`{service_name="solr-mcp"} | trace_id = 
"<id>"`) for a successful `search` trace returns the `completed in` line; 
before this change it returned nothing.
   - [x] `./gradlew build` passes: 421 tests, 0 failures, 0 skipped (includes 
the STDIO JSON-RPC test).
   - No automated test for the log line itself; verified against LGTM as above.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to