NewRelic Metrix error
Closed this issue · 3 comments
Description:
Following issue is occuring after installing newrelic 8.9.1 in java 11.
failed to send metrics to new relic: {}.
[Troubleshooting]
Upon further debugging I found that NewRelicMeterRegistery where there is function:
`private void sendEvents(String insightsEndpoint, Stream events) {
try {
AtomicInteger totalEvents = new AtomicInteger();
this.httpClient.post(insightsEndpoint).withHeader("X-Insert-Key", this.config.apiKey()).withJsonContent((String)events.peek((ev) -> {
totalEvents.incrementAndGet();
}).collect(Collectors.joining(",", "[", "]"))).send().onSuccess((response) -> {
this.logger.debug("successfully sent {} metrics to New Relic.", totalEvents);
}).onError((response) -> {
this.logger.error("failed to send metrics to new relic: {}", response.body());
});
} catch (Throwable var4) {
this.logger.warn("failed to send metrics to new relic", var4);
}
}`
Its bringing api key from NewRelicConfig class:
default String apiKey() { String v = this.get(this.prefix() + ".apiKey"); if (v == null) { throw new MissingRequiredConfigurationException("apiKey must be set to report metrics to New Relic"); } else { return v; } }
which is extending StepRegisteryPropertiesConfigAdapter which always return null. So its always returning exception.
public String get(String k) { return null; }
The code you mention is not supported by New Relic, it is supported by Micrometer and we have no control over that.
Here is a link to the code in question in the Micrometer repository.
The New Relic Java agent does not support Micrometer.
New Relic recommends using the OTEL Micrometer Registry to send Micrometer data to New Relic.
Here is an example project that uses the OTEL Micrometer Registry.