Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
da7b4a7
Initial tracing code
sailalithkanumuri8 Jul 21, 2025
f530d61
Fix tracing and Docker integration for advanced coffee machine with J…
sailalithkanumuri8 Jul 21, 2025
6093f1e
fix: ran npm run format
sailalithkanumuri8 Jul 22, 2025
8034db9
Updated README
sailalithkanumuri8 Jul 24, 2025
4053ee7
Modified tracing to include input values
sailalithkanumuri8 Jul 29, 2025
340ac8c
Refactored tracing.ts code
sailalithkanumuri8 Jul 30, 2025
b211687
Updated tracing code
sailalithkanumuri8 Jul 30, 2025
6b9d238
Fixed merge conflict errors
sailalithkanumuri8 Aug 4, 2025
24c09d8
fix: ran npm format
sailalithkanumuri8 Aug 4, 2025
6e57e3d
Added spans for properties and events
sailalithkanumuri8 Aug 5, 2025
72c077f
fix: ran npm run format
sailalithkanumuri8 Aug 5, 2025
4e7b3e6
Merge remote-tracking branch 'upstream/main' into sai-opentelemetry-i…
sailalithkanumuri8 Aug 6, 2025
0db157e
fix: ran npm run format again
sailalithkanumuri8 Aug 6, 2025
97280dc
Enhanced OpenTelemetry tracing
sailalithkanumuri8 Aug 8, 2025
40bd75d
refactor: remove low-level complexity and simplify OpenTelemetry trac…
sailalithkanumuri8 Aug 8, 2025
2e4284e
Added test file
sailalithkanumuri8 Aug 8, 2025
d4ecd0e
fix: ran npm run format
sailalithkanumuri8 Aug 8, 2025
0ec0d83
Fix Jaeger tracing configuration spans still not showing up
sailalithkanumuri8 Aug 11, 2025
a5e7996
Added more spans
sailalithkanumuri8 Aug 11, 2025
d2f4717
Merge remote-tracking branch 'origin/sai-opentelemetry-integration' i…
sailalithkanumuri8 Aug 11, 2025
740e6cd
fix: ran npm run format
sailalithkanumuri8 Aug 11, 2025
d404f88
update lock file
egekorkan Aug 12, 2025
40e84ae
Merge branch 'main' of github.com:eclipse-thingweb/test-things into s…
egekorkan Aug 12, 2025
f879825
Decreased redundancy to help developers code things faster
sailalithkanumuri8 Aug 19, 2025
680f320
fix: fixed jeager endpoint in docker-compose-things
sailalithkanumuri8 Aug 19, 2025
3cb0171
Removed unnecessary method
sailalithkanumuri8 Aug 19, 2025
f12f179
fix: hopefully fixed lint errors
sailalithkanumuri8 Aug 19, 2025
99f5db5
Fixed dependancy mismatch
sailalithkanumuri8 Aug 19, 2025
e69c3e7
Fixed hardcoded jeager endpoint
sailalithkanumuri8 Aug 19, 2025
71d984f
Updated paths to make tracing in util
sailalithkanumuri8 Aug 26, 2025
780c899
Fixed counter thing
sailalithkanumuri8 Aug 26, 2025
7053292
Updated loc file
sailalithkanumuri8 Aug 26, 2025
ff10f89
Reduced redundancy in main.ts
sailalithkanumuri8 Aug 27, 2025
d43998d
Updated README
sailalithkanumuri8 Aug 27, 2025
4d94a97
Ran npm run format
sailalithkanumuri8 Aug 27, 2025
9a7e000
Updated schema fetching in util.ts
sailalithkanumuri8 Aug 29, 2025
a43fb54
Made span name handling easier for developer
sailalithkanumuri8 Sep 1, 2025
13161c8
Updated span names and added more info on readme
sailalithkanumuri8 Sep 1, 2025
68cb5d4
Updated README
sailalithkanumuri8 Sep 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ COAP_SIMPLE_PORT_OUT=5683
COAP_NEGOTIATION_PORT_OUT=5684
SMART_HOME_SMART_CLOCK_PORT_OUT=5685
TRAEFIK_DASHBOARD_PORT_OUT=8080
JAEGER_ENDPOINT=http://host.docker.internal:8085/api/traces

STACK_HOSTNAME="plugfest.thingweb.io"
BROKER_URI="plugfest.thingweb.io"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,7 @@ docker buildx build \
For running the things separately, using their `Dockerfile`'s, `docker build -t <image-tag> -f ./Dockerfile ../../` command must be used to give the context to be able to copy `tm.json` into the container.

For Node.js-based devices, we use npm workspaces and running `npm install` at the root directory installs all the packages needed for every device. After packages are installed, running `node main.js` would run the thing. For port configuration, running either `node main.js -p 1000` or `node main.js --port 1000` would start the thing on port 1000.

## Tracing

Distributed tracing is enabled using OpenTelemetry and Jaeger. To view all traces and logs, open [http://localhost:8084](http://localhost:8084) in your browser (Jaeger UI). Traces are sent to the Jaeger collector on port 14268.
1 change: 1 addition & 0 deletions docker-compose-things-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ services:
environment:
- HOSTNAME=${STACK_HOSTNAME}
- PORT=${WEB_PORT_OUT}
- JAEGER_ENDPOINT=${JAEGER_ENDPOINT}
networks:
- things_network
http-data-schema-thing:
Expand Down
1 change: 1 addition & 0 deletions docker-compose-things.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ services:
environment:
- HOSTNAME=${STACK_HOSTNAME}
- PORT=${WEB_PORT_OUT}
- JAEGER_ENDPOINT=${JAEGER_ENDPOINT}
deploy:
resources:
limits:
Expand Down
3,333 changes: 2,540 additions & 793 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-notice": "^1.0.0",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-unused-imports": "^4.1.4",
"eslint-plugin-workspaces": "^0.10.1",
"mocha": "^10.7.3",
Expand Down
186 changes: 186 additions & 0 deletions tests/test-enhanced-tracing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#!/bin/bash

# Test script for Enhanced OpenTelemetry Tracing
# This script demonstrates the full-stack tracing capabilities

echo "🚀 Testing Enhanced OpenTelemetry Tracing for Advanced Coffee Machine"
echo "=================================================="

# Configuration
COFFEE_MACHINE_URL="http://localhost/http-advanced-coffee-machine"
JAEGER_URL="http://jaeger.localhost"


echo "📋 Prerequisites:"
echo " - Coffee machine should be running on port 80 (via Docker/proxy)"
echo " - Jaeger should be running on port 8084 (UI) and 14268 (collector)"
echo " - View traces at: $JAEGER_URL"
echo ""

sleep 2

echo "🧪 Test 0: Reset Resources (prepare for testing)"
echo "----------------------------------------"
curl -X PUT "$COFFEE_MACHINE_URL/properties/availableResourceLevel?id=water" \
-H 'Content-Type: application/json' \
-d '100' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

curl -X PUT "$COFFEE_MACHINE_URL/properties/availableResourceLevel?id=milk" \
-H 'Content-Type: application/json' \
-d '100' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

curl -X PUT "$COFFEE_MACHINE_URL/properties/availableResourceLevel?id=chocolate" \
-H 'Content-Type: application/json' \
-d '100' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

curl -X PUT "$COFFEE_MACHINE_URL/properties/availableResourceLevel?id=coffeeBeans" \
-H 'Content-Type: application/json' \
-d '100' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 1: Make a Latte (should show full nested trace)"
echo "----------------------------------------"
curl -X POST "$COFFEE_MACHINE_URL/actions/makeDrink?drinkId=latte&size=l&quantity=1" \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 2: Make an Espresso (smaller trace)"
echo "----------------------------------------"
curl -X POST "$COFFEE_MACHINE_URL/actions/makeDrink?drinkId=espresso&size=s&quantity=2" \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 3: Set a Valid Schedule (should show full nested trace)"
echo "----------------------------------------"
curl -X POST "$COFFEE_MACHINE_URL/actions/setSchedule" \
-H 'Content-Type: application/json' \
-d '{"time":"08:00","mode":"everyday","drinkId":"latte","size":"l","quantity":2}' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 4: Invalid Schedule (should show error trace)"
echo "----------------------------------------"
curl -X POST "$COFFEE_MACHINE_URL/actions/setSchedule" \
-H 'Content-Type: application/json' \
-d '{"time":"25:99","mode":"everyday"}' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 5: Check Resources (property read trace)"
echo "----------------------------------------"
curl -X GET "$COFFEE_MACHINE_URL/properties/allAvailableResources" \
-H 'Accept: application/json' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 6: Check Possible Drinks (property read trace)"
echo "----------------------------------------"
curl -X GET "$COFFEE_MACHINE_URL/properties/possibleDrinks" \
-H 'Accept: application/json' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 7: Update Resource Level (property write trace)"
echo "----------------------------------------"
curl -X PUT "$COFFEE_MACHINE_URL/properties/availableResourceLevel?id=water" \
-H 'Content-Type: application/json' \
-d '50' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 8: Update Served Counter (property write trace)"
echo "----------------------------------------"
curl -X PUT "$COFFEE_MACHINE_URL/properties/servedCounter" \
-H 'Content-Type: application/json' \
-d '1001' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 9: Check Schedules (property read trace)"
echo "----------------------------------------"
curl -X GET "$COFFEE_MACHINE_URL/properties/schedules" \
-H 'Accept: application/json' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 10: Trigger Low Resource Event - Set Water to 5% (event trace)"
echo "----------------------------------------"
curl -X PUT "$COFFEE_MACHINE_URL/properties/availableResourceLevel?id=water" \
-H 'Content-Type: application/json' \
-d '5' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 11: Trigger Out of Resource Event - Set Coffee Beans to 0% (event trace)"
echo "----------------------------------------"
curl -X PUT "$COFFEE_MACHINE_URL/properties/availableResourceLevel?id=coffeeBeans" \
-H 'Content-Type: application/json' \
-d '0' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 12: Try Making Drink with No Coffee Beans (should trigger outOfResource event)"
echo "----------------------------------------"
curl -X POST "$COFFEE_MACHINE_URL/actions/makeDrink?drinkId=espresso&size=m&quantity=1" \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 13: Set High Served Counter to Trigger Maintenance Event (event trace)"
echo "----------------------------------------"
curl -X PUT "$COFFEE_MACHINE_URL/properties/servedCounter" \
-H 'Content-Type: application/json' \
-d '1500' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

sleep 1

echo "🧪 Test 14: Check Maintenance Status After High Counter (property read trace)"
echo "----------------------------------------"
curl -X GET "$COFFEE_MACHINE_URL/properties/maintenanceNeeded" \
-H 'Accept: application/json' \
-w "\nStatus: %{http_code}\nTime: %{time_total}s\n\n"

echo "✅ All tests completed!"
echo ""
echo "🔍 To view the enhanced traces:"
echo " 1. Open Jaeger UI: $JAEGER_URL"
echo " 2. Select service: 'advanced-coffee-machine'"
echo " 3. Click 'Find Traces'"
echo " 4. Click on any trace to see the nested span structure"
echo ""
echo "📊 You should see traces with:"
echo " • HTTP request spans (auto-instrumented)"
echo " • property.read.* spans for GET requests with nested business logic"
echo " • property.write.* spans for PUT requests with validation and events"
echo " • action.* spans for POST requests with complex workflows"
echo " • event.* spans for outOfResource and maintenanceNeeded events"
echo " • Nested business logic, validation, and calculation spans"
echo " • Database operation spans (db.select, db.update, db.insert)"
echo " • Hardware simulation spans (sensors, drink preparation)"
echo " • Rich metadata and contextual attributes"
echo " • Error details and validation failures"
echo ""
echo "🎯 Event Testing Scenarios:"
echo " • Low resource alerts (water at 5%)"
echo " • Out of resource events (coffee beans at 0%)"
echo " • Maintenance threshold events (served counter > 1000)"
echo " • Failed drink attempts triggering resource events"
echo ""
echo "🚀 This comprehensive test covers ALL WoT interaction types with full-stack tracing!"
2 changes: 1 addition & 1 deletion things/advanced-coffee-machine/http/ts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /app
COPY ./advanced-coffee-machine.tm.json .
COPY ./http/ts .

RUN npm install
RUN npm install --legacy-peer-deps

RUN npm run build

Expand Down
7 changes: 6 additions & 1 deletion things/advanced-coffee-machine/http/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
"@node-wot/core": "0.8.16",
"dotenv": "^16.4.5",
"json-placeholder-replacer": "^2.0.5",
"wot-typescript-definitions": "0.8.0-SNAPSHOT.29"
"wot-typescript-definitions": "0.8.0-SNAPSHOT.29",
"@opentelemetry/api": "1.9.0",
"@opentelemetry/sdk-trace-node": "1.9.0",
"@opentelemetry/exporter-jaeger": "1.9.0",
"@opentelemetry/resources": "1.9.0",
"@opentelemetry/semantic-conventions": "1.9.0"
},
"devDependencies": {
"@types/node": "^22.1.0",
Expand Down
Loading
Loading