Skip to content

Commit 27231d3

Browse files
authored
Merge branch 'main' into feat/custom-client-resources
2 parents df1f9cd + 647c64e commit 27231d3

File tree

21 files changed

+357
-161
lines changed

21 files changed

+357
-161
lines changed

.github/copilot-instructions.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# OpenTelemetry Java Instrumentation
2+
3+
## Testing
4+
5+
Tests use AssertJ for assertions and JUnit 5 as the testing framework
6+
7+
Test classes and methods should not be public
8+
9+
When registering tests in gradle configurations, if using `val testName by registering(Test::class) {`...
10+
then you need to include `testClassesDirs` and `classpath` like so:
11+
12+
```
13+
val testExperimental by registering(Test::class) {
14+
testClassesDirs = sourceSets.test.get().output.classesDirs
15+
classpath = sourceSets.test.get().runtimeClasspath
16+
...
17+
}
18+
```
19+
20+
## General Java guidelines
21+
22+
* Always import classes when possible (i.e. don't use fully qualified class names in code).
23+
24+
## Gradle CLI
25+
26+
Never use the `--rerun-tasks` flag unless explicitly asked to use this option.
27+
28+
Gradle automatically detects changes and re-runs tasks automatically when needed. Using `--rerun-tasks`
29+
is wasteful and slows down builds unnecessarily.
30+
31+
## Throwing exceptions
32+
33+
When writing instrumentation, you have to be really careful about throwing exceptions. For library
34+
instrumentations it might be acceptable, but in javaagent code you shouldn't throw exceptions
35+
(keep in mind that javaagent instrumentations sometimes use library instrumentations).
36+
37+
In javaagent instrumentations we try not to break applications. If there are changes in the instrumented
38+
library that are not compatible with the instrumentation we disable the instrumentation instead of letting
39+
it fail. This is handled by muzzle. In javaagent instrumentations you should not fail if the methods
40+
that you need don't exist.
41+
42+
## Javaagent Instrumentation
43+
44+
### Java8BytecodeBridge
45+
46+
When to use `Java8BytecodeBridge.currentContext()` vs `Context.current()` ?
47+
48+
Using `Context.current()` is preferred. `Java8BytecodeBridge.currentContext()` is for using inside
49+
advice. We need this method because advice code is inlined in the instrumented method as it is.
50+
Since `Context.current()` is a static interface method it will cause a bytecode verification error
51+
when it is inserted into a pre 8 class. `Java8BytecodeBridge.currentContext()` is a regular class
52+
static method and can be used in any class version.

.github/scripts/check-javaagent-suppression-keys.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash -e
22

3-
# shellcheck disable=SC2044
43
for file in $(find instrumentation -name "*Module.java"); do
54

65
if ! grep -q "extends InstrumentationModule" "$file"; then
@@ -11,9 +10,7 @@ for file in $(find instrumentation -name "*Module.java"); do
1110
continue
1211
fi
1312

14-
# shellcheck disable=SC2001
1513
module_name=$(echo "$file" | sed 's#.*/\([^/]*\)/javaagent/src/.*#\1#')
16-
# shellcheck disable=SC2001
1714
simple_module_name=$(echo "$module_name" | sed 's/-[0-9.]*$//')
1815

1916
if [[ "$simple_module_name" == *jaxrs* ]]; then

.github/scripts/check-package-names.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash -e
22

3-
# shellcheck disable=SC2001
4-
53
for dir in $(find instrumentation -name "*.java" | grep library/src/main/java | sed 's#/[^/]*$##' | sort -u); do
64

75
module_name=$(echo "$dir" | sed 's#.*/\([^/]*\)/library/src/main/java/.*#\1#')

.github/scripts/diff-suppression-keys-with-docs.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ curl https://raw.githubusercontent.com/open-telemetry/opentelemetry.io/main/cont
99

1010
comm -3 \
1111
<(
12-
# shellcheck disable=SC2016 # "Expressions don't expand in single quotes"
1312
sed -n '/----------------------/,${p;/^$/q}' agent-config.md \
1413
| sed '1d;$d' \
1514
| cut -d '|' -f 3 \

.github/scripts/generate-release-contributors.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ from=$(git log --reverse --pretty=format:"%cI" "$from_version..HEAD" | head -1)
1515
# get the last commit on main that was included in the release
1616
to=$(git merge-base origin/main HEAD | xargs git log -1 --pretty=format:"%cI")
1717

18-
# shellcheck disable=SC2016 # "Expressions don't expand in single quotes"
1918
contributors1=$(gh api graphql --paginate -F q="repo:$GITHUB_REPOSITORY is:pr base:main is:merged merged:$from..$to" -f query='
2019
query($q: String!, $endCursor: String) {
2120
search(query: $q, type: ISSUE, first: 100, after: $endCursor) {
@@ -53,7 +52,6 @@ query($q: String!, $endCursor: String) {
5352

5453
# this query captures authors of issues which have had PRs in the current range reference the issue
5554
# but not necessarily through closingIssuesReferences (e.g. addressing just a part of an issue)
56-
# shellcheck disable=SC2016 # "Expressions don't expand in single quotes"
5755
contributors2=$(gh api graphql --paginate -F q="repo:$GITHUB_REPOSITORY is:pr base:main is:merged merged:$from..$to" -f query='
5856
query($q: String!, $endCursor: String) {
5957
search(query: $q, type: ISSUE, first: 100, after: $endCursor) {

.github/scripts/static-import-semconv-constants.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash -e
22

3-
# shellcheck disable=SC2044
43
for file in $(find instrumentation instrumentation-api -name '*Test.java'); do
54
echo "Processing $file"
65

.github/workflows/auto-license-report.yml

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ permissions:
1212
contents: read
1313

1414
jobs:
15-
auto-license-report:
16-
permissions:
17-
contents: write
15+
generate:
1816
runs-on: ubuntu-latest
1917
steps:
2018
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
@@ -33,16 +31,62 @@ jobs:
3331
with:
3432
cache-read-only: true
3533

36-
- name: Use CLA approved bot
37-
run: .github/scripts/use-cla-approved-bot.sh
38-
3934
- name: Update license report
4035
run: ./gradlew generateLicenseReport --no-build-cache
4136

42-
- name: Commit and push if there are changes
37+
- id: create-patch
38+
name: Create patch file
4339
run: |
44-
git add licenses
45-
if ! git diff --cached --quiet; then
46-
git commit -m "Update license report"
47-
git push
40+
git diff > patch
41+
if [ -s patch ]; then
42+
echo "exists=true" >> "$GITHUB_OUTPUT"
43+
fi
44+
45+
- name: Upload patch file
46+
if: steps.create-patch.outputs.exists == 'true'
47+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
48+
with:
49+
path: patch
50+
name: patch
51+
52+
# separate job is just to isolate the OTELBOT_JAVA_INSTRUMENTATION_PRIVATE_KEY usage a bit
53+
apply:
54+
runs-on: ubuntu-latest
55+
needs: generate
56+
steps:
57+
- name: Download patch
58+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
59+
with:
60+
path: ${{ runner.temp }}
61+
62+
- id: check-patch
63+
name: Check patch
64+
working-directory: ${{ runner.temp }}
65+
run: |
66+
if [ -f patch ]; then
67+
echo "exists=true" >> $GITHUB_OUTPUT
4868
fi
69+
70+
- uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
71+
if: steps.check-patch.outputs.exists == 'true'
72+
id: otelbot-token
73+
with:
74+
app-id: ${{ secrets.OTELBOT_JAVA_INSTRUMENTATION_APP_ID }}
75+
private-key: ${{ secrets.OTELBOT_JAVA_INSTRUMENTATION_PRIVATE_KEY }}
76+
77+
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
78+
if: steps.check-patch.outputs.exists == 'true'
79+
with:
80+
token: ${{ steps.otelbot-token.outputs.token }}
81+
82+
- name: Use CLA approved bot
83+
if: steps.check-patch.outputs.exists == 'true'
84+
run: .github/scripts/use-cla-approved-bot.sh
85+
86+
- name: Apply patch and push
87+
if: steps.check-patch.outputs.exists == 'true'
88+
run: |
89+
git apply "${{ runner.temp }}/patch"
90+
git add licenses
91+
git commit -m "Update license report"
92+
git push

.github/workflows/build-daily.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ jobs:
2525
muzzle:
2626
uses: ./.github/workflows/reusable-muzzle.yml
2727

28-
shell-script-check:
29-
uses: ./.github/workflows/reusable-shell-script-check.yml
30-
3128
link-check:
3229
uses: ./.github/workflows/reusable-link-check.yml
3330

.github/workflows/build-pull-request.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ jobs:
4040
with:
4141
cache-read-only: true
4242

43-
shell-script-check:
44-
uses: ./.github/workflows/reusable-shell-script-check.yml
45-
4643
# this is not a required check to avoid blocking pull requests if external links break
4744
markdown-check:
4845
# release branches are excluded because the README.md javaagent download link has to be updated
@@ -66,7 +63,6 @@ jobs:
6663
needs:
6764
- common
6865
- muzzle
69-
- shell-script-check
7066
- markdown-lint-check
7167
runs-on: ubuntu-latest
7268
if: always()
@@ -77,7 +73,6 @@ jobs:
7773
!startsWith(github.base_ref, 'release/') &&
7874
(
7975
needs.muzzle.result != 'success' ||
80-
needs.shell-script-check.result != 'success' ||
8176
needs.markdown-lint-check.result != 'success'
8277
)
8378
)

.github/workflows/build.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ jobs:
3434
if: "!startsWith(github.ref_name, 'release/')"
3535
uses: ./.github/workflows/reusable-muzzle.yml
3636

37-
shell-script-check:
38-
# release branches are excluded to avoid unnecessary maintenance if new shell checks are added
39-
if: "!startsWith(github.ref_name, 'release/')"
40-
uses: ./.github/workflows/reusable-shell-script-check.yml
41-
4237
link-check:
4338
# release branches are excluded to avoid unnecessary maintenance if external links break
4439
# (and also because the README.md javaagent download link has to be updated on release branches

0 commit comments

Comments
 (0)