{"id":"7ad5ee02e1823a09","repo":"apache/kafka","slug":"could-not-find-attribute-name","errorCode":null,"errorMessage":"Could not find attribute {name}","messagePattern":"Could not find attribute (.+?)","errorType":"exception","errorClass":"AttributeNotFoundException","httpStatus":null,"severity":"warning","filePath":"clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java","lineNumber":242,"sourceCode":"        KafkaMbean(String mbeanName) throws MalformedObjectNameException {\n            this.metrics = new HashMap<>();\n            this.objectName = new ObjectName(mbeanName);\n        }\n\n        public ObjectName name() {\n            return objectName;\n        }\n\n        void setAttribute(String name, KafkaMetric metric) {\n            this.metrics.put(name, metric);\n        }\n\n        @Override\n        public Object getAttribute(String name) throws AttributeNotFoundException {\n            if (this.metrics.containsKey(name))\n                return this.metrics.get(name).metricValue();\n            else\n                throw new AttributeNotFoundException(\"Could not find attribute \" + name);\n        }\n\n        @Override\n        public AttributeList getAttributes(String[] names) {\n            AttributeList list = new AttributeList();\n            for (String name : names) {\n                try {\n                    list.add(new Attribute(name, getAttribute(name)));\n                } catch (Exception e) {\n                    log.warn(\"Error getting JMX attribute '{}'\", name, e);\n                }\n            }\n            return list;\n        }\n\n        KafkaMetric removeAttribute(String name) {\n            return this.metrics.remove(name);\n        }","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java#L224-L260","documentation":"Thrown by KafkaMbean.getAttribute(String) when a JMX client queries an attribute name that the mbean does not contain. JmxReporter's KafkaMbean is a DynamicMBean whose attributes are the metric names it has registered; asking for any other name raises AttributeNotFoundException. The message echoes the requested attribute name so the offending query is identifiable.","triggerScenarios":"An external JMX client (jconsole, jmc, Prometheus JMX exporter, custom JMX query) calls getAttribute on a Kafka mbean with a name the mbean never registered. Occurs when a metric was removed (metricName removed via Metrics.removeMetric) but the JMX client still queries the old attribute, or when the client uses a guessed/hardcoded attribute name that does not match the metricName name in Kafka.","commonSituations":"Monitoring tooling or dashboards configured against an older Kafka version where metric names differed; a metric dynamically added/removed at runtime (e.g. per-partition sensors) while a polling JMX client keeps asking for the now-absent attribute; JMX exporter rules (jmx_exporter) listing metrics by name that have since been renamed in Kafka; scripted JMX automation that iterates an assumed set of names and hits one that is not present.","solutions":["Confirm the attribute name in the message matches a real Kafka metric — list the mbean's actual attributes with jconsole/jmc or Jolokia's list operation.","Update your JMX client / monitoring config to use the current metric names for your Kafka version (metric names have changed across major versions — check the upgrade notes).","If polling dynamic metrics, treat AttributeNotFoundException as a non-fatal 'metric not present' signal and skip rather than erroring.","Verify the metric hasn't been removed at runtime — check Metrics.removeMetric / sensor lifecycle in your code.","Pin a consistent Kafka version across the cluster and monitoring stack so metric names do not drift out from under dashboards."],"exampleFix":"// before — exporter config lists an old attribute that no longer exists\nrules:\n  - pattern: 'kafka.producer<type=producer-metrics><>(.*):'  # wrong/old name\n    name: kafka_producer_$1\n# JMX client -> AttributeNotFoundException: Could not find attribute ...\n\n// after — name aligned to the running Kafka version's actual metric\nrules:\n  - pattern: 'kafka.producer<type=producer-metrics><>compression-rate-avg'\n    name: kafka_producer_compression_rate_avg","handlingStrategy":"validation","validationCode":"// Before reading a JMX attribute, confirm it exists on the mbean.\nMBeanServer server = ManagementFactory.getPlatformMBeanServer();\nObjectName on = ...;\nString attr = \"records-rate\";\nMBeanInfo info = server.getMBeanInfo(on);\nboolean present = Arrays.stream(info.getAttributes())\n        .anyMatch(a -> a.getName().equals(attr));\nif (present) {\n    Object value = server.getAttribute(on, attr);\n} else {\n    // skip / report unknown metric\n}","typeGuard":"// Narrow a JMX attribute name to 'one this mbean actually exposes'.\nstatic Set<String> availableAttributes(MBeanServer server, ObjectName on) throws JMException {\n    return Arrays.stream(server.getMBeanInfo(on).getAttributes())\n                 .map(MBeanAttributeInfo::getName)\n                 .collect(Collectors.toSet());\n}","tryCatchPattern":"try {\n    Object v = server.getAttribute(objectName, attributeName);\n} catch (AttributeNotFoundException e) {\n    // metric was removed or never existed; treat as 'not available' rather than an error.\n    log.debug(\"JMX attribute {} not present on {}\", attributeName, objectName);\n    return Optional.empty();\n}","preventionTips":["Do not hard-code JMX attribute names in dashboards; discover them from getMBeanInfo() so removed metrics do not break scraping.","Metric attribute names are derived from MetricName.name(); reference the same constants when querying.","When scraping Kafka JMX, log AttributeNotFoundException at DEBUG and skip — it is expected during metric churn.","Refresh the attribute list after metric reconfiguration rather than caching forever."],"tags":["kafka-clients","jmx","metrics","jmx-reporter","monitoring","version-compat"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}