Skip to content

Commit a326cf5

Browse files
committed
refactor collect script
1 parent 66ef0e6 commit a326cf5

File tree

5 files changed

+107
-47
lines changed

5 files changed

+107
-47
lines changed

docs/instrumentation-list.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ libraries:
502502
couchbase:
503503
- name: couchbase-3.1.6
504504
description: |
505-
Couchbase instrumentation is owned upstream. This Couchbase instrumentation works by intercepting the constructor of the CoreEnvironment.Builder class. On construction, it automatically sets the Couchbase requestTracer to use an OpenTelemetryRequestTracer that wraps the agent's TracerProvider. This enables distributed tracing for Couchbase operations using OpenTelemetry, without requiring manual configuration by the user.
505+
Couchbase instrumentation is owned upstream. This Couchbase instrumentation manipulates the constructor of the CoreEnvironment.Builder class and sets the Couchbase requestTracer to use an OpenTelemetryRequestTracer that integrates with the OpenTelemetry agent.
506506
source_path: instrumentation/couchbase/couchbase-3.1.6
507507
scope:
508508
name: io.opentelemetry.couchbase-3.1.6
@@ -537,7 +537,7 @@ libraries:
537537
default: false
538538
- name: couchbase-3.2
539539
description: |
540-
Couchbase instrumentation is owned upstream. This Couchbase instrumentation works by intercepting the constructor of the CoreEnvironment.Builder class. On construction, it automatically sets the Couchbase requestTracer to use an OpenTelemetryRequestTracer that wraps the agent's TracerProvider. This enables distributed tracing for Couchbase operations using OpenTelemetry, without requiring manual configuration by the user.
540+
Couchbase instrumentation is owned upstream. This Couchbase instrumentation manipulates the constructor of the CoreEnvironment.Builder class and sets the Couchbase requestTracer to use an OpenTelemetryRequestTracer that integrates with the OpenTelemetry agent.
541541
source_path: instrumentation/couchbase/couchbase-3.2
542542
scope:
543543
name: io.opentelemetry.couchbase-3.2
@@ -546,7 +546,7 @@ libraries:
546546
- com.couchbase.client:java-client:[3.2.0,)
547547
- name: couchbase-3.1
548548
description: |
549-
Couchbase instrumentation is owned upstream. This instrumentation hooks into the CoreEnvironment.Builder constructor and automatically sets the Couchbase requestTracer to use an OpenTelemetry tracer from the agent. This enables distributed tracing for Couchbase operations using OpenTelemetry, without requiring manual configuration by the user.
549+
Couchbase instrumentation is owned upstream. This Couchbase instrumentation manipulates the constructor of the CoreEnvironment.Builder class and sets the Couchbase requestTracer to use an OpenTelemetryRequestTracer that integrates with the OpenTelemetry agent.
550550
source_path: instrumentation/couchbase/couchbase-3.1
551551
scope:
552552
name: io.opentelemetry.couchbase-3.1

instrumentation-docs/collect.sh

Lines changed: 95 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#!/bin/bash
2-
set -euo pipefail
1+
#!/usr/bin/env bash
2+
3+
# Runs selected Gradle test tasks to regenerate *.telemetry output for
4+
# individual OpenTelemetry Java agent instrumentations.
35

4-
# This script selectively runs tests for specific instrumentations in order to generate telemetry data.
6+
set -euo pipefail
57

6-
instrumentations=(
8+
readonly INSTRUMENTATIONS=(
9+
# <module path (colon-separated)> : <javaagent|library> : [ gradle-task-suffix ]
710
"apache-httpclient:apache-httpclient-5.0:javaagent:test"
811
"alibaba-druid-1.0:javaagent:test"
912
"c3p0-0.9:javaagent:test"
@@ -12,45 +15,107 @@ instrumentations=(
1215
"apache-dbcp-2.0:javaagent:test"
1316
)
1417

15-
gradle_tasks=()
18+
readonly TELEMETRY_DIR_NAME=".telemetry"
1619

20+
# Splits a single descriptor into its three logical parts.
21+
# argument $1: descriptor string (ex: "foo:bar:baz:test")
22+
# Outputs three variables via echo:
23+
# 1. module_path - instrumentation/foo/bar
24+
# 2. task_type - javaagent | library
25+
# 3. task_suffix - test
26+
parse_descriptor() {
27+
local descriptor="$1"
28+
local -a parts
1729

18-
for descriptor in "${instrumentations[@]}"; do
19-
# Split into array by colon
30+
# Convert colon-delimited string into array
2031
IFS=':' read -r -a parts <<< "$descriptor"
2132

22-
# Find "javaagent" / "library" token
23-
type_idx=-1
33+
# Locate "javaagent" or "library" token (there should be exactly one)
34+
local type_idx=-1
2435
for i in "${!parts[@]}"; do
25-
if [[ ${parts[$i]} == javaagent || ${parts[$i]} == library ]]; then
26-
type_idx=$i; break
36+
if [[ ${parts[$i]} == "javaagent" || ${parts[$i]} == "library" ]]; then
37+
type_idx=$i
38+
break
2739
fi
2840
done
29-
(( type_idx >= 0 )) || { echo "bad descriptor: $descriptor" >&2; continue; }
3041

31-
type=${parts[$type_idx]}
42+
if [[ $type_idx -lt 0 ]]; then
43+
echo "ERROR: malformed descriptor: $descriptor" >&2
44+
return 1
45+
fi
46+
47+
local task_type="${parts[$type_idx]}"
48+
49+
# Optional suffix lives after the type token
50+
local task_suffix=""
51+
if (( type_idx + 1 < ${#parts[@]} )); then
52+
task_suffix="${parts[$((type_idx + 1))]}"
53+
fi
54+
55+
# Join everything *before* the type token with slashes to make
56+
# instrumentation/<path>/...
57+
local path_segments=("${parts[@]:0:type_idx}")
58+
local module_path="instrumentation/$(IFS=/; echo "${path_segments[*]}")"
59+
60+
echo "$module_path" "$task_type" "$task_suffix"
61+
}
3262

33-
# set suffix to the next array element if one exists, otherwise leave it blank.
34-
suffix=""; (( type_idx+1 < ${#parts[@]} )) && suffix=${parts[$((type_idx+1))]}
63+
# Removes a .telemetry directory if it exists under the given module path.
64+
delete_existing_telemetry() {
65+
local module_path="$1"
66+
local telemetry_path="$module_path/$TELEMETRY_DIR_NAME"
3567

36-
# Slice the array to keep only the module path parts
37-
path_segments=("${parts[@]:0:type_idx}")
68+
if [[ -d "$telemetry_path" ]]; then
69+
rm -rf "$telemetry_path"
70+
fi
71+
}
3872

39-
# Join the path segments to form the full path
40-
path="instrumentation/$(IFS=/; echo "${path_segments[*]}")"
73+
# Converts the three parsed parts into a Gradle task name.
74+
# ex: instrumentation:foo:bar:javaagent:test
75+
build_gradle_task() {
76+
local module_path="$1" # instrumentation/foo/bar
77+
local task_type="$2" # javaagent | library
78+
local task_suffix="$3" # test | <blank>
4179

42-
[[ -d "$path/.telemetry" ]] && rm -rf "$path/.telemetry"
80+
# replace slashes with colons, then append task parts
81+
local module_colon_path="${module_path//\//:}"
82+
local task=":$module_colon_path:$task_type"
4383

44-
task=":instrumentation:$(IFS=:; echo "${path_segments[*]}"):$type"
45-
[[ -n $suffix ]] && task+=":$suffix"
46-
gradle_tasks+=("$task")
84+
[[ -n $task_suffix ]] && task+=":$task_suffix"
85+
echo "$task"
86+
}
87+
88+
# Cleans any stray .telemetry directories left in the repo.
89+
find_and_remove_all_telemetry() {
90+
echo "🔍 Removing stray .telemetry directories..."
91+
find . -type d -name "$TELEMETRY_DIR_NAME" -exec rm -rf {} +
92+
}
93+
94+
# Main
95+
declare -a gradle_tasks=()
96+
97+
for descriptor in "${INSTRUMENTATIONS[@]}"; do
98+
# Parse the descriptor into its components
99+
if ! read -r module_path task_type task_suffix \
100+
< <(parse_descriptor "$descriptor"); then
101+
continue # skip badly-formed descriptor
102+
fi
103+
104+
# Make sure we’re starting fresh for this instrumentation
105+
delete_existing_telemetry "$module_path"
106+
107+
# Build the Gradle task string and queue it
108+
gradle_tasks+=( "$(build_gradle_task "$module_path" "$task_type" "$task_suffix")" )
47109
done
48110

49-
# rerun-tasks is used to force re-running tests that might be cached
50-
echo "Running: ./gradlew ${gradle_tasks[*]} -PcollectMetadata=true --rerun-tasks"
51-
./gradlew "${gradle_tasks[@]}" -PcollectMetadata=true --rerun-tasks
52-
#./gradlew :instrumentation-docs:runAnalysis
111+
echo
112+
echo "Running Gradle tasks:"
113+
printf ' %s\n' "${gradle_tasks[@]}"
114+
echo
115+
116+
./gradlew "${gradle_tasks[@]}" \
117+
-PcollectMetadata=true \
118+
--rerun-tasks
53119

54-
# Remove all .telemetry directories recursively from the project root
55-
echo "Searching for and removing all .telemetry directories..."
56-
find . -type d -name ".telemetry" -exec rm -rf {} +
120+
#find_and_remove_all_telemetry
121+
echo "Telemetry file regeneration complete."
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
description: >
2-
Couchbase instrumentation is owned upstream. This Couchbase instrumentation works by intercepting
3-
the constructor of the CoreEnvironment.Builder class. On construction, it automatically sets the
4-
Couchbase requestTracer to use an OpenTelemetryRequestTracer that wraps the agent's
5-
TracerProvider. This enables distributed tracing for Couchbase operations using OpenTelemetry,
6-
without requiring manual configuration by the user.
2+
Couchbase instrumentation is owned upstream. This Couchbase instrumentation manipulates the
3+
constructor of the CoreEnvironment.Builder class and sets the Couchbase requestTracer to use an
4+
OpenTelemetryRequestTracer that integrates with the OpenTelemetry agent.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
description: >
2-
Couchbase instrumentation is owned upstream. This instrumentation hooks into the
3-
CoreEnvironment.Builder constructor and automatically sets the Couchbase requestTracer to use an
4-
OpenTelemetry tracer from the agent. This enables distributed tracing for Couchbase operations
5-
using OpenTelemetry, without requiring manual configuration by the user.
2+
Couchbase instrumentation is owned upstream. This Couchbase instrumentation manipulates the
3+
constructor of the CoreEnvironment.Builder class and sets the Couchbase requestTracer to use an
4+
OpenTelemetryRequestTracer that integrates with the OpenTelemetry agent.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
description: >
2-
Couchbase instrumentation is owned upstream. This Couchbase instrumentation works by intercepting
3-
the constructor of the CoreEnvironment.Builder class. On construction, it automatically sets the
4-
Couchbase requestTracer to use an OpenTelemetryRequestTracer that wraps the agent's
5-
TracerProvider. This enables distributed tracing for Couchbase operations using OpenTelemetry,
6-
without requiring manual configuration by the user.
2+
Couchbase instrumentation is owned upstream. This Couchbase instrumentation manipulates the
3+
constructor of the CoreEnvironment.Builder class and sets the Couchbase requestTracer to use an
4+
OpenTelemetryRequestTracer that integrates with the OpenTelemetry agent.

0 commit comments

Comments
 (0)