Skip to content

Commit 63cf3ef

Browse files
committed
Fix SPI service file relocation during javaagent shading
When classes are relocated during shading (e.g., io.opentelemetry.instrumentation to io.opentelemetry.javaagent.shaded.instrumentation), the corresponding SPI files in META-INF/services/ were not being renamed to match the new class locations. This fix adds an eachFile block to the Shadow plugin configuration to rename SPI service files when shading is enabled. Now extensions can use the correct shaded class names in their SPI files. Fixes issue where InstrumenterCustomizerProvider and HttpClientUrlTemplateCustomizer SPI files needed to reference shaded class names but weren't being automatically renamed during the build process. Changes: - Added eachFile transformation to javaagent-shadowing.gradle.kts - Added eachFile transformation to muzzle-check.gradle.kts - Added test SPI file to demonstrate functionality Resolves issue open-telemetry#14825
1 parent ad6cc1b commit 63cf3ef

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,11 @@ tasks.withType<ShadowJar>().configureEach {
5252

5353
// this is for instrumentation on java.util.logging (since java.util.logging itself is shaded above)
5454
relocate("application.java.util.logging", "java.util.logging")
55+
56+
// Rename SPI service files to match relocated class names
57+
eachFile {
58+
if (path.startsWith("META-INF/services/io.opentelemetry.instrumentation")) {
59+
path = path.replace("io.opentelemetry.instrumentation", "io.opentelemetry.javaagent.shaded.instrumentation")
60+
}
61+
}
5562
}

gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ tasks.withType<ShadowJar>().configureEach {
119119

120120
// this is for instrumentation on java.util.logging (since java.util.logging itself is shaded above)
121121
relocate("application.java.util.logging", "java.util.logging")
122+
123+
// Rename SPI service files to match relocated class names
124+
eachFile {
125+
if (path.startsWith("META-INF/services/io.opentelemetry.instrumentation")) {
126+
path = path.replace("io.opentelemetry.instrumentation", "io.opentelemetry.javaagent.shaded.instrumentation")
127+
}
128+
}
122129
}
123130

124131
val compileMuzzle by tasks.registering {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.opentelemetry.javaagent.tooling.instrumentation.http.RegexUrlTemplateCustomizer

0 commit comments

Comments
 (0)