Skip to content

Commit

Permalink
Add muzzle check to project and GH actions (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz authored Feb 4, 2025
1 parent b06075c commit 21912b6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 19 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,14 @@ jobs:
with:
name: test-results-${{ matrix.version }}-${{ matrix.vm }}
path: '**/build/test-results/test/TEST-*.xml'

muzzle-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run muzzle check
uses: ./.github/workflows/gradle-goal
with:
# We also compile the test-classes, even though we are skipping the tests
command: "./gradlew :instrumentation:muzzle"
7 changes: 0 additions & 7 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ repositories {
dependencies {
implementation(catalog.spotlessPlugin)
implementation(catalog.licenseReportPlugin)
// muzzle pulls in ancient versions of http components which conflict with other plugins, such as jib
implementation(catalog.muzzleGenerationPlugin) {
exclude(group = "org.apache.httpcomponents" )
}
implementation(catalog.muzzleCheckPlugin) {
exclude(group = "org.apache.httpcomponents" )
}
implementation(catalog.shadowPlugin)
// The ant dependency is required to add custom transformers for the shadow plugin
// but it is unfortunately not exposed as transitive dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

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

// Other instrumentations to include for testing
Expand Down
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ opentelemetryContribAlpha = "1.42.0-alpha"
# reference the "incubating" version explicitly
opentelemetrySemconvAlpha = "1.29.0-alpha"

# instrumented libraries
openaiClient = "0.13.0"

[libraries]

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

opentelemetrySemconv = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv", version.ref = "opentelemetrySemconvAlpha"}
opentelemetrySemconvIncubating = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv-incubating", version.ref = "opentelemetrySemconvAlpha"}
opentelemetrySemconv = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv", version.ref = "opentelemetrySemconvAlpha" }
opentelemetrySemconvIncubating = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv-incubating", version.ref = "opentelemetrySemconvAlpha" }

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

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

[bundles]

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

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

14 changes: 14 additions & 0 deletions instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

// Umbrella task for executing muzzle of all subprojects
// Note that invoking just "/.gradlew muzzle" reports that muzzle was executed,
// but it actually doesn't work, the plugin simply does nothing
// The same applies to executing the gradle task from the working directory of a subproject, like doing it via IntelliJ does
// You must really run exactly "./gradlew clean :instrumentation:muzzle" from the command line to have muzzle actually execute
val instrumentationProjectMuzzle = task("muzzle")

subprojects {
val subProj = this
plugins.withId("io.opentelemetry.instrumentation.muzzle-check") {
instrumentationProjectMuzzle.dependsOn(subProj.tasks.named("muzzle"))
}
}
13 changes: 10 additions & 3 deletions instrumentation/openai-client-instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
plugins {
alias(catalog.plugins.muzzleGeneration)
alias(catalog.plugins.muzzleCheck)
id("elastic-otel.instrumentation-conventions")
}

Expand All @@ -13,7 +15,12 @@ dependencies {
}

muzzle {
// TODO: setup muzzle to check older versions of openAI client
// See the docs on how to do it:
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/muzzle.md
pass {
val openaiClientLib = catalog.openaiClient.get()
group.set(openaiClientLib.group)
module.set(openaiClientLib.name)
versions.set("(,${openaiClientLib.version}]")
// no assertInverse.set(true) here because we don't want muzzle to fail for newer releases on our main branch
// instead, renovate will bump the version and failures will be automatically detected on that bump PR
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include("agent:entrypoint")
include("agentextension")
include("bootstrap")
include("custom")
include("instrumentation")
include("instrumentation:openai-client-instrumentation")
include("inferred-spans")
include("resources")
Expand Down

0 comments on commit 21912b6

Please sign in to comment.