Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7h4ZNF4BDUpJk3Zou
145 lines
6.8 KiB
Bash
Executable File
145 lines
6.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regenerates every file in output/. Needs JDK 25, Maven 3.9, curl and network access to Maven Central.
|
|
# Timing-sensitive files (07, 08) will differ run to run; the span and metric files should not
|
|
# (apart from ordering of attributes and the exact lists noted in the post).
|
|
set -euo pipefail
|
|
source "$(dirname "$0")/lib.sh"
|
|
trap cleanup EXIT
|
|
mkdir -p "$OUT"
|
|
cd "$ROOT"
|
|
|
|
[ "${SKIP_BUILD:-0}" = 1 ] || build
|
|
# build() already made plain, micrometer and sink; the third variant adds the JDBC observation library
|
|
( cd "$ROOT" && mvn -B -q -DskipTests -Pmicrometer,jdbc -pl app package ) >/dev/null
|
|
cp "$ROOT/app/target/orders-micrometer-jdbc.jar" "$DIST/"
|
|
bash "$ROOT/scripts/restclient-missing.sh" >/dev/null
|
|
|
|
AGENT_METHODS='com.ankurm.otelcmp.PricingService[price];com.ankurm.otelcmp.AuditService[write]'
|
|
|
|
# snapshot <title> : print what the sink has received so far
|
|
snap() {
|
|
sleep 5
|
|
echo "== $1"; echo
|
|
echo "-- span tree (one line per span: name [kind, instrumentation scope])"
|
|
curl -s localhost:$SINK_PORT/spans
|
|
}
|
|
# traffic: warm the app, reset the sink, then send exactly the requests the transcript describes
|
|
traffic() {
|
|
curl -s -o /dev/null localhost:$APP_PORT/orders/1
|
|
sleep 8 # the Micrometer span exporter batches for 5 s; let the warm-up spans arrive, then discard them
|
|
curl -s -X POST localhost:$SINK_PORT/reset >/dev/null
|
|
curl -s -o /dev/null localhost:$APP_PORT/orders/1
|
|
curl -s -o /dev/null localhost:$APP_PORT/orders/1/audited
|
|
}
|
|
|
|
# ---- 01 agent --------------------------------------------------------------------------
|
|
start_sink
|
|
start_app plain "${AGENT_PROPS[@]}" -Dotel.instrumentation.methods.include="$AGENT_METHODS"
|
|
traffic
|
|
{
|
|
echo "# 01 OpenTelemetry Java agent 2.34.0 on the unmodified 'plain' jar (Spring Boot 4.2.0, JDK $(java -version 2>&1 | awk -F'"' '/version/{print $2}'))"
|
|
echo "# Requests sent after warm-up: GET /orders/1, then GET /orders/1/audited"
|
|
snap "spans"
|
|
echo; echo "-- attribute keys per span name"
|
|
curl -s localhost:$SINK_PORT/span-attrs
|
|
} > "$OUT/01-agent-spans.txt"
|
|
{
|
|
echo "# 09 What each approach puts in the Resource (who is this service?)"
|
|
echo "# Machine-specific attributes are left out: host.name, os.*, process.pid, process.executable.path,"
|
|
echo "# process.command_args and service.instance.id."
|
|
echo "== agent"; curl -s localhost:$SINK_PORT/resource | grep -v '^process.pid\|^service.instance.id\|^host.name\|^os\.\|^process.executable\|^process.command'
|
|
} > "$OUT/09-resource.txt"
|
|
curl -s localhost:$SINK_PORT/metrics > $TMPD/metrics-agent.txt
|
|
stop_app
|
|
|
|
# ---- 02 micrometer, default conventions -----------------------------------------------------
|
|
curl -s -X POST localhost:$SINK_PORT/reset >/dev/null
|
|
start_app micrometer "${MICROMETER_PROPS[@]}"
|
|
traffic
|
|
{
|
|
echo "# 02 Micrometer Tracing via spring-boot-starter-opentelemetry, Spring Boot 4.2.0, default conventions"
|
|
echo "# Requests sent after warm-up: GET /orders/1, then GET /orders/1/audited (audit.executor=raw)"
|
|
snap "spans"
|
|
echo; echo "-- attribute keys per span name"
|
|
curl -s localhost:$SINK_PORT/span-attrs
|
|
} > "$OUT/02-micrometer-spans.txt"
|
|
{ echo; echo "== micrometer"; curl -s localhost:$SINK_PORT/resource | grep -v '^service.instance.id'; } >> "$OUT/09-resource.txt"
|
|
curl -s localhost:$SINK_PORT/metrics > $TMPD/metrics-micrometer.txt
|
|
stop_app
|
|
|
|
# ---- 03 micrometer, OpenTelemetry conventions ------------------------------------------------------
|
|
curl -s -X POST localhost:$SINK_PORT/reset >/dev/null
|
|
start_app micrometer "${MICROMETER_PROPS[@]}" -Dmanagement.observations.conventions=opentelemetry
|
|
traffic
|
|
{
|
|
echo "# 03 Same Micrometer build with management.observations.conventions=opentelemetry (new in Spring Boot 4.2)"
|
|
snap "spans"
|
|
echo; echo "-- attribute keys per span name"
|
|
curl -s localhost:$SINK_PORT/span-attrs
|
|
sleep 1
|
|
echo; echo "-- HTTP metrics exported"
|
|
curl -s localhost:$SINK_PORT/metrics | grep -E '^scope|http\.' | grep -E 'http\.|^scope' | grep -B1 'http\.' | grep -v '^--'
|
|
} > "$OUT/03-micrometer-otel-conventions.txt"
|
|
curl -s localhost:$SINK_PORT/metrics > $TMPD/metrics-micrometer-otelconv.txt
|
|
stop_app
|
|
|
|
# ---- 04 metrics side by side -----------------------------------------------------------------
|
|
{
|
|
echo "# 04 Metrics received over OTLP, grouped by the instrumentation scope that produced them"
|
|
echo; echo "######## agent"; cat $TMPD/metrics-agent.txt
|
|
echo; echo "######## micrometer (default conventions)"; cat $TMPD/metrics-micrometer.txt
|
|
} > "$OUT/04-metrics.txt"
|
|
|
|
# ---- 05 thread hand-off -------------------------------------------------------------------------
|
|
{
|
|
echo "# 05 Work handed to another thread (GET /orders/1/audited submits AuditService.write to a pool)"
|
|
echo "# One trace is expected: SERVER span with audit.write below it. Count the traces."
|
|
for cfg in "agent|plain|raw" "micrometer|micrometer|raw" "micrometer|micrometer|spring"; do
|
|
IFS='|' read -r kind jar ex <<<"$cfg"
|
|
curl -s -X POST localhost:$SINK_PORT/reset >/dev/null
|
|
if [ "$kind" = agent ]; then
|
|
start_app plain "${AGENT_PROPS[@]}" -Dotel.instrumentation.methods.include="$AGENT_METHODS" -Daudit.executor=$ex
|
|
else
|
|
start_app micrometer "${MICROMETER_PROPS[@]}" -Daudit.executor=$ex
|
|
fi
|
|
curl -s -o /dev/null localhost:$APP_PORT/orders/1/audited
|
|
sleep 8; curl -s -X POST localhost:$SINK_PORT/reset >/dev/null
|
|
curl -s -o /dev/null localhost:$APP_PORT/orders/1/audited
|
|
sleep 5
|
|
echo; echo "== $kind, audit.executor=$ex"
|
|
curl -s localhost:$SINK_PORT/spans
|
|
stop_app
|
|
done
|
|
} > "$OUT/05-thread-handoff.txt"
|
|
|
|
# ---- 06 JDBC gap ---------------------------------------------------------------------------
|
|
curl -s -X POST localhost:$SINK_PORT/reset >/dev/null
|
|
start_app micrometer-jdbc "${MICROMETER_PROPS[@]}"
|
|
traffic
|
|
{
|
|
echo "# 06 Micrometer build plus net.ttddyy.observation:datasource-micrometer-spring-boot 2.3.1 (third-party)"
|
|
snap "spans"
|
|
echo; echo "-- attribute keys per span name"
|
|
curl -s localhost:$SINK_PORT/span-attrs | grep -A1 'connection\|query\|result-set'
|
|
} > "$OUT/06-micrometer-jdbc.txt"
|
|
stop_app
|
|
|
|
# ---- 07 both at once ------------------------------------------------------------------------
|
|
curl -s -X POST localhost:$SINK_PORT/reset >/dev/null
|
|
start_app micrometer "${MICROMETER_PROPS[@]}" -Dotel.service.name=orders "${AGENT_PROPS[@]}"
|
|
traffic
|
|
{
|
|
echo "# 07 Micrometer build AND the agent in the same JVM, both exporting to the same sink"
|
|
snap "spans"
|
|
echo; echo "-- attribute keys per span name"
|
|
curl -s localhost:$SINK_PORT/span-attrs
|
|
echo; echo "-- url.full of the lone POST client spans"
|
|
curl -s "localhost:$SINK_PORT/span-values?name=POST&key=url.full"
|
|
echo; echo "-- HTTP server metrics received (scope, name)"
|
|
curl -s localhost:$SINK_PORT/metrics | grep -E '^scope|http\.server' | grep -B1 'http\.server' | grep -v '^--'
|
|
} > "$OUT/07-both-at-once.txt"
|
|
stop_app
|
|
stop_sink
|
|
[ "${SKIP_OVERHEAD:-0}" = 1 ] || source "$(dirname "$0")/overhead.sh"
|
|
echo "functional outputs written to $OUT"
|