{"record":{"id":"7e1f4324211096a4","repo":"pinpoint-apm/pinpoint","slug":"failed-to-create-metricid-metric","errorCode":null,"errorMessage":"Failed to create metricId. metric:{}","messagePattern":"Failed to create metricId\\. metric:(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/metric/DefaultCustomMetricRegistryService.java","lineNumber":67,"sourceCode":"\n    public DefaultCustomMetricRegistryService(int limitIdNumber, CustomMetricRegistryFilter filter) {\n        this.customMetricIdGenerator = new CustomMetricIdGenerator(limitIdNumber);\n        this.filter = Objects.requireNonNull(filter, \"filter\");\n    }\n\n    @Override\n    public boolean register(IntCounter intCounter) {\n        Objects.requireNonNull(intCounter, \"intCount\");\n\n        boolean filter = this.filter.filter(intCounter);\n        if (filter) {\n            LOGGER.warn(\"Failed to register CustomMetric({}). message:not allowed metric\", intCounter);\n            return false;\n        }\n\n        int id = customMetricIdGenerator.create(intCounter.getName());\n        if (id == CustomMetricIdGenerator.NOT_REGISTERED) {\n            LOGGER.warn(\"Failed to create metricId. metric:{}\", intCounter);\n            return false;\n        }\n\n        IntCounterWrapper customMetricWrapper = customMetricWrapperFactory.create(id, intCounter);\n        return add(customMetricWrapper);\n    }\n\n    @Override\n    public boolean register(LongCounter longCounter) {\n        Objects.requireNonNull(longCounter, \"longCount\");\n\n        boolean filter = this.filter.filter(longCounter);\n        if (filter) {\n            LOGGER.warn(\"Failed to register CustomMetric({}). message:not allowed metric\", longCounter);\n            return false;\n        }\n\n        int id = customMetricIdGenerator.create(longCounter.getName());","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/metric/DefaultCustomMetricRegistryService.java#L49-L85","documentation":"After passing the filter, register(IntCounter) calls customMetricIdGenerator.create(name); if the generator returns NOT_REGISTERED (invalid name or the ID limit exhausted), the service logs \"Failed to create metricId\" and returns false. This means the metric name was either invalid (see CustomMetricIdGenerator validation) or the profiler already registered the maximum number of custom metric IDs (limitIdNumber).","triggerScenarios":"Registering an IntCounter with an invalid name (bad characters/length), or registering more distinct custom metrics than the configured limit (currentId >= limitIdNumber).","commonSituations":"Dynamically generating metric names per URL/user so the ID pool runs out; apps registering many metrics at startup; invalid names coming from unsanitized dynamic strings.","solutions":["Reduce the number of distinct custom metrics; aggregate dynamic values into a bounded label set.","Raise the custom metric ID limit in profiler configuration and restart the agent.","Sanitize metric names to satisfy CustomMetricIdGenerator validation.","Handle register() returning false gracefully so metric failures never affect business logic."],"exampleFix":"// before: unbounded dynamic names exhaust IDs\nregistryService.register(new IntCounterCounterAdapter(\"uri.\" + requestUri));\n// after: bound cardinality\nregistryService.register(new IntCounterCounterAdapter(\"uri.\" + normalizePattern(requestUri)));","handlingStrategy":"validation","validationCode":"// Bound cardinality before registering\nassert distinctMetricNames.size() <= MAX_CUSTOM_METRICS : \"too many custom metrics\";","typeGuard":"boolean registerable(IntCounter c) { return c.getName() != null && c.getName().matches(\"[A-Za-z0-9_]+\"); }","tryCatchPattern":"if (!registryService.register(counter)) {\n    logger.warn(\"metric {} not registered (invalid name or ID limit reached)\", counter.getName());\n}","preventionTips":["Avoid unbounded dynamic metric names (per-URL/per-user).","Raise the custom metric ID limit if you legitimately need many metrics.","Monitor the count of distinct registered custom metrics."],"tags":["metrics","limit-exceeded","id-exhaustion","custom-metric"],"backgroundTag":"limit-exceeded","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"}