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

feat: add logs and update deps in java services #990

Merged
merged 10 commits into from
Mar 28, 2024

Conversation

JamieDanielson
Copy link
Contributor

@JamieDanielson JamieDanielson commented Mar 11, 2024

Which problem is this PR solving?

Short description of the changes

  • update all deps in java services
  • update java year to use vanilla otel, specifically the java agent
  • update java year to use log4j logs
  • update docker-compose.java.yml to include OTEL_LOGS_EXPORTER=otlp

Some findings:

  • Using java agent <2.x, set OTEL_LOGS_EXPORTER=otlp
  • Using java agent >=2.x, exporter is enabled by default
  • For more fine-tuning, use log4j2.xml or in this specific service that uses Springboot, use log4j2-spring.xml. Some instructions are here and here.
  • I tried getting a better JSON-formatted log but it didn't quite look as I wanted and so I wasn't sure it was worth it to add here (would be included in above step). I tried both JSONLayout (deprecated) and JsonTemplateLayout.
  • Also for the log itself, the MapMessage showed up in Honeycomb as an empty string "", whereas ObjectMessage showed {selected_year=2015} which is why I went with it. Maybe that's something to look further into, as MapMessage seems like it might be a nicer format.

How to verify this has the expected result

From the root directory run tilt up java, or from the java year service set env vars including OTEL_LOGS_EXPORTER=otlp then ./gradlew build and ./gradlew bootRun... and curl the endpoint curl localhost:6001/year.

The log for selected year should show up in Honeycomb on the YearService.getYear span

@JamieDanielson JamieDanielson requested a review from a team as a code owner March 11, 2024 22:15
@JamieDanielson JamieDanielson self-assigned this Mar 11, 2024
@JamieDanielson JamieDanielson added the type: enhancement New feature or request label Mar 11, 2024
@JamieDanielson JamieDanielson marked this pull request as draft March 11, 2024 22:15
gradlew scripts were already there for year service, so
this is just an update to those files.
other services did not have them at all.
according to baeldung/gradle-wrapper, these are
recommended to be checked into source control
to allow devs to run the project without needing to
install gradle.
@JamieDanielson JamieDanielson marked this pull request as ready for review March 18, 2024 21:59
@JamieDanielson
Copy link
Contributor Author

JamieDanielson commented Mar 18, 2024

So this works, but there's 2 main problems with it in my mind:

  1. It seems to require 2.x of java agent to work out of the box. I think this is because the appender is included with the spring boot starter now by default and some other configuration with the log sdk might be necessary otherwise, which gets weird with the agent and avoiding double initialization.
  2. Structured logs are not really working as the log body is just {selected_year=2020}. I've tried various forms of JSONLayout but I think the log4j2.xml file isn't actually being picked up and used properly.

Edit: updated to include environment variable and added extra notes to PR description. This works OOTB for both 1.x and 2.x of otel-java, just needs the OTEL_LOGS_EXPORTER env var on 1.x.

removing log4j2.xml bc its not used at all.
log4j2-spring.xml would be used and it
would require some changes to log pkgs
so for now we'll just keep defaults.

if using the sdk instead of the java agent,
this work would be required, as would
the other packages like the appender.
Copy link
Member

@robbkidd robbkidd left a comment

Choose a reason for hiding this comment

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

Screenshot 2024-03-28 at 3 09 19 PM

@JamieDanielson JamieDanielson merged commit 619d38e into main Mar 28, 2024
3 checks passed
@JamieDanielson JamieDanielson deleted the jamie.update-java-with-logs branch March 28, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

java year-service using honeycomb-opentelemetry-sdk
2 participants