Skip to content

Conversation

@felixbarny
Copy link
Member

@felixbarny felixbarny commented Feb 2, 2022

What does this PR do?

  • Documents service name auto discovery mechanisms
  • Documents how to set Implementation-Title and Implementation-Version manifest entries with maven
  • Avoid standalone spring applications to have two different service names, one based on the jar name, the other based on spring.application.name.

Checklist

  • This is an enhancement of existing features, or a new feature in existing plugins
    • I have updated CHANGELOG.asciidoc
    • I have added tests that prove my fix is effective or that my feature works
    • [ ] Added an API method or config option? Document in which version this will be introduced
    • I have made corresponding changes to the documentation

@ghost
Copy link

ghost commented Feb 2, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Reason: null

  • Start Time: 2022-02-03T14:56:48.922+0000

  • Duration: 52 min 28 sec

  • Commit: 8b63bf0

Test stats 🧪

Test Results
Failed 0
Passed 2488
Skipped 16
Total 2504

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run benchmark tests : Run the benchmark tests.

  • run jdk compatibility tests : Run the JDK Compatibility tests.

  • run integration tests : Run the Agent Integration tests.

  • run end-to-end tests : Run the APM-ITs.

  • run windows tests : Build & tests on windows.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@felixbarny felixbarny added the await-release Mark issues that depend on next release, or PRs that are planned to be included label Feb 3, 2022
public static void afterInitPropertySources(@Advice.This WebApplicationContext applicationContext) {
// avoid having two service names for a standalone jar
// one based on Implementation-Title and one based on spring.application.name
if (!ServiceInfo.autoDetected().isMultiServiceContainer()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Some background:
The risk of that is that if we don't properly detect that we're running on an application server/servlet container. In that case, we wouldn't be able to determine the service name based on spring.application.name. That's why I didn't add the check in Tracer.overrideServiceInfoForClassLoader but made it specific to this instrumentation. This way, we at least can still override based on the servlet context path and the display-name. It's quite unlikely that a standalone application that's using embedded Tomcat, for example, sets a display-name or even a servlet context path. Therefore, if any of these are set, that's a pretty good indication that we're running in a container and not in a standalone jar.

public static void afterInitPropertySources(@Advice.This WebApplicationContext applicationContext) {
// avoid having two service names for a standalone jar
// one based on Implementation-Title and one based on spring.application.name
if (!ServiceInfo.autoDetected().isMultiServiceContainer()) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we could still honor the spring application name here in case the manifest entry is not set.

  • If the manifest entry is available, we make isMultiServiceContainer() return false and then ServiceInfo.autoDetected() will match what was read in the manifest
  • If the manifest entry is not available, we should still set it, so in the case of our test application it should still work as expected.

Copy link
Member

Choose a reason for hiding this comment

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

Clarified this through an offline discussion: we have another fallback here for the ServiceInfo.autoDetected() that relies on the .jar name. Unfortunately when running in the IDE the test app is not packaged and thus not available.

assertThat(transaction.getTraceContext().getServiceName()).isEqualTo("spring-boot-test");
// as this test runs in a standalone application and not in a servlet container,
// the service.name will not be overwritten for the webapp class loader based on spring.application.name
assertThat(transaction.getTraceContext().getServiceName()).isNull();
Copy link
Member

Choose a reason for hiding this comment

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

We should be able to still support this in the case where the auto-detected value is not read from manifest (see previous comment).

@felixbarny felixbarny merged commit 4c37214 into elastic:main Feb 3, 2022
@felixbarny felixbarny deleted the service-name-polishing branch February 3, 2022 16:24
@felixbarny felixbarny removed the await-release Mark issues that depend on next release, or PRs that are planned to be included label Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants