Skip to content

Commit 6964036

Browse files
authored
Merge branch 'master' into jb/j9_crash_report
2 parents 38b8253 + b90494a commit 6964036

496 files changed

Lines changed: 2388 additions & 1085 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/pull_request_template.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
# Contributor Checklist
88

9-
- Format the title [according the contribution guidelines](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md#title-format)
10-
- Assign the `type:` and (`comp:` or `inst:`) labels in addition to [any useful labels](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md#labels)
11-
- Don't use `close`, `fix` or any [linking keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) when referencing an issue.
9+
- Format the title according to [the contribution guidelines](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md#title-format)
10+
- Assign the `type:` and (`comp:` or `inst:`) labels in addition to [any other useful labels](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md#labels)
11+
- Avoid using `close`, `fix`, or [any linking keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) when referencing an issue
1212
Use `solves` instead, and assign the PR [milestone](https://github.com/DataDog/dd-trace-java/milestones) to the issue
13-
- Update the [CODEOWNERS](https://github.com/DataDog/dd-trace-java/blob/master/.github/CODEOWNERS) file on source file addition, move, or deletion
14-
- Update the [public documentation](https://docs.datadoghq.com/tracing/trace_collection/library_config/java/) in case of new configuration flag or behavior
13+
- Update the [CODEOWNERS](https://github.com/DataDog/dd-trace-java/blob/master/.github/CODEOWNERS) file on source file addition, migration, or deletion
14+
- Update [public documentation](https://docs.datadoghq.com/tracing/trace_collection/library_config/java/) with any new configuration flags or behaviors
1515

1616
Jira ticket: [PROJ-IDENT]
1717

18+
***Note:*** **Once your PR is ready to merge, add it to the merge queue by commenting `/merge`.** `/merge -c` cancels the queue request. `/merge -f --reason "reason"` skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see [this doc](https://datadoghq.atlassian.net/wiki/spaces/DEVX/pages/3121612126/MergeQueue).
19+
1820
<!--
1921
# Opening vs Drafting a PR:
2022
When opening a pull request, please open it as a draft to not auto assign reviewers before you feel the pull request is in a reviewable state.

.github/workflows/analyze-changes.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
${{ runner.os }}-gradle-
3131
3232
- name: Initialize CodeQL
33-
uses: github/codeql-action/init@6bc82e05fd0ea64601dd4b465378bbcf57de0314 # v4.32.1
33+
uses: github/codeql-action/init@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
3434
with:
3535
languages: 'java'
3636
build-mode: 'manual'
@@ -49,7 +49,7 @@ jobs:
4949
--build-cache --parallel --stacktrace --no-daemon --max-workers=4
5050
5151
- name: Perform CodeQL Analysis and upload results to GitHub Security tab
52-
uses: github/codeql-action/analyze@6bc82e05fd0ea64601dd4b465378bbcf57de0314 # v4.32.1
52+
uses: github/codeql-action/analyze@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
5353

5454
trivy:
5555
name: Analyze changes with Trivy
@@ -114,7 +114,7 @@ jobs:
114114
TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db
115115

116116
- name: Upload Trivy scan results to GitHub Security tab
117-
uses: github/codeql-action/upload-sarif@6bc82e05fd0ea64601dd4b465378bbcf57de0314 # v4.32.1
117+
uses: github/codeql-action/upload-sarif@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
118118
if: always()
119119
with:
120120
sarif_file: 'trivy-results.sarif'

.github/workflows/check-pull-request-labels.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
'inst:',
3232
'tag:',
3333
'mergequeue-status:',
34+
'team:',
3435
'performance:', // To refactor to 'ci: ' in the future
3536
'run-tests:' // Unused since GitLab migration
3637
]
@@ -55,7 +56,7 @@ jobs:
5556
'**This PR is blocked until:**\n' +
5657
'1. The invalid labels are deleted, and\n' +
5758
'2. A maintainer deletes this comment to unblock the PR\n\n' +
58-
'**Note:** Simply removing labels from the pull request is not enough - a maintainer must remove the label and delete this comment to remove the block.\n\n' +
59+
'**Note:** Simply removing labels from the pull request is not enough - a maintainer must delete this comment then remove the label to remove the block.\n\n' +
5960
commentMarker
6061
6162
if (blockingComment) {
@@ -79,5 +80,9 @@ jobs:
7980
}
8081
if (blockingComment) {
8182
// Block the PR by failing the workflow
82-
core.setFailed(`PR blocked: Invalid labels detected: (${invalidLabels.join(', ')}). A maintainer must delete the blocking comment after fixing the labels to allow merging.`)
83+
if (hasInvalidLabels) {
84+
core.setFailed(`PR blocked: Invalid labels detected: (${invalidLabels.join(', ')}). A maintainer must delete the blocking comment after fixing the labels to allow merging.`)
85+
} else {
86+
core.setFailed(`PR blocked: A previous blocking comment still exists. A maintainer must delete it to allow merging.`)
87+
}
8388
}

.gitlab/collect_results.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ function get_source_file () {
2626
class="${RESULT_XML_FILE%.xml}"
2727
class="${class##*"TEST-"}"
2828
class="${class##*"."}"
29-
# Extract the inner class name if there's a "$"
30-
if [[ "$class" == *"$"* ]]; then
31-
class="${class##*"$"}"
32-
fi
29+
class="${class##*"$"}" # remove inner class name if it exists
3330
set +e # allow grep to fail
3431
common_root=$(grep -rl "class $class\|static class $class" "$file_path" 2>/dev/null | head -n 1)
3532
set -e
@@ -39,14 +36,19 @@ function get_source_file () {
3936
while [[ $line != "$common_root"* ]]; do
4037
common_root=$(dirname "$common_root")
4138
if [[ "$common_root" == "$common_root/.." ]] || [[ "$common_root" == "/" ]]; then
39+
common_root=""
4240
break
4341
fi
4442
done
4543
done < <(grep -rl "class $class\|static class $class" "$file_path" 2>/dev/null)
4644

47-
if [[ -n "$common_root" ]] && [[ "$common_root" != "/" ]]; then
45+
if [[ -n "$common_root" && "$common_root" != "/" ]]; then
4846
file_path="/$common_root"
47+
else
48+
file_path="UNKNOWN"
4949
fi
50+
else
51+
file_path="UNKNOWN"
5052
fi
5153
fi
5254
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/BaseDecorator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package datadog.trace.bootstrap.instrumentation.decorator;
22

3-
import static datadog.trace.api.cache.RadixTreeCache.PORTS;
43
import static datadog.trace.api.cache.RadixTreeCache.UNSET_PORT;
54
import static datadog.trace.bootstrap.instrumentation.java.net.HostNameResolver.hostName;
65

@@ -153,9 +152,8 @@ public AgentSpan setPeerPort(AgentSpan span, String port) {
153152

154153
public AgentSpan setPeerPort(AgentSpan span, int port) {
155154
if (port > UNSET_PORT) {
156-
span.setTag(Tags.PEER_PORT, PORTS.get(port));
155+
span.setTag(Tags.PEER_PORT, port);
157156
}
158-
159157
return span;
160158
}
161159

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java

Lines changed: 133 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,25 @@
1414
import datadog.trace.api.git.GitInfo;
1515
import datadog.trace.civisibility.ci.env.CiEnvironment;
1616
import datadog.trace.util.Strings;
17+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18+
import java.io.IOException;
1719
import java.nio.charset.StandardCharsets;
20+
import java.nio.file.DirectoryStream;
1821
import java.nio.file.Files;
1922
import java.nio.file.Path;
2023
import java.nio.file.Paths;
2124
import java.util.Map;
25+
import java.util.regex.Matcher;
26+
import java.util.regex.Pattern;
2227
import javax.annotation.Nonnull;
28+
import javax.annotation.Nullable;
2329
import org.slf4j.Logger;
2430
import org.slf4j.LoggerFactory;
2531

32+
@SuppressFBWarnings(
33+
value = "DMI_HARDCODED_ABSOLUTE_FILENAME",
34+
justification =
35+
"The GitHub Actions runner diagnostics directories have well-known absolute paths for Linux runners")
2636
class GithubActionsInfo implements CIProviderInfo {
2737

2838
private static final Logger LOGGER = LoggerFactory.getLogger(GithubActionsInfo.class);
@@ -43,11 +53,26 @@ class GithubActionsInfo implements CIProviderInfo {
4353
public static final String GHACTIONS_JOB = "GITHUB_JOB";
4454
public static final String GITHUB_BASE_REF = "GITHUB_BASE_REF";
4555
public static final String GITHUB_EVENT_PATH = "GITHUB_EVENT_PATH";
56+
public static final String GHACTIONS_JOB_CHECK_RUN_ID = "JOB_CHECK_RUN_ID";
57+
58+
static final String GHA_DIAGNOSTICS_DIR = "/home/runner/actions-runner/_diag";
59+
static final String GHA_DIAGNOSTICS_DIR_CACHED = "/home/runner/actions-runner/cached/_diag";
60+
private static final Pattern CHECK_RUN_ID_PATTERN =
61+
Pattern.compile("\"k\"\\s*:\\s*\"check_run_id\"\\s*,\\s*\"v\"\\s*:\\s*(\\d+(?:\\.\\d+)?)");
4662

4763
private final CiEnvironment environment;
64+
private final Path diagnosticsDir;
65+
private final Path diagnosticsDirCached;
4866

4967
GithubActionsInfo(CiEnvironment environment) {
68+
this(environment, Paths.get(GHA_DIAGNOSTICS_DIR), Paths.get(GHA_DIAGNOSTICS_DIR_CACHED));
69+
}
70+
71+
// for testing purposes
72+
GithubActionsInfo(CiEnvironment environment, Path diagnosticsDir, Path diagnosticsDirCached) {
5073
this.environment = environment;
74+
this.diagnosticsDir = diagnosticsDir;
75+
this.diagnosticsDirCached = diagnosticsDirCached;
5176
}
5277

5378
@Override
@@ -63,26 +88,35 @@ public GitInfo buildCIGitInfo() {
6388

6489
@Override
6590
public CIInfo buildCIInfo() {
91+
String serverUrl = filterSensitiveInfo(environment.get(GHACTIONS_URL));
92+
String repository = environment.get(GHACTIONS_REPOSITORY);
93+
String pipelineId = environment.get(GHACTIONS_PIPELINE_ID);
94+
String commit = environment.get(GHACTIONS_SHA);
95+
6696
final String pipelineUrl =
6797
buildPipelineUrl(
68-
filterSensitiveInfo(environment.get(GHACTIONS_URL)),
69-
environment.get(GHACTIONS_REPOSITORY),
70-
environment.get(GHACTIONS_PIPELINE_ID),
71-
environment.get(GHACTIONS_PIPELINE_RETRY));
72-
final String jobUrl =
73-
buildJobUrl(
74-
filterSensitiveInfo(environment.get(GHACTIONS_URL)),
75-
environment.get(GHACTIONS_REPOSITORY),
76-
environment.get(GHACTIONS_SHA));
98+
serverUrl, repository, pipelineId, environment.get(GHACTIONS_PIPELINE_RETRY));
99+
100+
// Try to get numeric job ID for better job URL
101+
String numericJobId = getNumericJobId();
102+
String jobId;
103+
String jobUrl;
104+
if (numericJobId != null) {
105+
jobId = numericJobId;
106+
jobUrl = buildJobUrlWithNumericId(serverUrl, repository, pipelineId, numericJobId);
107+
} else {
108+
jobId = environment.get(GHACTIONS_JOB);
109+
jobUrl = buildJobUrl(serverUrl, repository, commit);
110+
}
77111

78112
CIInfo.Builder builder = CIInfo.builder(environment);
79113
return builder
80114
.ciProviderName(GHACTIONS_PROVIDER_NAME)
81-
.ciPipelineId(environment.get(GHACTIONS_PIPELINE_ID))
115+
.ciPipelineId(pipelineId)
82116
.ciPipelineName(environment.get(GHACTIONS_PIPELINE_NAME))
83117
.ciPipelineNumber(environment.get(GHACTIONS_PIPELINE_NUMBER))
84118
.ciPipelineUrl(pipelineUrl)
85-
.ciJobId(environment.get(GHACTIONS_JOB))
119+
.ciJobId(jobId)
86120
.ciJobName(environment.get(GHACTIONS_JOB))
87121
.ciJobUrl(jobUrl)
88122
.ciWorkspace(expandTilde(environment.get(GHACTIONS_WORKSPACE_PATH)))
@@ -186,6 +220,94 @@ private String buildJobUrl(final String host, final String repo, final String co
186220
return String.format("%s/%s/commit/%s/checks", host, repo, commit);
187221
}
188222

223+
private String buildJobUrlWithNumericId(
224+
final String host, final String repo, final String pipelineId, final String jobId) {
225+
return String.format("%s/%s/actions/runs/%s/job/%s", host, repo, pipelineId, jobId);
226+
}
227+
228+
/**
229+
* Gets the numeric job ID for GitHub Actions.
230+
*
231+
* <p>First checks the JOB_CHECK_RUN_ID environment variable. If not present, falls back to
232+
* parsing GitHub Actions diagnostics files (Worker_*.log) in the runner's diagnostics directory.
233+
*
234+
* @return the numeric job ID, or null if not found
235+
*/
236+
@Nullable
237+
private String getNumericJobId() {
238+
// First, check if the numeric job ID is provided via environment variable
239+
String jobId = environment.get(GHACTIONS_JOB_CHECK_RUN_ID);
240+
if (Strings.isNotBlank(jobId)) {
241+
return jobId;
242+
}
243+
244+
// Fall back to parsing diagnostics files
245+
jobId = parseJobIdFromDirectory(diagnosticsDir);
246+
if (Strings.isNotBlank(jobId)) {
247+
return jobId;
248+
}
249+
250+
return parseJobIdFromDirectory(diagnosticsDirCached);
251+
}
252+
253+
@Nullable
254+
private String parseJobIdFromDirectory(Path directory) {
255+
if (!Files.isDirectory(directory)) {
256+
return null;
257+
}
258+
259+
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory, "Worker_*.log")) {
260+
// Find the most recent file by filename (contains timestamp like
261+
// Worker_20260130-154110-utc.log)
262+
Path mostRecentLog = null;
263+
for (Path workerLog : stream) {
264+
if (mostRecentLog == null
265+
|| workerLog.getFileName().toString().compareTo(mostRecentLog.getFileName().toString())
266+
> 0) {
267+
mostRecentLog = workerLog;
268+
}
269+
}
270+
271+
if (mostRecentLog == null) {
272+
return null;
273+
}
274+
275+
String content = new String(Files.readAllBytes(mostRecentLog), StandardCharsets.UTF_8);
276+
return parseCheckRunIdFromContent(content);
277+
} catch (IOException e) {
278+
LOGGER.debug("Error reading diagnostics directory: {}", directory, e);
279+
return null;
280+
}
281+
}
282+
283+
/**
284+
* Extracts the last check_run_id value from the file content.
285+
*
286+
* <p>The JSON structure in worker logs contains: {"k":"check_run_id","v":12345.0}
287+
*
288+
* <p>Uses the last match because a single worker file might contain multiple jobs' data, and the
289+
* most recent job entry appears last.
290+
*
291+
* @param content the file content to parse
292+
* @return the check_run_id as a string, or null if not found
293+
*/
294+
@Nullable
295+
String parseCheckRunIdFromContent(String content) {
296+
Matcher matcher = CHECK_RUN_ID_PATTERN.matcher(content);
297+
String lastMatch = null;
298+
while (matcher.find()) {
299+
String value = matcher.group(1);
300+
// Strip decimal part if present
301+
int pointIdx = value.indexOf('.');
302+
if (pointIdx != -1) {
303+
lastMatch = value.substring(0, pointIdx);
304+
} else {
305+
lastMatch = value;
306+
}
307+
}
308+
return lastMatch;
309+
}
310+
189311
@Override
190312
public Provider getProvider() {
191313
return Provider.GITHUBACTIONS;

0 commit comments

Comments
 (0)