Skip to content

Commit 9187ceb

Browse files
committed
convert validation app to flask app
1 parent 1f4ef80 commit 9187ceb

File tree

2 files changed

+55
-52
lines changed

2 files changed

+55
-52
lines changed

.github/workflows/release-udp-exporter.yml

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,37 @@ jobs:
3131
working-directory: exporters/aws-otel-otlp-udp-exporter
3232
run: hatch build
3333

34-
- name: Setup X-Ray daemon
35-
run: |
36-
# Download X-Ray daemon
37-
wget https://s3.us-east-2.amazonaws.com/aws-xray-assets.us-east-2/xray-daemon/aws-xray-daemon-linux-3.x.zip
38-
unzip -o aws-xray-daemon-linux-3.x.zip
39-
40-
# Create config file
41-
echo '{
42-
"Version": 2,
43-
"TotalBufferSizeMB": 10,
44-
"Logging": {
45-
"LogLevel": "debug"
46-
},
47-
}' > xray-daemon-config.json
34+
# TODO: Add unit tests step
4835

49-
# Make sure xray is executable
50-
chmod +x ./xray
51-
52-
# Create logs directory
53-
mkdir -p daemon-logs
54-
55-
# Start X-Ray daemon
56-
./xray -o -n us-west-2 -c xray-daemon-config.json > daemon-logs/xray-daemon.log 2>&1 &
57-
XRAY_PID=$!
58-
echo "X-Ray daemon started with PID $XRAY_PID"
59-
60-
# Wait for daemon to be ready
61-
echo "Waiting for X-Ray daemon to start..."
62-
sleep 5
63-
64-
echo "X-Ray daemon setup completed"
36+
- name: Download and run X-Ray Daemon
37+
run: |
38+
mkdir xray-daemon
39+
cd xray-daemon
40+
wget https://s3.us-west-2.amazonaws.com/aws-xray-assets.us-west-2/xray-daemon/aws-xray-daemon-linux-3.x.zip
41+
unzip aws-xray-daemon-linux-3.x.zip
42+
./xray -o -n us-west-2 -f ./daemon-logs.log --log-level debug &
6543
66-
- name: Setup validation app
44+
- name: Install UDP Exporter
6745
run: |
6846
pip install ./exporters/aws-otel-otlp-udp-exporter/dist/*.whl
6947
70-
- name: Run validation test
48+
- name: Run Sample App in Background
7149
working-directory: sample-applications/integ-test-app
72-
run: python udp_exporter_validation_app.py
50+
run: |
51+
# Start validation app
52+
python udp_exporter_validation_app.py &
53+
# Wait for validation app to initialize
54+
sleep 5
55+
56+
-name: Call Sample App Endpoint
57+
# Trigger trace generation
58+
echo "traceId=$(curl localhost:8080/test)" >> $GITHUB_OUTPUT
59+
echo $traceId
60+
61+
- name: Print Daemon Logs
62+
run: |
63+
sleep 20
64+
cat xray-daemon/daemon-logs.log
7365
7466
- name: Verify X-Ray daemon received traces
7567
run: |
Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import socket
22
import threading
33
import time
4+
from flask import Flask, jsonify
45

56
from amazon.opentelemetry.exporters.otlp.udp import OTLPUdpSpanExporter
67
from opentelemetry import trace
78
from opentelemetry.sdk.trace import TracerProvider
89
from opentelemetry.sdk.trace.export import BatchSpanProcessor
910

11+
app = Flask(__name__)
1012

1113
# Set up tracer provider
1214
tracer_provider = TracerProvider()
@@ -17,24 +19,33 @@
1719
span_processor = BatchSpanProcessor(exporter)
1820
tracer_provider.add_span_processor(span_processor)
1921

20-
# Create a span for testing with various attributes
22+
# Get tracer
2123
tracer = trace.get_tracer(__name__)
22-
with tracer.start_as_current_span("test_parent_span") as parent:
23-
parent.set_attribute("service.name", "validation-app")
24-
parent.set_attribute("test.attribute", "test_value")
25-
parent.add_event("test-event", {"event.data": "some data"})
2624

27-
# Add a child span
28-
with tracer.start_as_current_span("test_child_span") as child:
29-
child.set_attribute("child.attribute", "child_value")
30-
print("Created spans with attributes and events")
31-
32-
# Force flush to ensure spans are exported immediately
33-
success = tracer_provider.force_flush()
34-
print(f"Force flush {'succeeded' if success else 'failed'}")
35-
36-
# Give some time for the UDP packet to be processed
37-
time.sleep(2)
38-
39-
# Shutdown
40-
tracer_provider.shutdown()
25+
@app.route('/trace', methods=['GET'])
26+
def create_trace():
27+
# Create a span for testing with various attributes
28+
tracer = trace.get_tracer(__name__)
29+
with tracer.start_as_current_span("test_parent_span") as parent:
30+
parent.set_attribute("service.name", "validation-app")
31+
parent.set_attribute("test.attribute", "test_value")
32+
parent.add_event("test-event", {"event.data": "some data"})
33+
34+
# Get the trace ID
35+
trace_id = format(parent.get_span_context().trace_id, '032x')
36+
37+
# Add a child span
38+
with tracer.start_as_current_span("test_child_span") as child:
39+
child.set_attribute("child.attribute", "child_value")
40+
print("Created spans with attributes and events")
41+
42+
# Force flush to ensure spans are exported immediately
43+
success = tracer_provider.force_flush()
44+
print(f"Force flush {'succeeded' if success else 'failed'}")
45+
46+
return jsonify({
47+
"trace_id": trace_id
48+
})
49+
50+
if __name__ == '__main__':
51+
app.run(port=8080)

0 commit comments

Comments
 (0)