Skip to content
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

Example of Log Appenders when using OpenTelemetry JavaAgent #503

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

smoke
Copy link

@smoke smoke commented Oct 10, 2024

No description provided.

@smoke smoke requested review from a team as code owners October 10, 2024 09:19
@smoke smoke marked this pull request as draft October 10, 2024 14:37
@smoke smoke marked this pull request as ready for review October 11, 2024 07:57
@smoke
Copy link
Author

smoke commented Oct 11, 2024

Such example was useful for me to explore how the log appending works when using JavaAgent and how to properly configure them.
I was under the impression logger xml files can be used to configure them accordingly, but this is not the case.

My final goal was to achieve ability to control from properties and env vars the Logs Sending and Level.
There is my PoC implementation smoke#1 that allows usage of these env vars or system properties defined in log4j2.xml:

  • LOG_LEVEL env var or logLevel property - controls the log4j2 Root (and inherited) loggers
    level
  • OTEL_X_LOG_SENDING_DISABLED env var or otel.x.log_sending.disabled property - set to "true" to fully disable the
    OpenTelemetryAppender
  • OTEL_X_LOG_SENDING_LEVEL env var or otel.x.log_sending.level property - defaults to "all", set to relevant log4j2 Level
    (off, fatal, error, warn, info, debug, trace, all) to additionally filter what goes to Otel Collector

…operties

JavaAgent instrumentation of Log Appenders does not respect logger configs like `log4j2.xml` or `logback.xml`
as it uses direct patching of loggers to do the same and no appenders set in the loggers.
@smoke smoke force-pushed the example/javaagent-log4j2-appender branch from ec6b8fa to b4beac8 Compare October 11, 2024 07:59
Copy link
Member

@jeanbisutti jeanbisutti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```shell
export \
OTEL_SERVICE_NAME=log4j-example \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Java agent uses http/protobuf by default. Perhaps this example could use the default protocol as the Java agent example is doing, and a new example could be created to illustrate the gprc usage.

* The application is configured with a variety of log solutions:
* Log4j API [configured](./src/main/resources/log4j2.xml) to print logs to the
console and
the [OpenTelemetry Log4J Appender](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/log4j/log4j-appender-2.17/library/README.md).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The application does not use the OpenTelemetry Log4j Appender library but the Java agent out-of-the-box instrumentation for Log4j.

the [OpenTelemetry Log4J Appender](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/log4j/log4j-appender-2.17/library/README.md).
* SLF4J API [configured with Logback](./src/main/resources/logback.xml) to
print logs to the console and
the [OpenTelemetry Logback Appender](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/logback/logback-appender-1.0/library/README.md).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The application does not use the OpenTelemetry Logback Appender library but the Java agent out-of-the-box instrumentation for Logback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants