{"record":{"id":"59f36d05ff62bf93","repo":"alibaba/spring-ai-alibaba","slug":"unknown-observation-method","errorCode":null,"errorMessage":"Unknown observation method: ","messagePattern":"Unknown observation method: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spring-boot-starters/spring-ai-alibaba-starter-config-nacos/src/main/java/com/alibaba/cloud/ai/agent/nacos/utils/ChatOptionsProxy.java","lineNumber":178,"sourceCode":"\t\t\t\treturn observationName;\n\n\t\t\tcase \"setObservationName\":\n\t\t\t\tif (args != null && args.length > 0) {\n\t\t\t\t\tobservationName = (String) args[0];\n\t\t\t\t}\n\t\t\t\treturn null;\n\n\t\t\tcase \"isObservationEnabled\":\n\t\t\t\treturn observationEnabled;\n\n\t\t\tcase \"setObservationEnabled\":\n\t\t\t\tif (args != null && args.length > 0) {\n\t\t\t\t\tobservationEnabled = (Boolean) args[0];\n\t\t\t\t}\n\t\t\t\treturn null;\n\n\t\t\tdefault:\n\t\t\t\tthrow new UnsupportedOperationException(\"Unknown observation method: \" + methodName);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 处理Object类的方法\n\t\t */\n\t\tprivate Object handleObjectMethod(String methodName, Object[] args, Object obj) {\n\t\t\tswitch (methodName) {\n\t\t\tcase \"toString\":\n\t\t\t\treturn \"CglibProxy{\" +\n\t\t\t\t\t\t\"chatOptions=\" + chatOptions +\n\t\t\t\t\t\t\", observationMetadata=\" + observationMetadata +\n\t\t\t\t\t\t\", observationName='\" + observationName + '\\'' +\n\t\t\t\t\t\t\", observationEnabled=\" + observationEnabled +\n\t\t\t\t\t\t'}';\n\n\t\t\tcase \"equals\":\n\t\t\t\tif (args != null && args.length > 0) {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-boot-starters/spring-ai-alibaba-starter-config-nacos/src/main/java/com/alibaba/cloud/ai/agent/nacos/utils/ChatOptionsProxy.java#L160-L196","documentation":"ChatOptionsProxy is a dynamic proxy that intercepts a known set of observation-related methods (e.g. toggling observationEnabled). Any method invocation on the proxy that is not in its handled list for observation methods falls through to a default case which throws UnsupportedOperationException('Unknown observation method: ' + name).","triggerScenarios":"Code calls an observation-interface method on the ChatOptionsProxy that handleObservationMethod's switch does not cover — e.g. a newly added method in an upgraded observation interface, or a typo'd/direct call to an unhandled getter/setter routed to the observation handler.","commonSituations":"Spring AI upgrade adds a new method to the observed interface and the proxy switch was not updated; passing the proxy to framework code that invokes methods the proxy author didn't anticipate; calling proxy methods directly in tests.","solutions":["Read the method name in the exception message and add a corresponding case to handleObservationMethod's switch in ChatOptionsProxy.","Upgrade/patch spring-ai-alibaba-starter-config-nacos to a version whose proxy covers the current interface.","Avoid invoking unsupported methods on the proxied options; unwrap to the underlying ChatOptions for those calls."],"exampleFix":"// before\ncase \"isObservationEnabled\": ... return null;\ndefault: throw new UnsupportedOperationException(...);\n// after\ncase \"isObservationEnabled\": ... return null;\ncase \"newObservationMethod\": return handleNewMethod(args); // added case\ndefault: throw new UnsupportedOperationException(...);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return proxied.someObservationMethod(); }\ncatch (UnsupportedOperationException e) {\n    if (e.getMessage().startsWith(\"Unknown observation method\")) { return invokeOnUnwrapped(originalOptions); }\n    throw e;\n}","preventionTips":["After Spring AI upgrades, re-check the proxy switch covers all interface methods","Call only documented observation methods on the proxy","Add a catch-all default that delegates to the underlying options instead of throwing, if extending the proxy"],"tags":["dynamic-proxy","unsupported-operation","observation","spring-ai"],"backgroundTag":"unsupported-operation","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}