Skip to content

Commit 0141bda

Browse files
authored
Split out incubating artifact (#41)
* Add dependencyManagement * Breaking out incubating artifact * Add check for schema urls * Fix automatic module name * Update readme * Revert to using 0.23.0 of generator * Fix check for diff check * PR feedback * Add availability test for incubating classes
1 parent 2be178a commit 0141bda

File tree

19 files changed

+675
-2374
lines changed

19 files changed

+675
-2374
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ jobs:
7171
- name: Check for diff
7272
run: |
7373
# need to "git add" in case any generated files did not already exist
74-
git add src
74+
# select files from both /semconv and /semconv-incubating
75+
git add semconv**
7576
if git diff --cached --quiet
7677
then
7778
echo "No diff detected."

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ Published releases are available on maven central. Replace `{{version}}` with th
1515
```xml
1616
<project>
1717
<dependencies>
18+
<!-- Stable semantic conventions. Note: generated code is still subject to breaking changes while published with "-alpha" suffix. -->
1819
<dependency>
1920
<groupId>io.opentelemetry.semconv</groupId>
2021
<artifactId>opentelemetry-semconv</artifactId>
2122
<version>{{version}}</version>
2223
</dependency>
24+
<!-- Incubating semantic conventions. Breaking changes expected. Library instrumentation SHOULD NOT depend on this. -->
25+
<dependency>
26+
<groupId>io.opentelemetry.semconv</groupId>
27+
<artifactId>opentelemetry-semconv-incubating</artifactId>
28+
<version>{{version}}</version>
29+
</dependency>
2330
</dependencies>
2431
</project>
2532
```
@@ -28,7 +35,10 @@ Published releases are available on maven central. Replace `{{version}}` with th
2835

2936
```groovy
3037
dependencies {
38+
// Stable semantic conventions. Note: generated code is still subject to breaking changes while published with "-alpha" suffix.
3139
implementation "io.opentelemetry.semconv:opentelemetry-semconv:{{version}}"
40+
// Incubating semantic conventions. Breaking changes expected. Library instrumentation SHOULD NOT depend on this.
41+
implementation "io.opentelemetry.semconv:opentelemetry-semconv-incubating:{{version}}"
3242
}
3343
```
3444

@@ -37,7 +47,7 @@ dependencies {
3747
Java 17 or higher is required to build the projects in this repository. The built artifacts can be
3848
used on Java 8 or higher.
3949

40-
To use this artifact you must also depend on `io.opentelemetry:opentelemetry-api:{{version}}`.
50+
To use these artifacts, you must also depend on `io.opentelemetry:opentelemetry-api:{{version}}`.
4151
See [opentelemetry-java releases](https://github.com/open-telemetry/opentelemetry-java#releases) for
4252
more information.
4353

@@ -57,6 +67,8 @@ of [open-telemetry/semantic-conventions](https://github.com/open-telemetry/seman
5767
defined in the `semanticConventionsVersion` variable of [build.gradle.kts](./build.gradle.kts) and
5868
generate semantic conventions classes from the release contents.
5969

70+
TODO: Update the following paragraph with new strategy for managing compatibility
71+
6072
This repository publishes `-alpha` artifacts and as discussed
6173
in [opentelemetry-java/VERSIONING.md](https://github.com/open-telemetry/opentelemetry-java/blob/main/VERSIONING.md),
6274
we make no compatibility guarantees. However, by convention we've been keeping attribute constants

build.gradle.kts

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ import de.undercouch.gradle.tasks.download.Download
22
import java.time.Duration
33

44
plugins {
5-
id("otel.java-conventions")
6-
id("otel.publish-conventions")
7-
id("otel.japicmp-conventions")
8-
9-
id("otel.animalsniffer-conventions")
10-
115
id("de.undercouch.download")
126
id("io.github.gradle-nexus.publish-plugin")
137
}
@@ -18,6 +12,7 @@ val snapshot = true
1812

1913
// The release version of https://github.com/open-telemetry/semantic-conventions used to generate classes
2014
var semanticConventionsVersion = "1.23.1"
15+
val schemaUrlVersions = listOf(semanticConventionsVersion, "1.22.0")
2116

2217
// Compute the artifact version, which includes the "-alpha" suffix and includes "-SNAPSHOT" suffix if not releasing
2318
// Release example: version=1.21.0-alpha
@@ -27,10 +22,8 @@ if (snapshot) {
2722
releaseVersion += "-SNAPSHOT"
2823
}
2924

30-
base {
25+
allprojects {
3126
version = releaseVersion
32-
description = "OpenTelemetry Semantic Conventions generated classes for Java"
33-
archivesName.set("opentelemetry-semconv")
3427
}
3528

3629
nexusPublishing {
@@ -54,22 +47,6 @@ nexusPublishing {
5447
}
5548
}
5649

57-
val opentelemetryJavaVersion = "1.31.0"
58-
59-
dependencies {
60-
compileOnly("io.opentelemetry:opentelemetry-api:$opentelemetryJavaVersion")
61-
62-
testImplementation("io.opentelemetry:opentelemetry-api:$opentelemetryJavaVersion")
63-
64-
testImplementation(platform("org.junit:junit-bom:5.10.0"))
65-
testImplementation("org.junit.jupiter:junit-jupiter-api")
66-
testImplementation("org.junit.jupiter:junit-jupiter-params")
67-
testImplementation("org.junit.jupiter:junit-jupiter-engine")
68-
69-
testImplementation(platform("org.assertj:assertj-bom:3.24.2"))
70-
testImplementation("org.assertj:assertj-core")
71-
}
72-
7350
// start - define tasks to download, unzip, and generate from opentelemetry/semantic-conventions
7451
var generatorVersion = "0.23.0"
7552
val semanticConventionsRepoZip = "https://github.com/open-telemetry/semantic-conventions/archive/v$semanticConventionsVersion.zip"
@@ -93,50 +70,66 @@ val unzipConfigurationSchema by tasks.registering(Copy::class) {
9370
into("$buildDir/semantic-conventions/")
9471
}
9572

96-
val generateSemanticAttributes by tasks.registering(Exec::class) {
97-
dependsOn(unzipConfigurationSchema)
98-
99-
standardOutput = System.out
100-
executable = "docker"
101-
setArgs(listOf(
102-
"run",
103-
"--rm",
104-
"-v", "$buildDir/semantic-conventions/model:/source",
105-
"-v", "$projectDir/buildscripts/templates:/templates",
106-
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/:/output",
107-
"otel/semconvgen:$generatorVersion",
108-
"--only", "span,event,attribute_group,scope,metric",
109-
"--yaml-root", "/source", "code",
110-
"--template", "/templates/SemanticAttributes.java.j2",
111-
"--output", "/output/SemanticAttributes.java",
112-
"-Dclass=SemanticAttributes",
113-
"-DschemaUrl=$schemaUrl",
114-
"-Dpkg=io.opentelemetry.semconv"))
73+
fun generateTask(taskName: String, resource: Boolean, incubating: Boolean) {
74+
tasks.register(taskName, Exec::class) {
75+
dependsOn(unzipConfigurationSchema)
76+
77+
standardOutput = System.out
78+
executable = "docker"
79+
80+
val onlyArg = if (resource) "resource" else "span,event,attribute_group,scope,metric"
81+
val classNamePrefix = if (incubating) "Incubating" else ""
82+
var className = if (resource) "${classNamePrefix}ResourceAttributes" else "${classNamePrefix}SemanticAttributes"
83+
val outputDir = if (incubating) "semconv-incubating/src/main/java/io/opentelemetry/semconv/incubating/" else "semconv/src/main/java/io/opentelemetry/semconv/"
84+
val stability = if (incubating) "StabilityLevel.EXPERIMENTAL" else "StabilityLevel.STABLE"
85+
val packageNameArg = if (incubating) "io.opentelemetry.semconv.incubating" else "io.opentelemetry.semconv"
86+
87+
setArgs(listOf(
88+
"run",
89+
"--rm",
90+
"-v", "$buildDir/semantic-conventions/model:/source",
91+
"-v", "$projectDir/buildscripts/templates:/templates",
92+
"-v", "$projectDir/$outputDir:/output",
93+
"otel/semconvgen:$generatorVersion",
94+
"--only", onlyArg,
95+
"--yaml-root", "/source", "code",
96+
"--template", "/templates/SemanticAttributes.java.j2",
97+
"--output", "/output/$className.java",
98+
"-Dclass=$className",
99+
"-Dstability=${stability}",
100+
"-Dpkg=$packageNameArg"))
101+
}
115102
}
116103

117-
val generateResourceAttributes by tasks.registering(Exec::class) {
118-
dependsOn(unzipConfigurationSchema)
119-
120-
standardOutput = System.out
121-
executable = "docker"
122-
setArgs(listOf(
123-
"run",
124-
"--rm",
125-
"-v", "$buildDir/semantic-conventions/model:/source",
126-
"-v", "$projectDir/buildscripts/templates:/templates",
127-
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/:/output",
128-
"otel/semconvgen:$generatorVersion",
129-
"--only", "resource",
130-
"--yaml-root", "/source", "code",
131-
"--template", "/templates/SemanticAttributes.java.j2",
132-
"--output", "/output/ResourceAttributes.java",
133-
"-Dclass=ResourceAttributes",
134-
"-DschemaUrl=$schemaUrl",
135-
"-Dpkg=io.opentelemetry.semconv"))
104+
generateTask("generateStableSemanticAttributes", false, false)
105+
generateTask("generateIncubatingSemanticAttributes", false, true)
106+
generateTask("generateStableResourceAttributes", true, false)
107+
generateTask("generateIncubatingResourceAttributes", true, true)
108+
109+
tasks.register("checkSchemaUrls") {
110+
val schemaUrlsClass = File("$projectDir/semconv/src/main/java/io/opentelemetry/semconv/SchemaUrls.java")
111+
if (!schemaUrlsClass.exists()) {
112+
throw GradleException("SchemaUrls file does not exist")
113+
}
114+
115+
for (schemaUrlVersion: String in schemaUrlVersions) {
116+
val expectedLine = "public static final String V" + schemaUrlVersion.replace(".", "_") + " = \"https://opentelemetry.io/schemas/" + schemaUrlVersion + "\";"
117+
if (!schemaUrlsClass.readLines().any { it.contains(expectedLine) }) {
118+
throw GradleException("SchemaUrls file does not contain: $expectedLine")
119+
}
120+
}
136121
}
137122

138123
val generateSemanticConventions by tasks.registering {
139-
dependsOn(generateSemanticAttributes)
140-
dependsOn(generateResourceAttributes)
124+
dependsOn(tasks.getByName("generateStableSemanticAttributes"))
125+
dependsOn(tasks.getByName("generateIncubatingSemanticAttributes"))
126+
dependsOn(tasks.getByName("generateStableResourceAttributes"))
127+
dependsOn(tasks.getByName("generateIncubatingResourceAttributes"))
128+
dependsOn(tasks.getByName("checkSchemaUrls"))
129+
}
130+
131+
tasks.register("build") {
132+
dependsOn(tasks.getByName("checkSchemaUrls"))
141133
}
134+
142135
// end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.gradle
7+
8+
import org.gradle.api.provider.Property
9+
10+
abstract class OtelJavaExtension {
11+
abstract val moduleName: Property<String>
12+
}

buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io.opentelemetry.gradle.OtelJavaExtension
12
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
23

34
plugins {
@@ -10,6 +11,8 @@ plugins {
1011
id("otel.spotless-conventions")
1112
}
1213

14+
val otelJava = extensions.create<OtelJavaExtension>("otelJava")
15+
1316
java {
1417
toolchain {
1518
languageVersion.set(JavaLanguageVersion.of(17))
@@ -81,9 +84,11 @@ tasks {
8184
}
8285

8386
withType<Jar>().configureEach {
87+
inputs.property("moduleName", otelJava.moduleName)
88+
8489
manifest {
8590
attributes(
86-
"Automatic-Module-Name" to "io.opentelemetry.semconv",
91+
"Automatic-Module-Name" to otelJava.moduleName,
8792
"Built-By" to System.getProperty("user.name"),
8893
"Built-JDK" to System.getProperty("java.version"),
8994
"Implementation-Title" to project.base.archivesName,
@@ -108,3 +113,34 @@ configurations.configureEach {
108113
preferProjectModules()
109114
}
110115
}
116+
117+
val dependencyManagement by configurations.creating {
118+
isCanBeConsumed = false
119+
isCanBeResolved = false
120+
isVisible = false
121+
}
122+
123+
dependencies {
124+
dependencyManagement(platform(project(":dependencyManagement")))
125+
afterEvaluate {
126+
configurations.configureEach {
127+
if (isCanBeResolved && !isCanBeConsumed) {
128+
extendsFrom(dependencyManagement)
129+
}
130+
}
131+
}
132+
}
133+
134+
testing {
135+
suites.withType(JvmTestSuite::class).configureEach {
136+
dependencies {
137+
implementation(project(project.path))
138+
139+
implementation("org.junit.jupiter:junit-jupiter-api")
140+
implementation("org.junit.jupiter:junit-jupiter-params")
141+
runtimeOnly("org.junit.jupiter:junit-jupiter-engine")
142+
143+
implementation("org.assertj:assertj-core")
144+
}
145+
}
146+
}

0 commit comments

Comments
 (0)