-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bridge agent logs into application's slf4j logger #7339
Bridge agent logs into application's slf4j logger #7339
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems cool to me. I'd love a small demo to see it in action, maybe in the sig somtime?
...on-api/src/main/java/io/opentelemetry/instrumentation/api/internal/ConfigPropertiesUtil.java
Show resolved
Hide resolved
|
||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void onExit() { | ||
Slf4jApplicationLoggerBridge.install(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not immediately clear to me why this installation needs to happen in this instrumentation. Is there not another lifecycle hook that makes sense for this? If not (like maybe we only want to do this when slf4j is actually in the runtime mix?), maybe a comment could help to clarify why this should be wired via bytecode instead of agent lifecycle hookery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there not another lifecycle hook that makes sense for this?
There is not - this needs to be initialized from the application code, because we need to grab a handle to the application's slf4j. This can pretty much only be done in an instrumentation.
@Override | ||
public boolean defaultEnabled(ConfigProperties config) { | ||
// only enable this instrumentation if the application logger is enabled | ||
return config.getString("otel.javaagent.logging", "simple").equalsIgnoreCase("application"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this was around before this PR, but I don't see mention of it in any readme/notes/docs (and I also search the docs repo). Can we please get this added somewhere or an issue created to do that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was planning to add some docs once this PR is accepted. Will create an issue when this is merged.
...nt-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/ApplicationLoggerBridge.java
Outdated
Show resolved
Hide resolved
if (bridge != null) { | ||
bridge.install(applicationLoggerFactory); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relationship between set()
and installApplicationLogger()
is a little confusing. I wish there was just one method...but I'm sure there are timing considerations that make this challenging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, there need to be 2 steps to initialize this thing. The names could be better, but I didn't manage to think up anything less confusing. Suggestions welcome 😄
...plication/src/main/java/io/opentelemetry/javaagent/logging/application/InMemoryLogStore.java
Outdated
Show resolved
Hide resolved
...plication/src/main/java/io/opentelemetry/javaagent/logging/application/InMemoryLogStore.java
Outdated
Show resolved
Hide resolved
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentStarterImpl.java
Outdated
Show resolved
Hide resolved
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/NoopLoggingCustomizer.java
Show resolved
Hide resolved
...ng-application/src/main/java/io/opentelemetry/javaagent/logging/application/InMemoryLog.java
Outdated
Show resolved
Hide resolved
e235600
to
0fcbedc
Compare
0fcbedc
to
4ad2805
Compare
4ad2805
to
3cf626f
Compare
Rebased with main, @open-telemetry/java-instrumentation-maintainers PTAL |
Related discussion #7257
Resolves #3413
Resolves #5059
Resolves #6258
Resolves #7179
Adds a logging implementation that'll collect agent logs in memory until slf4j is detected in the instrumented application; and when that happens will dump all the logs into the application slf4j and log directly to the application logger from that time on.
It's still in a POC state, unfortunately: while it works fine with an app that uses & initializes slf4j directly, Spring Boot applications actually reconfigure the logging implementation (e.g. logback) a while after slf4j is loaded; which causes all the startup agent logs (debug included) to be dumped with the default logback pattern.
Future work:
Make sure all logs produces by the agent are sent to loggers namedDONEio.opentelemetry...
(Muzzle logs should be logged using the io.opentelemetry.* logger name #7446)