Claus Ibsen created CAMEL-24551:
-----------------------------------

             Summary: Expose structured error metadata (category, retry-after) 
as Exchange properties when an AI producer call fails
                 Key: CAMEL-24551
                 URL: https://issues.apache.org/jira/browse/CAMEL-24551
             Project: Camel
          Issue Type: Improvement
          Components: camel-openai
            Reporter: Claus Ibsen


When OpenAIProducer (and the equivalent langchain4j/spring-ai producers) catch 
a RuntimeException before rethrowing it for observability (e.g. 
OpenAIProducer.java ~714-738), they currently only call 
observation.recordError(e). Propose also setting a small set of Exchange 
properties derived from the underlying SDK exception, e.g.:

- CamelAiErrorCategory (e.g. RATE_LIMIT, SERVER_ERROR, VALIDATION, AUTH, 
UNKNOWN) — classified from the SDK's typed exception hierarchy 
(RateLimitException, InternalServerException, UnprocessableEntityException, 
BadRequestException, UnauthorizedException).
- CamelAiRetryAfterMillis — populated when available (e.g. from a 429's 
Retry-After header), so an onException handler can react without reaching into 
SDK-internal exception fields.

This should live in the shared camel-ai-observability-api module (or a 
similarly shared camel-ai module) so all four producers (openai, 
langchain4j-chat/agent/embeddings, spring-ai-chat) get it consistently rather 
than duplicating logic. No behavior change to what's thrown — properties are 
additive, set right before the exception propagates.

Related to CAMEL-24550 (documentation for targeted onException handling), which 
should reference these new properties once available.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to