logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

Create metrics API proof of concept

Open jvz opened this issue 1 year ago • 6 comments

Related to #1344, this demonstrates a proof of concept metrics API to begin using. This implements the metric added in #1927, though I think we should be defining several more metrics beyond that. Before going too far into this idea, here's the gist of what I've come up with so far. API is loosely based on Micrometer which will be added as an implementation (probably its own module; this is effectively a plugin).

jvz avatar Nov 03 '23 22:11 jvz

This PR has me very confused. I do see the new metrics package but the vast majority of this PR seems to have nothing to do with metrics. Could you please separate out the builder improvements into their own PR?

rgoers avatar Nov 05 '23 04:11 rgoers

The builder updates are related to adding dependency-injected values. I did not include any concrete implementations of the metrics API yet, but I updated some areas that are supposed to export metrics.

jvz avatar Nov 07 '23 19:11 jvz

Or to be more specific, instead of creating yet another global variable, I had to refactor some code to apply inversion of control a little bit. If we were adapting Log4j to work via Spring beans, we'd still have to do the exact same thing.

jvz avatar Nov 07 '23 19:11 jvz

What sort of event would be published here that could correspond to a counter? That's a push-based mechanism itself.

jvz avatar Nov 11 '23 01:11 jvz

Looking through https://opentelemetry.io/docs/specs/otel/logs/ and OTel in general, it seems like we should have support for some of this directly. I don't think we need to implement all the APIs (like metrics and traces, though they might be natural logging APIs to include in the future). The alternative is a dependency stack larger than Log4j 2.x with optional dependencies in practice.

jvz avatar Nov 11 '23 01:11 jvz

What sort of event would be published here that could correspond to a counter? That's a push-based mechanism itself.

For me an event is just any kind of object: in this case long is an event. ;-) So stripped to the bone we need methods that return long and methods that consume Supplier<Long>.

ppkarwasz avatar Nov 17 '23 22:11 ppkarwasz

@jvz,

I think we could choose an approach similar to RxJavaHooks to provide instrumentation hooks without affecting the performance of our application.

For 2.x we could create an InstrumentationService to give users the possibility to wrap our most important services:

public interface InstrumentationService {

    ReliabilityStrategy instrumentReliabilityStrategy(ReliabilityStrategy strategy);

    MessageFactory instrumentMessageFactory(MessageFactory factory);

    LogEventFactory instrumentEventFactory(LogEventFactory factory);

    AsyncQueueFullPolicy instrumentQueueFullPolicy(AsyncQueueFullPolicy policy);

    Appender instrumentAppender(Appender appender);
}

The default implementation would of course return the argument unchanged. What do you think?

For 3.x I believe that users can use the DI system to post-process these services.

Can we close this PR?

ppkarwasz avatar Apr 05 '24 10:04 ppkarwasz

I think that's a good idea.

jvz avatar Apr 05 '24 19:04 jvz