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

Semconv code generation prototype #40

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 72 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ val snapshot = true

// The release version of https://github.com/open-telemetry/semantic-conventions used to generate classes
var semanticConventionsVersion = "1.23.1"
val semanticConventionsVersionEscaped = "v" + semanticConventionsVersion.replace(".", "_")

// Compute the artifact version, which includes the "-alpha" suffix and includes "-SNAPSHOT" suffix if not releasing
// Release example: version=1.21.0-alpha
Expand Down Expand Up @@ -71,7 +72,7 @@ dependencies {
}

// start - define tasks to download, unzip, and generate from opentelemetry/semantic-conventions
var generatorVersion = "0.23.0"
var generatorVersion = "foo14"
val semanticConventionsRepoZip = "https://github.com/open-telemetry/semantic-conventions/archive/v$semanticConventionsVersion.zip"
val schemaUrl = "https://opentelemetry.io/schemas/$semanticConventionsVersion"

Expand All @@ -93,7 +94,7 @@ val unzipConfigurationSchema by tasks.registering(Copy::class) {
into("$buildDir/semantic-conventions/")
}

val generateSemanticAttributes by tasks.registering(Exec::class) {
val generateStableSemanticAttributes by tasks.registering(Exec::class) {
dependsOn(unzipConfigurationSchema)

standardOutput = System.out
Expand All @@ -104,17 +105,16 @@ val generateSemanticAttributes by tasks.registering(Exec::class) {
"-v", "$buildDir/semantic-conventions/model:/source",
"-v", "$projectDir/buildscripts/templates:/templates",
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/:/output",
"otel/semconvgen:$generatorVersion",
"--only", "span,event,attribute_group,scope,metric",
"semconvgen:$generatorVersion",
"--yaml-root", "/source", "code",
"--template", "/templates/SemanticAttributes.java.j2",
"--output", "/output/SemanticAttributes.java",
"-Dclass=SemanticAttributes",
"-DschemaUrl=$schemaUrl",
"--output", "/output/Attributes.java",
"--file-per-group", "root_namespace",
"-Dfilter=is_stable",
"-Dpkg=io.opentelemetry.semconv"))
}

val generateResourceAttributes by tasks.registering(Exec::class) {
val generateStableSemanticMetrics by tasks.registering(Exec::class) {
dependsOn(unzipConfigurationSchema)

standardOutput = System.out
Expand All @@ -125,18 +125,74 @@ val generateResourceAttributes by tasks.registering(Exec::class) {
"-v", "$buildDir/semantic-conventions/model:/source",
"-v", "$projectDir/buildscripts/templates:/templates",
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/:/output",
"otel/semconvgen:$generatorVersion",
"--only", "resource",
"semconvgen:$generatorVersion",
"--yaml-root", "/source", "code",
"--template", "/templates/SemanticAttributes.java.j2",
"--output", "/output/ResourceAttributes.java",
"-Dclass=ResourceAttributes",
"-DschemaUrl=$schemaUrl",
"--template", "/templates/SemanticMetrics.java.j2",
"--output", "/output/Metrics.java",
"--file-per-group", "root_namespace",
"-Dfilter=is_stable",
"-Dpkg=io.opentelemetry.semconv"))
}

val generateExperimentalSemanticAttributes by tasks.registering(Exec::class) {
dependsOn(unzipConfigurationSchema)

standardOutput = System.out
executable = "docker"
setArgs(listOf(
"run",
"--rm",
"-v", "$buildDir/semantic-conventions/model:/source",
"-v", "$projectDir/buildscripts/templates:/templates",
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/$semanticConventionsVersionEscaped/:/output",
"semconvgen:$generatorVersion",
"--yaml-root", "/source", "code",
"--template", "/templates/SemanticAttributes.java.j2",
"--output", "/output/Attributes.java",
lmolkova marked this conversation as resolved.
Show resolved Hide resolved
"--file-per-group", "root_namespace",
"-Dfilter=is_experimental",
"-Dpkg=io.opentelemetry.semconv.$semanticConventionsVersionEscaped"))
}

val generateExperimentalSemanticMetrics by tasks.registering(Exec::class) {
dependsOn(unzipConfigurationSchema)

standardOutput = System.out
executable = "docker"
setArgs(listOf(
"run",
"--rm",
"-v", "$buildDir/semantic-conventions/model:/source",
"-v", "$projectDir/buildscripts/templates:/templates",
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/$semanticConventionsVersionEscaped/:/output",
"semconvgen:$generatorVersion",
"--yaml-root", "/source", "code",
"--template", "/templates/SemanticMetrics.java.j2",
"--output", "/output/Metrics.java",
"--file-per-group", "root_namespace",
"-Dfilter=is_experimental",
"-Dpkg=io.opentelemetry.semconv.$semanticConventionsVersionEscaped"))
}

// check if SchemaURLs file contains the new schema URL
val checkSchemaUrls by tasks.registering {
val schemaUrlsFile = File("$projectDir/src/main/java/io/opentelemetry/semconv/SchemaUrls.java")
if (!schemaUrlsFile.exists()) {
throw GradleException("SchemaUrls file does not exist")
}

val schemaUrls = schemaUrlsFile.readLines()
if (!schemaUrls.any { it.contains(schemaUrl) }) {
throw GradleException("SchemaUrls file does not contain $schemaUrl")
}
}

val generateSemanticConventions by tasks.registering {
dependsOn(generateSemanticAttributes)
dependsOn(generateResourceAttributes)
dependsOn(generateStableSemanticAttributes)
dependsOn(generateExperimentalSemanticAttributes)
// dependsOn(generateStableSemanticMetrics)
dependsOn(generateExperimentalSemanticMetrics)
dependsOn(checkSchemaUrls)
}

// end
4 changes: 3 additions & 1 deletion buildscripts/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<suppressions>
<!-- Suppress Javadoc-related checks in non-public code. -->
<suppress checks="JavadocParagraph|JavadocMethod" files="[\\/](jmh|test)[\\/]" />
<suppress checks="SummaryJavadoc" files="SemanticAttributes|ResourceAttributes"/>
<suppress checks="SummaryJavadoc" files=".*Attributes"/>
<suppress checks="SummaryJavadoc" files=".*Metrics"/>
<suppress checks="RedundantImport" files="[\\/]build[\\/]"/>
<suppress checks="PackageName" files=".*Attributes"/>
</suppressions>
Loading
Loading