{"record":{"id":"509441f4eed338b0","repo":"pinpoint-apm/pinpoint","slug":"failed-to-create-metricid-metricname","errorCode":null,"errorMessage":"Failed to create MetricId. metricName:{}","messagePattern":"Failed to create MetricId\\. metricName:(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/metric/CustomMetricIdGenerator.java","lineNumber":51,"sourceCode":"\n    private final Logger logger = LogManager.getLogger(this.getClass());\n\n    private final Object lockObject = new Object();\n\n    private final int limitIdNumber;\n\n    private final Map<String, Integer> metricNameToIdMap = new HashMap<>();\n\n    private int currentId = 0;\n\n    CustomMetricIdGenerator(int limitIdNumber) {\n        Assert.isTrue(limitIdNumber > 0, \"'limitIdNumber' must be >= 0\");\n        this.limitIdNumber = limitIdNumber;\n    }\n\n    int create(String metricName) {\n        if (!checkValidCustomMetricName(metricName)) {\n            logger.warn(\"Failed to create MetricId. metricName:{}\", metricName);\n            return NOT_REGISTERED;\n        }\n\n        synchronized (lockObject) {\n            if (currentId >= limitIdNumber) {\n                return NOT_REGISTERED;\n            }\n\n            boolean contains = metricNameToIdMap.containsKey(metricName);\n            if (contains) {\n                return NOT_REGISTERED;\n            }\n\n            ++currentId;\n            metricNameToIdMap.put(metricName, currentId);\n            return currentId;\n        }\n    }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/metric/CustomMetricIdGenerator.java#L33-L69","documentation":"CustomMetricIdGenerator.create(metricName) validates the custom metric name before assigning an ID. If the name fails checkValidCustomMetricName (e.g. disallowed characters, wrong length, or an exception during validation), it logs \"Failed to create MetricId\" and returns NOT_REGISTERED (-1). The custom metric is simply not registered; no exception is thrown to the caller.","triggerScenarios":"Calling register() on DefaultCustomMetricRegistryService with an IntCounter/LongCounter whose name contains characters outside the allowed set (per the validator's regex/charset check), is empty, too long, or triggers an exception in the validation loop.","commonSituations":"Users building custom metrics from dynamic strings (URIs, class names) containing invalid characters; names with non-ASCII characters; names exceeding the length limit; metric names containing dots/special symbols not whitelisted.","solutions":["Rename the metric to contain only allowed characters (alphanumeric and underscore are safe) and keep it within the length limit.","Sanitize dynamic name components before constructing IntCounter/LongCounter (replace invalid chars).","Check the return of register()/the id against NOT_REGISTERED and log the offending name in your own code.","Read checkValidCustomMetricName in CustomMetricIdGenerator to confirm the exact allowed pattern for your Pinpoint version."],"exampleFix":"// before\nIntCounter counter = new IntCounterCounterAdapter(\"my.metric/name!\");\nregistryService.register(counter);\n// after\nString safeName = rawName.replaceAll(\"[^A-Za-z0-9_]\", \"_\");\nregistryService.register(new IntCounterCounterAdapter(safeName));","handlingStrategy":"validation","validationCode":"boolean isValidMetricName(String name) {\n    return name != null && name.matches(\"[A-Za-z0-9_]+\") && name.length() <= 255;\n}\n// call only if isValidMetricName(rawName) before register()","typeGuard":"boolean validName(String s) { return s instanceof String && !((String) s).isEmpty() && ((String) s).matches(\"[A-Za-z0-9_]+\"); }","tryCatchPattern":null,"preventionTips":["Sanitize dynamic name components (replace [^A-Za-z0-9_] with _).","Keep names ASCII, alphanumeric+underscore, and short.","Check register()'s return value / id != NOT_REGISTERED.","Read checkValidCustomMetricName for your Pinpoint version's exact rules."],"tags":["metrics","naming","validation","custom-metric"],"backgroundTag":"invalid-identifier-format","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}