Skip to content

Commit 7c44dfc

Browse files
authored
Merge branch 'master' into joey/aws-sns
2 parents 08fd7d7 + 57369e8 commit 7c44dfc

File tree

18 files changed

+701
-232
lines changed

18 files changed

+701
-232
lines changed

BUILDING.md

Lines changed: 146 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11

22
# Building
33

4+
This documentation is dedicated to developers to setup their environment, and build the project from sources:
5+
6+
* Check your development environment is ready to build,
7+
* Check the development environment requirements,
8+
* Guide - How to setup your development environment,
9+
* Guide - How to build the project.
10+
411
## Development environment quick check
512

6-
You can quickly check that your development environment is properly set up to build the project running `./setup.sh` from the project root:
13+
As a preliminary step, you can quickly check that your development environment is properly set up to build the project running `./setup.sh` from the project root:
714

815
```bash
916
$ ./setup.sh
@@ -18,50 +25,169 @@ $ ./setup.sh
1825
✅ The git command line is installed.
1926
✅ pre-commit hook is installed in repository.
2027
✅ git config submodule.recurse is set to true.
21-
ℹ️ Checking shell configuration:
22-
✅ File descriptor limit is set to 12800.
28+
ℹ️ Checking Docker environment:
2329
✅ The docker command line is installed.
2430
✅ The Docker server is running.
2531
```
2632

27-
If the script finds any issue, you can follow the requirements below to install and configure the required tools and [the code contribution guidelines](CONTRIBUTING.md#code-contributions).
33+
If the script finds any issue, you can check the requirements and follow the guide below to install and configure the required tools.
2834

2935
## Building requirements
3036

3137
To build the full project:
3238

33-
* JDK version 8 must be installed.
34-
* JDK version 11 must be installed.
35-
* JDK version 17 must be installed.
36-
* JDK version 21 must be installed.
37-
* `JAVA_8_HOME` must point to the JDK-8 location.
38-
* `JAVA_11_HOME` must point to the JDK-11 location.
39-
* `JAVA_17_HOME` must point to the JDK-17 location.
40-
* `JAVA_21_HOME` must point to the JDK-21 location.
39+
* The JDK versions 8, 11, 17 and 21 must be installed
40+
* The `JAVA_8_HOME`, `JAVA_11_HOME`, `JAVA_17_HOME`, `JAVA_21_HOME` and `JAVA_GRAALVM17_HOME` must point to their respective JDK location,
4141
* The JDK-8 `bin` directory must be the only JDK on the PATH (e.g. `$JAVA_8_HOME/bin`).
42-
* `JAVA_HOME` may be unset. If set, it must point to JDK-8 (same as `JAVA_8_HOME`).
43-
* git command line must be installed.
42+
* The `JAVA_HOME` environment variable may be unset. If set, it must point to the JDK 8 location (same as `JAVA_8_HOME`),
43+
* The `git` command line must be installed,
4444
* A container runtime environment must be available to run all tests (usually Docker Desktop).
4545

46-
> [!NOTE]
47-
> MacOS users, remember that `/usr/libexec/java_home` may control which JDK is in your path.
46+
47+
## Setting up development environment
48+
49+
### Install the required JDKs
50+
51+
**On MacOS:**
52+
53+
* Install the required JDKs using `brew`:
54+
`brew install --cask zulu@8 zulu@11 zulu@17 zulu@21 graalvm/tap/graalvm-ce-java17`
55+
* Fix the GraalVM installation by [removing the quarantine flag](https://www.graalvm.org/latest/docs/getting-started/macos/):
56+
`sudo xattr -r -d com.apple.quarantine /Library/Java/JavaVirtualMachines/graalvm-<current version of graalvm>`
57+
* Add the required environment variables to your shell using the `export` command:
58+
```shell
59+
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
60+
export JAVA_11_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
61+
export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home
62+
export JAVA_21_HOME=/Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home
63+
export JAVA_GRAALVM17_HOME=/Library/Java/JavaVirtualMachines/graalvm-<current version of grallvm>/Contents/Home
64+
export JAVA_HOME=$JAVA_8_HOME
65+
```
4866

4967
> [!NOTE]
5068
> ARM users, there is no Oracle JDK v8 for ARM.
51-
> You might want to use [Azul's Zulu](https://www.azul.com/downloads/?version=java-8-lts&architecture=arm-64-bit&package=jdk#zulu) builds of Java 8.
52-
> On macOS, they can be installed using `brew tap homebrew/cask-versions && brew install --cask zulu8`.
69+
> It's recommended to use [Azul's Zulu](https://www.azul.com/downloads/?version=java-8-lts&architecture=arm-64-bit&package=jdk#zulu) builds of Java 8.
5370
> [Amazon Corretto](https://aws.amazon.com/corretto/) builds have also been proven to work.
5471
72+
> [!NOTE]
73+
> MacOS users, remember that `/usr/libexec/java_home` may control which JDK is in your path.
74+
75+
> [!NOTE]
76+
> You can permanently install the environment variables by appending the `export` commands into your shell configuration file `~/.zshrc` (or `.bashrc` dependening of your shell).
77+
> You will need to restart your shell first to apply the changes.
78+
79+
**On Linux:**
80+
81+
* Download and extract JDK 8, 11, 17 and 21 from [Eclipse Temurin releases](https://adoptium.net/temurin/releases/) and GraalVM from [Oracle downloads](https://www.graalvm.org/downloads/),
82+
* Install the GraalVM native image requirements for native builds following [the GraalVM official documentation](https://www.graalvm.org/latest/reference-manual/native-image/#prerequisites),
83+
* Add the required environment variables to your shell using the `export` command:
84+
```shell
85+
export JAVA_8_HOME=/<path to extracted archive>/jdk8u<current version of JDK 8>
86+
export JAVA_11_HOME=/<path to extracted archive>/jdk-11.<current version of JDK 11>
87+
export JAVA_17_HOME=/<path to extracted archive>/jdk-17.<current version of JDK 17>
88+
export JAVA_21_HOME=/<path to extracted archive>/jdk-21.<current version of JDK 21>
89+
export JAVA_GRAALVM17_HOME=/<path to extracted archive>/graalvm-jdk-17.<current version of grallvm>/Contents/Home
90+
export JAVA_HOME=$JAVA_8_HOME
91+
```
92+
93+
> [!NOTE]
94+
> You can permanently install the environment variables by appending the `export` commands into your shell configuration file `~/.zshrc` (or `.bashrc` dependening of your shell).
95+
> You will need to restart your shell first to apply the changes.
96+
97+
**On Windows:**
98+
99+
* Download and install JDK 8, 11, 17 and 21 from [Eclipse Temurin releases](https://adoptium.net/temurin/releases/) and GraalVM from [Oracle downloads](https://www.graalvm.org/downloads/),
100+
* Install the GraalVM native image requirements for native builds following [the GraalVM official documentation](https://www.graalvm.org/latest/docs/getting-started/windows/#prerequisites-for-native-image-on-windows),
101+
* Add the required environment variables:
102+
* Open the *Start Menu*, type `environment variable` and open the *System Properties* using the *Edit environment variable for your account* entry,
103+
* Add new entries to the table:
104+
* `JAVA_8_HOME` to the JDK 8 installation folder, usually `C:\Program Files\Eclipse Adoptium\jdk-<current version of Java 8>-hotspot\bin`,
105+
* `JAVA_11_HOME`, `JAVA_21_HOME`, and `JAVA_21_HOME` similarly to their respective installation `bin` folders,
106+
* `JAVA_GRAALVM17_HOME` to the GraalVM installation folder, usually `C:\Program Files\Java\<current version of graalvm>\bin`.
107+
108+
### Install git
109+
110+
**On MacOS**, you can trigger the installation running any `git` command from the terminal, like `git --version`.
111+
If not installed, it will prompt you to install it.
112+
113+
**On Linux**, use `# apt-get install git` command.
114+
115+
**On Windows**, [download and install the installer from the offical website](https://git-scm.com/download/win).
116+
117+
### Install Docker Desktop
118+
119+
Download and install Docker Desktop from the offical website for [MacOS](https://docs.docker.com/desktop/install/mac-install/), [Linux](https://docs.docker.com/desktop/install/linux-install/) or [Windows](https://docs.docker.com/desktop/install/windows-install/).
120+
121+
> [!NOTE]
122+
> Docker Desktop is the recommended container runtime environment but you can use any other environment to run testcontainers tests.
123+
> Check [the testcontainers container runtime requirements](https://java.testcontainers.org/supported_docker_environment/) for more details.
124+
125+
### Clone the repository and setup git
126+
127+
First get a copy of the project.
128+
Start a terminal into your workspace and clone the repository using git:
129+
```bash
130+
git clone --recurse-submodules [email protected]:DataDog/dd-trace-java.git
131+
```
132+
133+
Then, install the project git hooks:
134+
135+
There is a pre-commit hook setup to verify formatting before committing. It can be activated with this command:
136+
137+
```bash
138+
# On MacOS and Linux
139+
cd dd-trace-java
140+
cp .githooks/pre-commit .git/hooks/
141+
142+
# On Windows
143+
cd dd-trace-java
144+
copy .githooks/pre-comit .git/hooks/
145+
```
146+
147+
> [!TIP]
148+
> You can alternative use the `core.hooksPath` configuration to point to the `.githooks` folder using `git config --local core.hooksPath .githooks` if you don't already have a hooks path already defined system-wide.
149+
150+
> [!NOTE]
151+
> The git hooks will check your code is properly formatted before commiting it.
152+
> This is done both to avoid future merge conflict and ensure an uniformity inside the code base.
153+
154+
Finally, configure git to automatically update submodules:
155+
```bash
156+
git config --local submodule.recurse true
157+
```
158+
159+
> [!NOTE]
160+
> Git does not automatically update submodules when switching branches.
161+
> Without this configuration, you will need to remember to add `--recurse-submodules` to `git checkout` when switching to old branches.
162+
163+
> [!TIP]
164+
> This will keep the submodule in `dd-java-agent/agent-jmxfetch/integrations-core` up-to-date.
165+
> There is also an automated check when opening a pull request if you are trying to submit an module version change (usually an outdated version).
166+
167+
> [!NOTE]
168+
> Both git configurations (hooks and submodule) will only be applied to the project and won't apply globally to your setup.
169+
170+
### Check your development environment
171+
172+
If you properly followed this guide, the `setup.sh` script at the project root should run without issue, confirming everything is properly setup.
173+
174+
> [!NOTE]
175+
> The `setup.sh` script is only available for MacOS and Linux.
176+
177+
### Build the project
178+
179+
Now everything is setup, you can then move the next section to start a build, or check [the contribution guidelines](CONTRIBUTING.md).
180+
55181
## Building commands
56182

57183
To build the project without running tests run:
58-
59184
```bash
60185
./gradlew clean assemble
61186
```
62187

63188
To build the entire project with tests (this can take a very long time) run:
64-
65189
```bash
66190
./gradlew clean build
67191
```
192+
193+
After building the project, you can find the jar build artifact into the `dd-java-agent/build/libs` folder.

CONTRIBUTING.md

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,6 @@ command line should be Java 8.
6565
![import layout](https://user-images.githubusercontent.com/734411/43430811-28442636-94ae-11e8-86f1-f270ddcba023.png)
6666
* [Google Java Format](https://plugins.jetbrains.com/plugin/8527-google-java-format) plugin
6767

68-
### Git pre-commit hook
69-
70-
There is a pre-commit hook setup to verify formatting before committing. It can be activated with this command:
71-
72-
```bash
73-
git config core.hooksPath .githooks
74-
```
75-
76-
### Git submodule setup
77-
78-
Git does not automatically update submodules when switching branches.
79-
80-
Add the following configuration setting, or you will need to remember to add `--recurse-submodules` to `git checkout`
81-
when switching to old branches.
82-
83-
```bash
84-
git config --local submodule.recurse true
85-
```
86-
87-
This will keep the submodule in `dd-java-agent/agent-jmxfetch/integrations-core` up to date.
88-
8968
### Troubleshooting
9069

9170
* Gradle fails with a "too many open files" error.
@@ -109,31 +88,3 @@ This will keep the submodule in `dd-java-agent/agent-jmxfetch/integrations-core`
10988
to `Add New` -> `Gradle` -> `Environmental Variables`
11089

11190
</details>
112-
113-
## Running tests on another JVM
114-
115-
To run tests on a different JVM than the one used for doing the build, you need two things:
116-
117-
1) An environment variable pointing to the JVM to use on the form `JAVA_[JDKNAME]_HOME`,
118-
e.g. `JAVA_ZULU15_HOME`, `JAVA_GRAALVM17_HOME`
119-
120-
2) A command line option to the gradle task on the form `-PtestJvm=[JDKNAME]`,
121-
e.g. `-PtestJvm=ZULU15`, `-PtestJvm=GRAALVM17`
122-
123-
Please note that the JDK name needs to end with the JDK version, e.g. `11`, `ZULU15`, `ORACLE8`, `GRAALVM17`, etc.
124-
125-
## The APM test agent
126-
127-
The APM test agent emulates the APM endpoints of the Datadog Agent.
128-
The APM Test Agent container runs alongside Java tracer Instrumentation Tests in CI,
129-
handling all traces during test runs and performing a number of `Trace Checks`.
130-
Trace Check results are returned within the `Get APM Test Agent Trace Check Results` step for all instrumentation test
131-
jobs.
132-
Check [trace invariant checks](https://github.com/DataDog/dd-apm-test-agent#trace-invariant-checks) for more
133-
informations.
134-
135-
The APM Test Agent also emits helpful logging, including logging received traces' headers, spans, errors encountered,
136-
ands information on trace checks being performed.
137-
Logs can be viewed in CircleCI within the Test-Agent container step for all instrumentation test suites,
138-
ie: `z_test_8_inst` job.
139-
Read more about [the APM Test Agent](https://github.com/datadog/dd-apm-test-agent#readme).

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ Take a look at the [APM Glossary][visualization docs].
3434
## Contributing
3535

3636
Before contributing to the project, please take a moment to read our brief [Contribution Guidelines](CONTRIBUTING.md).
37+
Then check our guides:
38+
* [How to setup a development and build the project](BUILDING.md),
39+
* [How to create a new instrumentation](docs/add_new_instrumentation.md),
40+
* [How to test](docs/how_to_test.md),
41+
42+
Or our reference documents:
43+
* [How instrumentations work](docs/how_instrumentations_work.md).

dd-java-agent/agent-builder/src/main/java/datadog/trace/agent/tooling/AgentInstaller.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.trace.agent.tooling;
22

3+
import static datadog.trace.agent.tooling.ExtensionFinder.findExtensions;
4+
import static datadog.trace.agent.tooling.ExtensionLoader.loadExtensions;
35
import static datadog.trace.agent.tooling.bytebuddy.matcher.GlobalIgnoresMatcher.globalIgnoresMatcher;
46
import static net.bytebuddy.matcher.ElementMatchers.isDefaultFinalizer;
57

@@ -242,19 +244,18 @@ public void applied(Iterable<String> instrumentationNames) {
242244
/** Returns an iterable that combines the original sequence with any discovered extensions. */
243245
private static Iterable<InstrumenterModule> withExtensions(Iterable<InstrumenterModule> initial) {
244246
String extensionsPath = InstrumenterConfig.get().getTraceExtensionsPath();
245-
if (null == extensionsPath) {
246-
return initial;
247-
}
248-
final List<InstrumenterModule> extensions = new ExtensionsLoader(extensionsPath).loadModules();
249-
if (extensions.isEmpty()) {
250-
return initial;
251-
}
252-
return new Iterable<InstrumenterModule>() {
253-
@Override
254-
public Iterator<InstrumenterModule> iterator() {
255-
return withExtensions(initial.iterator(), extensions);
247+
if (null != extensionsPath) {
248+
if (findExtensions(extensionsPath, InstrumenterModule.class)) {
249+
final List<InstrumenterModule> extensions = loadExtensions(InstrumenterModule.class);
250+
return new Iterable<InstrumenterModule>() {
251+
@Override
252+
public Iterator<InstrumenterModule> iterator() {
253+
return withExtensions(initial.iterator(), extensions);
254+
}
255+
};
256256
}
257-
};
257+
}
258+
return initial;
258259
}
259260

260261
/** Returns an iterator that combines the original sequence with any discovered extensions. */

dd-java-agent/agent-builder/src/main/java/datadog/trace/agent/tooling/CombiningTransformerBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void applyAdvice(ElementMatcher<? super MethodDescription> matcher, Strin
247247
}
248248
advice.add(
249249
new AgentBuilder.Transformer.ForAdvice(customMapping)
250-
.include(Utils.getBootstrapProxy(), Utils.getAgentClassLoader())
250+
.include(Utils.getBootstrapProxy(), Utils.getExtendedClassLoader())
251251
.withExceptionHandler(ExceptionHandlers.defaultExceptionHandler())
252252
.advice(not(ignoredMethods).and(matcher), adviceClass));
253253
}

0 commit comments

Comments
 (0)