pinpoint-apm/pinpoint · warning
Failed to create MetricId. metricName:{}
Error message
Failed to create MetricId. metricName:{} What it means
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.
Source
Thrown at agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/metric/CustomMetricIdGenerator.java:51
private final Logger logger = LogManager.getLogger(this.getClass());
private final Object lockObject = new Object();
private final int limitIdNumber;
private final Map<String, Integer> metricNameToIdMap = new HashMap<>();
private int currentId = 0;
CustomMetricIdGenerator(int limitIdNumber) {
Assert.isTrue(limitIdNumber > 0, "'limitIdNumber' must be >= 0");
this.limitIdNumber = limitIdNumber;
}
int create(String metricName) {
if (!checkValidCustomMetricName(metricName)) {
logger.warn("Failed to create MetricId. metricName:{}", metricName);
return NOT_REGISTERED;
}
synchronized (lockObject) {
if (currentId >= limitIdNumber) {
return NOT_REGISTERED;
}
boolean contains = metricNameToIdMap.containsKey(metricName);
if (contains) {
return NOT_REGISTERED;
}
++currentId;
metricNameToIdMap.put(metricName, currentId);
return currentId;
}
}View on GitHub (pinned to 744c3d3075)
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.
Example fix
// before
IntCounter counter = new IntCounterCounterAdapter("my.metric/name!");
registryService.register(counter);
// after
String safeName = rawName.replaceAll("[^A-Za-z0-9_]", "_");
registryService.register(new IntCounterCounterAdapter(safeName)); Defensive patterns
Strategy: validation
Validate before calling
boolean isValidMetricName(String name) {
return name != null && name.matches("[A-Za-z0-9_]+") && name.length() <= 255;
}
// call only if isValidMetricName(rawName) before register() Type guard
boolean validName(String s) { return s instanceof String && !((String) s).isEmpty() && ((String) s).matches("[A-Za-z0-9_]+"); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Inserted customMetricName({}) is not valid. cause:{}
- customMetricName must consist of {GroupName}/{MetricName}/La
- Resource attribute `service.name` is required to save OTLP m
- invalid pinpoint.agentName=${agentName}
- Invalid applicationName
AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07).
Data as JSON: /api/errors/509441f4eed338b0.
Report an issue: GitHub.