Commit e27f234
authored
Fix the gap in the build time instrumentation plugin to allow processing additional folder (#10735)
fix(build): TODO non-deterministic OTel class embedding in otel-bootstrap shadow jar
The problem was that `./gradlew shadowJar --rerun-tasks` execution was
non-deterministic depending on the state of the build. This resulted in
`otel-bootstrap` jar sometimes embedded the full set of OTel semconv
classes (~189), and sometimes only the Java-compiled ones (~4).
### Root cause
`unpackJars` and `compileJava` shared the same output directory
(`compileJava.destinationDirectory` = `build/classes/java/main/`).
After a first successful build, `main/` contained **instrumented** OTel
classes (modified in-place by the ByteBuddy `doLast` action).
But on the next execution **with** `--rerun-tasks`:
1. `unpackJars` re-ran and wrote **original** (un-instrumented) OTel
classes to `main/`, replacing the previously-instrumented versions.
2. The Java compiler detected that files in its output directory had
changed (instrumented → original) and switched to
**non-incremental mode**, in the info log:
Not incremental: removing prior outputs"
thus deleting **all** prior outputs from `main/` — including the
OTel classes just placed by `unpackJars`.
3. In the end only the project's compiled and processed classes files
remained.
The bug was not manifested on a clean state because `main/` had no prior
files for the Java compiler to compare against.
---
This commit fixes the situation by filling a gap in the build time
instrumentation plugin:
- `unpackJars`'s output is now a dedicated `build/otel-unpacked/`
directory to avoid overlap with `compileJava.destinationDirectory`.
- Build time instrumentation plugin allow to declare a
`includeClassDirectories` used as task input, its classes will be
included for post processing.
Because `build/otel-unpacked/` is now only written to by `unpackJars`,
Gradle's stale-output cleanup for `compileJava` never touches it.
chore: Rename unpackJars to unpackOtelJars
fix(build): Properly wire the unpackJars task
The `unpackJars` task dependency do not have to be declared as a
dependency of the compile task, however it should be declared as
an included input of the build time instrumentation.
Also, the `unpackJars` is now a `Sync` task to deletes files that
are no longer in the source JARs.
style: sourcesDir to classesDir
Merge branch 'master' into bdu/allow-build-time-instrumentation-to-process-additional-classes
Merge branch 'master' into bdu/allow-build-time-instrumentation-to-process-additional-classes
Co-authored-by: brice.dutheil <brice.dutheil@datadoghq.com>1 parent 77900be commit e27f234
6 files changed
Lines changed: 42 additions & 27 deletions
File tree
- buildSrc/src/main/groovy/datadog/gradle/plugin/instrument
- dd-java-agent/agent-otel/otel-bootstrap
buildSrc/src/main/groovy/datadog/gradle/plugin/instrument/BuildTimeInstrumentationExtension.groovy
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
149 | 150 | | |
150 | 151 | | |
151 | 152 | | |
152 | | - | |
| 153 | + | |
| 154 | + | |
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
| |||
Lines changed: 9 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
| |||
72 | 75 | | |
73 | 76 | | |
74 | 77 | | |
| 78 | + | |
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
31 | 48 | | |
32 | 49 | | |
| 50 | + | |
33 | 51 | | |
34 | 52 | | |
35 | 53 | | |
| |||
56 | 74 | | |
57 | 75 | | |
58 | 76 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | 77 | | |
81 | 78 | | |
82 | 79 | | |
| |||
0 commit comments