-
Notifications
You must be signed in to change notification settings - Fork 932
/
Copy pathjavaagent.gradle
129 lines (103 loc) · 4.08 KB
/
javaagent.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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id "com.github.johnrengelman.shadow"
}
description = 'OpenTelemetry Javaagent'
group = 'io.opentelemetry.javaagent'
apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/publish.gradle"
configurations {
shadowInclude
}
jar {
manifest {
attributes(
"Main-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Agent-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Premain-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Can-Redefine-Classes": true,
"Can-Retransform-Classes": true,
)
}
}
CopySpec isolateSpec(Collection<Project> projectsWithShadowJar) {
return copySpec {
from({ projectsWithShadowJar.tasks.shadowJar.collect { zipTree(it.archiveFile) } }) {
// important to keep prefix 'inst' short, as it is prefixed to lots of strings in runtime mem
into 'inst'
rename '(^.*)\\.class$', '$1.classdata'
// Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac)
rename '^LICENSE$', 'LICENSE.renamed'
}
}
}
//Includes everything needed for OOTB experience
shadowJar {
dependsOn ':instrumentation:shadowJar'
dependsOn ':javaagent-exporters:shadowJar'
def projectsWithShadowJar = [project(':javaagent-exporters'), project(':instrumentation')]
with isolateSpec(projectsWithShadowJar)
// Exclude class files pulled in from the javaagent-exporters project that are also pulled in from the
// instrumentation project.
// Removing duplicates reduces jar size and can prevent issues when downstream projects repackage
// the jar.
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
//Includes instrumentations, but not exporters
task lightShadow(type: ShadowJar) {
from sourceSets.main.output
dependsOn ':instrumentation:shadowJar'
def projectsWithShadowJar = [project(':instrumentation')]
with isolateSpec(projectsWithShadowJar)
}
publishing {
publications {
maven(MavenPublication) {
artifact lightShadow
}
}
}
tasks.withType(ShadowJar).configureEach {
configurations = [project.configurations.shadowInclude]
mergeServiceFiles()
manifest {
inheritFrom project.tasks.jar.manifest
}
exclude '**/module-info.class'
// Prevents conflict with other SLF4J instances. Important for premain.
relocate 'org.slf4j', 'io.opentelemetry.javaagent.slf4j'
// rewrite dependencies calling Logger.getLogger
relocate 'java.util.logging.Logger', 'io.opentelemetry.javaagent.bootstrap.PatchLogger'
// prevents conflict with library instrumentation
relocate 'io.opentelemetry.instrumentation.api', 'io.opentelemetry.javaagent.shaded.instrumentation.api'
// relocate OpenTelemetry API
relocate "io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api"
relocate "io.opentelemetry.spi", "io.opentelemetry.javaagent.shaded.io.opentelemetry.spi"
relocate "io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context"
relocate "io.opentelemetry.extension.trace.propagation", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.trace.propagation"
}
dependencies {
testImplementation project(':javaagent-bootstrap')
testImplementation project(':javaagent-api')
testImplementation project(':instrumentation-api')
testImplementation project(':utils:test-utils')
testImplementation deps.testLogging
testImplementation deps.guava
testImplementation 'io.opentracing.contrib.dropwizard:dropwizard-opentracing:0.2.2'
shadowInclude project(path: ':javaagent-bootstrap')
}
tasks.withType(Test).configureEach {
// Multi-threaded logging seems to be causing deadlocks with Gradle's log capture.
// jvmArgs "-Dio.opentelemetry.javaagent.slf4j.simpleLogger.defaultLogLevel=debug"
// jvmArgs "-Dorg.slf4j.simpleLogger.defaultLogLevel=debug"
doFirst {
// Defining here to allow jacoco to be first on the command line.
jvmArgs "-javaagent:${shadowJar.archivePath}"
}
testLogging {
events "started"
}
dependsOn shadowJar
}
assemble.dependsOn lightShadow
assemble.dependsOn shadowJar