Skip to content

rrezartprebreza/spring-boot-skills / skills/spring-boot-4/ai-observability

ai-observability

Verified

Use when adding Spring AI-specific model observations, token usage, latency, externally configured cost attribution, advisor telemetry, or protected prompt and completion logging. Use production-observability for general service metrics, health, logs, and OTLP setup.

examples/bad-ai-audit-advisor.java

View on GitHub
// BAD — logs full prompts (PII), synchronous audit, hardcoded pricing, no error metrics,
//          @Async via self-invocation (silently runs synchronously)

@Component
@Slf4j
public class AiAuditAdvisor implements CallAdvisor {

    @Autowired                                           // field injection
    private AuditLogRepository auditLogRepository;

    @Override
    public int getOrder() { return 0; }

    @Override
    public String getName() { return "AiAuditAdvisor"; }

    @Override
    public ChatClientResponse adviseCall(ChatClientRequest request, CallAdvisorChain chain) {

        // BAD: Logs full prompt content — may contain PII, secrets, customer data
        log.info("AI request prompt: {}", request.prompt().getContents());

        long start = System.currentTimeMillis();
        ChatClientResponse response = chain.nextCall(request);  // no try/catch — errors untracked
        long duration = System.currentTimeMillis() - start;

        // BAD: Hardcoded token pricing — changes when provider updates pricing
        Usage usage = response.chatResponse().getMetadata().getUsage();
        double cost = usage.getPromptTokens() * 0.003 / 1000
            + usage.getCompletionTokens() * 0.015 / 1000;

        // BAD: Synchronous audit save — blocks the main request thread
        // BAD: this.persistAsync(...) would be just as broken: @Async on a method of the
        //    same bean bypasses the proxy and runs inline (self-invocation pitfall)
        auditLogRepository.save(new AiAuditLog(
            request.prompt().getContents(),                              // stores full prompt (PII risk)
            response.chatResponse().getResult().getOutput().getText(),  // stores full response
            cost,
            duration));

        // BAD: No Micrometer metrics — can't alert on latency spikes or error rates
        // BAD: No request ID for tracing
        // BAD: No error handling — if chain throws, no metrics or audit recorded
        // BAD: Only counters, no histograms for latency distribution

        return response;
    }
}
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall