apache / logging-log4j2

Apache Log4j 2 is a versatile, feature-rich, efficient logging API and backend for Java.
https://logging.apache.org/log4j/2.x/
Apache License 2.0
3.35k stars 1.59k forks source link

Add support for defining internal metrics #2027

Open jvz opened 9 months ago

jvz commented 9 months ago

Related to https://issues.apache.org/jira/browse/LOG4J2-2937 (provide counters for logger rates) and #1927, we need some sort of basic metrics API we can use internally for exporting said metrics into a metrics library. This should not be created as brand new metrics API (if we want to do that, then we'd probably start somewhere like having additional modules which implement various OpenTelemetry APIs for better reusability), but it does need to define enough of an API so that various metrics collectors can use this. I've seen some similar ideas before in various Spring libraries before Spring Framework 6 integrated Micrometer everywhere as the general metrics API, so there may be some inspiration to take.

jack-berg commented 9 months ago

Hi 👋 - I'm a maintainer from opentelemetry-java.

Just wanted to chime in with a few notes about the OpenTelemetry API for your consideration:

If you're considering adding metrics to log4j, consider using the OpenTelemetry metrics API, available at maven coordinates io.opentelemetry:opentelemetry-api. I believe it will give you the API functionality required while being highly configurable for users.

jvz commented 9 months ago

We've got a couple sides to metrics: defining metrics within Log4j itself, and direct support for OpenTelemetry APIs. As Log4j itself does not depend on anything besides the java.base module, we need some level of indirection to support the same thing OpenTelemetry is doing with the API/SDK split (no-op by default, require an actual metrics implementation to collect and forward them). I see that the Java OpenTelemetry API modules are designed similarly (not sure about the required Java modules there, but I assume they're similarly lightweight). Thus, I'd expect the default metrics plugin for Log4j to use OpenTelemetry since that makes it much easier to configure all those other integrations, though if third party extensions create plugins that directly use some vendor tool or whatever, that's also fine (but probably easier to do via OpenTelemetry).

From a higher level, though, we'd like to consider how to best integrate with OpenTelemetry to aid with standardizing the operational side of things, but that's a different topic.

ppkarwasz commented 4 months ago

This should be fixed by #2469