-
Notifications
You must be signed in to change notification settings - Fork 856
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
Make spring boot service name detector handle BOOT-INF/classes #8101
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
id("otel.java-conventions") | ||
} | ||
|
||
dependencies { | ||
testCompileOnly("com.google.auto.service:auto-service-annotations") | ||
|
||
testImplementation("org.mockito:mockito-junit-jupiter") | ||
testImplementation(project(":instrumentation:spring:spring-boot-resources:library")) | ||
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi") | ||
testImplementation(project(path = ":smoke-tests:images:spring-boot", configuration = "springBootJar")) | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,33 @@ | ||||||||||||||
/* | ||||||||||||||
* Copyright The OpenTelemetry Authors | ||||||||||||||
* SPDX-License-Identifier: Apache-2.0 | ||||||||||||||
*/ | ||||||||||||||
|
||||||||||||||
package io.opentelemetry.instrumentation.spring.resources; | ||||||||||||||
|
||||||||||||||
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME; | ||||||||||||||
import static org.assertj.core.api.Assertions.assertThat; | ||||||||||||||
|
||||||||||||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||||||||||||||
import io.opentelemetry.sdk.resources.Resource; | ||||||||||||||
import org.junit.jupiter.api.Test; | ||||||||||||||
import org.junit.jupiter.api.extension.ExtendWith; | ||||||||||||||
import org.mockito.Mock; | ||||||||||||||
import org.mockito.junit.jupiter.MockitoExtension; | ||||||||||||||
|
||||||||||||||
@ExtendWith(MockitoExtension.class) | ||||||||||||||
class TestBootInfClassesResource { | ||||||||||||||
@Mock ConfigProperties config; | ||||||||||||||
|
||||||||||||||
@Test | ||||||||||||||
void testServiceName() { | ||||||||||||||
// verify that the test app, that is added as a dependency to this project, has the expected | ||||||||||||||
// layout | ||||||||||||||
assertThat(getClass().getResource("/application.properties")).isNull(); | ||||||||||||||
assertThat(getClass().getResource("/BOOT-INF/classes/application.properties")).isNotNull(); | ||||||||||||||
|
||||||||||||||
SpringBootServiceNameDetector guesser = new SpringBootServiceNameDetector(); | ||||||||||||||
Resource result = guesser.createResource(config); | ||||||||||||||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copy pasted from Lines 49 to 50 in 195fd38
WDYT about renaming this in both tests after this is merged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sure. I think |
||||||||||||||
assertThat(result.getAttribute(SERVICE_NAME)).isEqualTo("otel-spring-test-app"); | ||||||||||||||
} | ||||||||||||||
} |
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 getting the context CL necessary? This class runs in SDK setup time; in the javaagent it shouldn't have any context CL set (I've removed the
setContextClassLoader
calls a while ago)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.
There isn't anything that says this has to be used only with javaagent. I think the context class loader defaults to system when it is not set (not set to null or some other class loader by the user).