-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
169 lines (142 loc) · 6.41 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
plugins {
id "java"
/*
Instrumentation agent extension mechanism expects a single jar containing everything required
for your extension. This also includes any external libraries that your extension uses and
cannot access from application classpath (see comment below about `javax.servlet-api` dependency).
Thus we use Shadow Gradle plugin to package our classes and all required runtime dependencies
into a single jar.
See https://imperceptiblethoughts.com/shadow/ for more details about Shadow plugin.
*/
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.diffplug.spotless" version "6.3.0"
id "io.opentelemetry.instrumentation.muzzle-generation" version "1.17.0-alpha-SNAPSHOT"
id "io.opentelemetry.instrumentation.muzzle-check" version "1.17.0-alpha-SNAPSHOT"
}
group 'io.opentelemetry.example'
version '1.0'
ext {
versions = [
// these lines are managed by .github/scripts/update-sdk-version.sh
opentelemetry : "1.17.0",
opentelemetryAlpha : "1.17.0-alpha",
// these lines are managed by .github/scripts/update-version.sh
opentelemetryJavaagent : "1.17.0-SNAPSHOT",
opentelemetryJavaagentAlpha: "1.17.0-alpha-SNAPSHOT",
]
deps = [
autoservice: dependencies.create(group: 'com.google.auto.service', name: 'auto-service', version: '1.0.1')
]
}
repositories {
mavenCentral()
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
}
configurations {
/*
We create a separate gradle configuration to grab a published Otel instrumentation agent.
We don't need the agent during development of this extension module.
This agent is used only during integration test.
*/
otel
}
spotless {
java {
googleJavaFormat()
licenseHeaderFile(rootProject.file("../../buildscripts/spotless.license.java"), "(package|import|public)")
target("src/**/*.java")
}
}
dependencies {
/*
Interfaces and SPIs that we implement. We use `compileOnly` dependency because during
runtime all necessary classes are provided by javaagent itself.
*/
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:${versions.opentelemetry}")
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:${versions.opentelemetryJavaagentAlpha}")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
//Provides @AutoService annotation that makes registration of our SPI implementations much easier
compileOnly deps.autoservice
annotationProcessor deps.autoservice
/*
Used by our demo instrumentation module to reference classes of the target instrumented library.
We again use `compileOnly` here because during runtime these classes are provided by the
actual application that we instrument.
NB! Only Advice (and "helper") classes of instrumentation modules can access classes from application classpath.
See https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/writing-instrumentation-module.md#advice-classes
*/
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
/*
This dependency is required for DemoSpanProcessor both during compile and runtime.
Only dependencies added to `implementation` configuration will be picked up by Shadow plugin
and added to the resulting jar for our extension's distribution.
*/
implementation 'org.apache.commons:commons-lang3:3.11'
//All dependencies below are only for tests
testImplementation("org.testcontainers:testcontainers:1.16.2")
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.11.2")
testImplementation("com.google.protobuf:protobuf-java-util:3.12.4")
testImplementation("com.squareup.okhttp3:okhttp:3.12.12")
testImplementation("io.opentelemetry:opentelemetry-api:${versions.opentelemetry}")
testImplementation("io.opentelemetry.proto:opentelemetry-proto:0.16.0-alpha")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2")
testRuntimeOnly("ch.qos.logback:logback-classic:1.2.3")
//Otel Java instrumentation that we use and extend during integration tests
otel("io.opentelemetry.javaagent:opentelemetry-javaagent:${versions.opentelemetryJavaagent}")
//TODO remove when start using io.opentelemetry.instrumentation.javaagent-instrumentation plugin
add("codegen", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}")
add("codegen", "ch.qos.logback:logback-classic:1.2.3")
add("muzzleBootstrap", "io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations-support:${versions.opentelemetryJavaagentAlpha}")
add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}")
}
//Produces a copy of upstream javaagent with this extension jar included inside it
//The location of extension directory inside agent jar is hard-coded in the agent source code
task extendedAgent(type: Jar) {
dependsOn(configurations.otel)
archiveFileName = "opentelemetry-javaagent.jar"
from zipTree(configurations.otel.singleFile)
from(tasks.shadowJar.archiveFile) {
into "extensions"
}
//Preserve MANIFEST.MF file from the upstream javaagent
doFirst {
manifest.from(
zipTree(configurations.otel.singleFile).matching {
include 'META-INF/MANIFEST.MF'
}.singleFile
)
}
}
tasks {
test {
useJUnitPlatform()
inputs.files(layout.files(tasks.shadowJar))
inputs.files(layout.files(tasks.extendedAgent))
systemProperty 'io.opentelemetry.smoketest.agentPath', configurations.otel.singleFile.absolutePath
systemProperty 'io.opentelemetry.smoketest.extendedAgentPath', tasks.extendedAgent.archiveFile.get().asFile.absolutePath
systemProperty 'io.opentelemetry.smoketest.extensionPath', tasks.shadowJar.archiveFile.get().asFile.absolutePath
}
compileJava {
options.release.set(8)
}
assemble.dependsOn(shadowJar)
}
muzzle {
pass {
group.set("javax.servlet")
module.set("javax.servlet-api")
versions.set("[3.0,)")
assertInverse.set(true)
}
pass {
group.set("javax.servlet")
module.set("servlet-api")
versions.set("[2.2, 3.0)")
assertInverse.set(true)
}
}