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 8 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

@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.

Thank you for this PR.

I have added comments.

This documentation link could perhaps be added: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/logback/logback-appender-1.0/javaagent/README.md

```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.

Copy link
Contributor

Choose a reason for hiding this comment

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

http/protobuf is also the recommended default in the spec. Would prefer to use that over grpc.

Copy link
Author

Choose a reason for hiding this comment

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

This is addressed in the follow-up changes.

* 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.

@smoke smoke force-pushed the example/javaagent-log4j2-appender branch from b4beac8 to da88e35 Compare October 17, 2024 10:59
@smoke
Copy link
Author

smoke commented Oct 17, 2024

@jeanbisutti Thanks for your review! I have made changes to address your remarks, please re-review.

mainClass = "io.opentelemetry.example.logappender.Application"
}


Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

* 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/javaagent/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.

I don't follow what it means.
Is it needed?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it is needed, I have clarified it further.

the [OpenTelemetry Log4J Appender](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/log4j/log4j-appender-2.17/javaagent/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/javaagent/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.

I don't follow what it means.
Is it needed?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it is needed, I have clarified it further.

receivers:
otlp:
protocols:
grpc:
Copy link
Member

Choose a reason for hiding this comment

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

Lines 4 and 5 don't seem necessary

Copy link
Author

Choose a reason for hiding this comment

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

* Log4j API [configured](./src/main/resources/log4j2.xml) to print logs to the
console and
the OpenTelemetry Java Agent brings built-in
[OpenTelemetry Log4J Appender](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/log4j/log4j-appender-2.17/javaagent/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.

* SLF4J API [configured with Logback](./src/main/resources/logback.xml) to
print logs to the console and
the OpenTelemetry Java Agent brings built-in
[OpenTelemetry Logback Appender](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/logback/logback-appender-1.0/javaagent/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.

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.

3 participants