Skip to content

Commit 21912b6

Browse files
authored
Add muzzle check to project and GH actions (#529)
1 parent b06075c commit 21912b6

File tree

7 files changed

+49
-19
lines changed

7 files changed

+49
-19
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,14 @@ jobs:
107107
with:
108108
name: test-results-${{ matrix.version }}-${{ matrix.vm }}
109109
path: '**/build/test-results/test/TEST-*.xml'
110+
111+
muzzle-check:
112+
runs-on: ubuntu-latest
113+
steps:
114+
- name: Checkout
115+
uses: actions/checkout@v4
116+
- name: Run muzzle check
117+
uses: ./.github/workflows/gradle-goal
118+
with:
119+
# We also compile the test-classes, even though we are skipping the tests
120+
command: "./gradlew :instrumentation:muzzle"

buildSrc/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ repositories {
1616
dependencies {
1717
implementation(catalog.spotlessPlugin)
1818
implementation(catalog.licenseReportPlugin)
19-
// muzzle pulls in ancient versions of http components which conflict with other plugins, such as jib
20-
implementation(catalog.muzzleGenerationPlugin) {
21-
exclude(group = "org.apache.httpcomponents" )
22-
}
23-
implementation(catalog.muzzleCheckPlugin) {
24-
exclude(group = "org.apache.httpcomponents" )
25-
}
2619
implementation(catalog.shadowPlugin)
2720
// The ant dependency is required to add custom transformers for the shadow plugin
2821
// but it is unfortunately not exposed as transitive dependency

buildSrc/src/main/kotlin/elastic-otel.instrumentation-conventions.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22

33
plugins {
44
`java-library`
5+
id("com.gradleup.shadow")
56
id("elastic-otel.java-conventions")
6-
id("io.opentelemetry.instrumentation.muzzle-generation")
7-
id("io.opentelemetry.instrumentation.muzzle-check")
7+
// NOTE: We can't declare a dependency on the muzzle-check and muzzle-generation here
8+
// Unfortunately those pull in ancient version of apache-httpclient if used as dependency in buildSrc/build.gradle
9+
// That ancient version would then be used in the buildEnvironment of ALL other modules, including the smoke tests
10+
// If there is any other plugin using apache httpclient (like jib) it will fail due to the ancient http client version
11+
// we workaround this problem by making instrumentation modules pull in the dependency instead of doing it globally here
812
}
913

1014
// Other instrumentations to include for testing

gradle/libs.versions.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ opentelemetryContribAlpha = "1.42.0-alpha"
2222
# reference the "incubating" version explicitly
2323
opentelemetrySemconvAlpha = "1.29.0-alpha"
2424

25-
# instrumented libraries
26-
openaiClient = "0.13.0"
27-
2825
[libraries]
2926

3027
# transitively provides 'opentelemetry-instrumentation-bom' (non-alpha)
@@ -38,8 +35,8 @@ contribResources = { group = "io.opentelemetry.contrib", name = "opentelemetry-r
3835
contribSpanStacktrace = { group = "io.opentelemetry.contrib", name = "opentelemetry-span-stacktrace", version.ref = "opentelemetryContribAlpha" }
3936
contribInferredSpans = { group = "io.opentelemetry.contrib", name = "opentelemetry-inferred-spans", version.ref = "opentelemetryContribAlpha" }
4037

41-
opentelemetrySemconv = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv", version.ref = "opentelemetrySemconvAlpha"}
42-
opentelemetrySemconvIncubating = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv-incubating", version.ref = "opentelemetrySemconvAlpha"}
38+
opentelemetrySemconv = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv", version.ref = "opentelemetrySemconvAlpha" }
39+
opentelemetrySemconvIncubating = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv-incubating", version.ref = "opentelemetrySemconvAlpha" }
4340

4441
autoservice-processor = { group = "com.google.auto.service", name = "auto-service", version.ref = "autoservice" }
4542
autoservice-annotations = { group = "com.google.auto.service", name = "auto-service-annotations", version.ref = "autoservice" }
@@ -80,7 +77,7 @@ ant = "org.apache.ant:ant:1.10.15"
8077
asm = "org.ow2.asm:asm:9.7"
8178

8279
# Instrumented libraries
83-
openaiClient = {group = "com.openai", name = "openai-java", version.ref ="openaiClient"}
80+
openaiClient = "com.openai:openai-java:0.13.0"
8481

8582
[bundles]
8683

@@ -90,6 +87,9 @@ semconv = ["opentelemetrySemconv", "opentelemetrySemconvIncubating"]
9087

9188
jib = { id = "com.google.cloud.tools.jib", version.ref = "jib" }
9289
taskinfo = { id = "org.barfuin.gradle.taskinfo", version = '2.2.0' }
93-
jmh = {id = "me.champeau.jmh", version = "0.7.3"}
90+
jmh = { id = "me.champeau.jmh", version = "0.7.3" }
9491
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = '2.0.0' }
9592
dockerJavaApplication = { id = "com.bmuschko.docker-java-application", version = "9.4.0" }
93+
muzzleCheck = { id = "io.opentelemetry.instrumentation.muzzle-check", version.ref = "opentelemetryJavaagentAlpha" }
94+
muzzleGeneration = { id = "io.opentelemetry.instrumentation.muzzle-generation", version.ref = "opentelemetryJavaagentAlpha" }
95+

instrumentation/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
// Umbrella task for executing muzzle of all subprojects
3+
// Note that invoking just "/.gradlew muzzle" reports that muzzle was executed,
4+
// but it actually doesn't work, the plugin simply does nothing
5+
// The same applies to executing the gradle task from the working directory of a subproject, like doing it via IntelliJ does
6+
// You must really run exactly "./gradlew clean :instrumentation:muzzle" from the command line to have muzzle actually execute
7+
val instrumentationProjectMuzzle = task("muzzle")
8+
9+
subprojects {
10+
val subProj = this
11+
plugins.withId("io.opentelemetry.instrumentation.muzzle-check") {
12+
instrumentationProjectMuzzle.dependsOn(subProj.tasks.named("muzzle"))
13+
}
14+
}

instrumentation/openai-client-instrumentation/build.gradle.kts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
plugins {
2+
alias(catalog.plugins.muzzleGeneration)
3+
alias(catalog.plugins.muzzleCheck)
24
id("elastic-otel.instrumentation-conventions")
35
}
46

@@ -13,7 +15,12 @@ dependencies {
1315
}
1416

1517
muzzle {
16-
// TODO: setup muzzle to check older versions of openAI client
17-
// See the docs on how to do it:
18-
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/muzzle.md
18+
pass {
19+
val openaiClientLib = catalog.openaiClient.get()
20+
group.set(openaiClientLib.group)
21+
module.set(openaiClientLib.name)
22+
versions.set("(,${openaiClientLib.version}]")
23+
// no assertInverse.set(true) here because we don't want muzzle to fail for newer releases on our main branch
24+
// instead, renovate will bump the version and failures will be automatically detected on that bump PR
25+
}
1926
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ include("agent:entrypoint")
1616
include("agentextension")
1717
include("bootstrap")
1818
include("custom")
19+
include("instrumentation")
1920
include("instrumentation:openai-client-instrumentation")
2021
include("inferred-spans")
2122
include("resources")

0 commit comments

Comments
 (0)