Skip to content

Commit 0038c8e

Browse files
authored
Fix instrumentation publications (#926)
* Reorganizing instrumentation subprojects * Updating README * Updating instrumentation subproject artifact ids * Updating instrumentation artifact names without subprojects * Updating comments * Updating readmes * Updating CONTRIBUTING.md * Updating comments * Renaming okhttp to okhttp3
1 parent b650750 commit 0038c8e

37 files changed

Lines changed: 60 additions & 46 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ instrumentation/
8484
```
8585

8686
You can take a look at how it's done for the OkHttp
87-
instrumentation [here](./instrumentation/okhttp/okhttp-3.0) for reference.
87+
instrumentation [here](instrumentation/okhttp3) for reference.

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ if (android != null) {
3535
afterEvaluate {
3636
publishing.publications {
3737
val maven = create<MavenPublication>("maven") {
38-
artifactId = computeArtifactId()
38+
val path = project.path
39+
artifactId = computeArtifactId(path)
40+
groupId = computeGroupId(path)
3941
if (android != null) {
4042
from(components.findByName(androidVariantToRelease))
4143
} else {
@@ -83,21 +85,38 @@ afterEvaluate {
8385
}
8486
}
8587

86-
fun computeArtifactId(): String {
87-
val path = project.path
88-
if (!path.contains("instrumentation")) {
88+
fun computeArtifactId(path: String): String {
89+
val projectName = project.name
90+
if (!path.startsWith(":instrumentation:")) {
8991
// Return default artifactId for non auto-instrumentation publications.
90-
return project.name
92+
return projectName
9193
}
9294

93-
// Adding library name to its related auto-instrumentation subprojects.
94-
// For example, prepending "okhttp-3.0-" to both the "library" and "agent" subprojects inside the "okhttp-3.0" folder.
95-
val match = Regex("[^:]+:[^:]+\$").find(path)
96-
var artifactId = match!!.value.replace(":", "-")
97-
if (!artifactId.startsWith("instrumentation-")) {
98-
artifactId = "instrumentation-$artifactId"
95+
val match = Regex("^:instrumentation:([^:]+)(:[^:]+)?\$").matchEntire(path)
96+
?: throw IllegalStateException("Invalid instrumentation path: '$path'")
97+
98+
if (match.groupValues[2].isEmpty()) {
99+
// This is not an instrumentation subproject.
100+
return projectName
99101
}
100102

103+
val instrumentationName = match.groupValues[1].replace(":", "")
104+
val instrumentationSubprojectName = match.groupValues[2].replace(":", "")
105+
106+
// Adding instrumentation name to its related subprojects.
107+
// For example, prepending "okhttp-" to both the "library" and "agent" subprojects inside the "okhttp" folder.
108+
val artifactId = "$instrumentationName-$instrumentationSubprojectName"
109+
101110
logger.debug("Using artifact id: '{}' for subproject: '{}'", artifactId, path)
102111
return artifactId
103112
}
113+
114+
fun computeGroupId(path: String): String {
115+
val groupId = project.group.toString()
116+
if (!path.startsWith(":instrumentation:")) {
117+
// Return default groupId for non instrumentation publications.
118+
return groupId
119+
}
120+
121+
return "$groupId.instrumentation"
122+
}

instrumentation/httpurlconnection/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ plugins {
5454
#### Project dependencies
5555

5656
```kotlin
57-
implementation("io.opentelemetry.android:httpurlconnection-library:AUTO_HTTP_URL_INSTRUMENTATION_VERSION")
58-
byteBuddy("io.opentelemetry.android:httpurlconnection-agent:AUTO_HTTP_URL_INSTRUMENTATION_VERSION")
57+
implementation("io.opentelemetry.android.instrumentation:httpurlconnection-library:AUTO_HTTP_URL_INSTRUMENTATION_VERSION")
58+
byteBuddy("io.opentelemetry.android.instrumentation:httpurlconnection-agent:AUTO_HTTP_URL_INSTRUMENTATION_VERSION")
5959
```
6060

6161
### Configurations

instrumentation/okhttp/websocket/okhttp-3.0/agent/build.gradle.kts renamed to instrumentation/okhttp3-websocket/agent/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
}
1111

1212
dependencies {
13-
implementation(project(":instrumentation:okhttp:websocket:okhttp-3.0:library"))
13+
implementation(project(":instrumentation:okhttp3-websocket:library"))
1414
compileOnly(libs.okhttp)
1515
implementation(libs.byteBuddy)
1616
}

instrumentation/okhttp/websocket/okhttp-3.0/agent/src/main/java/io/opentelemetry/instrumentation/agent/okhttp/v3_0/websocket/OkHttpClientWebsocketAdvice.java renamed to instrumentation/okhttp3-websocket/agent/src/main/java/io/opentelemetry/instrumentation/agent/okhttp/v3_0/websocket/OkHttpClientWebsocketAdvice.java

File renamed without changes.

instrumentation/okhttp/websocket/okhttp-3.0/agent/src/main/java/io/opentelemetry/instrumentation/agent/okhttp/v3_0/websocket/OkHttpClientWebsocketPlugin.java renamed to instrumentation/okhttp3-websocket/agent/src/main/java/io/opentelemetry/instrumentation/agent/okhttp/v3_0/websocket/OkHttpClientWebsocketPlugin.java

File renamed without changes.

instrumentation/okhttp/websocket/okhttp-3.0/agent/src/main/resources/META-INF/net.bytebuddy/build.plugins renamed to instrumentation/okhttp3-websocket/agent/src/main/resources/META-INF/net.bytebuddy/build.plugins

File renamed without changes.

instrumentation/okhttp/websocket/okhttp-3.0/library/build.gradle.kts renamed to instrumentation/okhttp3-websocket/library/build.gradle.kts

File renamed without changes.

instrumentation/okhttp/okhttp-3.0/library/consumer-rules.pro renamed to instrumentation/okhttp3-websocket/library/consumer-rules.pro

File renamed without changes.

instrumentation/okhttp/websocket/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/library/okhttp/v3_0/websocket/internal/OkHttpWebsocketInstrumentation.java renamed to instrumentation/okhttp3-websocket/library/src/main/java/io/opentelemetry/instrumentation/library/okhttp/v3_0/websocket/internal/OkHttpWebsocketInstrumentation.java

File renamed without changes.

0 commit comments

Comments
 (0)