Skip to content

Commit 4d73e33

Browse files
committed
use SDK json
1 parent eca730f commit 4d73e33

File tree

2 files changed

+6
-590
lines changed
  • instrumentation/spring/spring-boot-autoconfigure

2 files changed

+6
-590
lines changed

instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ plugins {
66
base.archivesName.set("opentelemetry-spring-boot-autoconfigure")
77
group = "io.opentelemetry.instrumentation"
88

9-
val springBootVersion =
10-
"2.7.18" // AutoConfiguration is added in 2.7.0, but can be used with older versions
9+
val springBootVersion = "2.7.18" // AutoConfiguration is added in 2.7.0, but can be used with older versions
1110

1211
// r2dbc-proxy is shadowed to prevent org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration
1312
// from being loaded by Spring Boot (by the presence of META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider) - even if the user doesn't want to use R2DBC.
@@ -50,12 +49,7 @@ dependencies {
5049
implementation(project(":instrumentation-annotations-support"))
5150
implementation(project(":instrumentation:kafka:kafka-clients:kafka-clients-2.6:library"))
5251
implementation(project(":instrumentation:mongo:mongo-3.1:library"))
53-
compileOnly(
54-
project(
55-
path = ":instrumentation:r2dbc-1.0:library-instrumentation-shaded",
56-
configuration = "shadow"
57-
)
58-
)
52+
compileOnly(project(path = ":instrumentation:r2dbc-1.0:library-instrumentation-shaded", configuration = "shadow"))
5953
implementation(project(":instrumentation:spring:spring-kafka-2.7:library"))
6054
implementation(project(":instrumentation:spring:spring-web:spring-web-3.1:library"))
6155
implementation(project(":instrumentation:spring:spring-webmvc:spring-webmvc-5.3:library"))
@@ -124,14 +118,8 @@ dependencies {
124118
add("javaSpring3CompileOnly", files(sourceSets.main.get().output.classesDirs))
125119
add("javaSpring3CompileOnly", "org.springframework.boot:spring-boot-starter-web:3.2.4")
126120
add("javaSpring3CompileOnly", "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
127-
add(
128-
"javaSpring3CompileOnly",
129-
project(":instrumentation:spring:spring-web:spring-web-3.1:library")
130-
)
131-
add(
132-
"javaSpring3CompileOnly",
133-
project(":instrumentation:spring:spring-webmvc:spring-webmvc-6.0:library")
134-
)
121+
add("javaSpring3CompileOnly", project(":instrumentation:spring:spring-web:spring-web-3.1:library"))
122+
add("javaSpring3CompileOnly", project(":instrumentation:spring:spring-webmvc:spring-webmvc-6.0:library"))
135123

136124
// Spring Boot 4
137125
add("javaSpring4CompileOnly", files(sourceSets.main.get().output.classesDirs))
@@ -157,10 +145,8 @@ if (latestDepTest) {
157145
}
158146
}
159147

160-
val testJavaVersion =
161-
gradle.startParameter.projectProperties["testJavaVersion"]?.let(JavaVersion::toVersion)
162-
val testSpring3 =
163-
(testJavaVersion == null || testJavaVersion.compareTo(JavaVersion.VERSION_17) >= 0)
148+
val testJavaVersion = gradle.startParameter.projectProperties["testJavaVersion"]?.let(JavaVersion::toVersion)
149+
val testSpring3 = (testJavaVersion == null || testJavaVersion.compareTo(JavaVersion.VERSION_17) >= 0)
164150

165151
testing {
166152
suites {
@@ -280,65 +266,7 @@ configurations.configureEach {
280266
}
281267
}
282268

283-
val buildGraalVmReflectionJson = tasks.register("buildGraalVmReflectionJson") {
284-
val targetFile = File(
285-
projectDir,
286-
"src/main/resources/META-INF/native-image/io.opentelemetry.instrumentation/opentelemetry-spring-boot/reflect-config.json"
287-
)
288-
289-
onlyIf { !targetFile.exists() }
290-
291-
doLast {
292-
val sourcePackage =
293-
"io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model"
294-
val sourcePackagePath = sourcePackage.replace(".", "/")
295-
296-
val incubatorJar = configurations.compileClasspath.get()
297-
.filter { it.name.contains("opentelemetry-sdk-extension-incubator") && it.name.endsWith(".jar") }
298-
.singleFile
299-
300-
val classes = mutableListOf<String>()
301-
zipTree(incubatorJar).matching {
302-
include("$sourcePackagePath/**")
303-
}.forEach {
304-
val path = it.path
305-
306-
val className = path
307-
.substringAfter(sourcePackagePath)
308-
.removePrefix("/")
309-
.removeSuffix(".class")
310-
.replace("/", ".")
311-
classes.add("$sourcePackage.$className")
312-
}
313-
314-
// write into targetFile in json format
315-
// todo either write to generated sources or add to SDK extension incubator build process
316-
targetFile.parentFile.mkdirs()
317-
targetFile.bufferedWriter().use { writer ->
318-
writer.write("[\n")
319-
classes.forEachIndexed { index, className ->
320-
writer.write(" {\n")
321-
writer.write(" \"name\": \"$className\",\n")
322-
writer.write(" \"allDeclaredMethods\": true,\n")
323-
writer.write(" \"allDeclaredFields\": true,\n")
324-
writer.write(" \"allDeclaredConstructors\": true\n")
325-
writer.write(" }")
326-
if (index < classes.size - 1) {
327-
writer.write(",\n")
328-
} else {
329-
writer.write("\n")
330-
}
331-
}
332-
writer.write("]\n")
333-
}
334-
}
335-
}
336-
337269
tasks {
338-
compileJava {
339-
dependsOn(buildGraalVmReflectionJson)
340-
}
341-
342270
compileTestJava {
343271
options.compilerArgs.add("-parameters")
344272
}

0 commit comments

Comments
 (0)