Skip to content

Commit 294bf25

Browse files
author
Michael Wunderlich
committed
basic X-Ray integration
1 parent 713ee9c commit 294bf25

File tree

10 files changed

+97
-4
lines changed

10 files changed

+97
-4
lines changed

.ebextensions/xray.config

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
commands:
2+
01-stop-tracing:
3+
command: yum remove -y xray
4+
ignoreErrors: true
5+
02-copy-tracing:
6+
command: curl https://s3.amazonaws.com/aws-xray-assets.us-east-1/xray-daemon/aws-xray-daemon-1.x.rpm -o /home/ec2-user/xray.rpm
7+
03-start-tracing:
8+
command: yum install -y /home/ec2-user/xray.rpm
9+
10+
files:
11+
"/opt/elasticbeanstalk/tasks/taillogs.d/xray-daemon.conf" :
12+
mode: "000644"
13+
owner: root
14+
group: root
15+
content: |
16+
/var/log/xray/xray.log
17+
"/etc/amazon/xray/cfg.yaml" :
18+
mode: "000644"
19+
owner: root
20+
group: root
21+
content: |
22+
Logging:
23+
LogLevel: "warn"

Buildfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
build: gradle build
1+
01build: gradle build

bin/full-traces.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
EPOCH=$(date +%s)
2+
echo "epoch is $EPOCH"
3+
TRACEIDS=$(aws xray get-trace-summaries --start-time $(($EPOCH-120)) --end-time $(($EPOCH-60)) --query 'TraceSummaries[*].Id' --output text | cut -c 1-180)
4+
aws xray batch-get-traces --trace-ids $TRACEIDS --query 'Traces[*]'

bin/put-trace-segments.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aws xray put-trace-segments --trace-segment-documents "{\"id\":\"20312a0e2b8809f4\",\"name\":\"DynamoDB\",\"trace_id\":\"1-5832862d-a43aafded3334a971fe312db\",\"start_time\":1.479706157195E9,\"end_time\":1.479706157202E9,\"parent_id\":\"79736b962fe3239e\",\"http\":{\"response\":{\"content_length\":60,\"status\":200}},\"inferred\":true,\"aws\":{\"consistent_read\":false,\"table_name\":\"scorekeep-session-xray\",\"operation\":\"GetItem\",\"request_id\":\"SCAU23OM6M8FO38UASGC7785ARVV4KQNSO5AEMVJF66Q9ASUAAJG\",\"resource_names\":[\"scorekeep-session-xray\"]},\"origin\":\"AWS::DynamoDB::Table\"}"

bin/service-graph.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
EPOCH=$(date +%s)
2+
echo "epoch is $EPOCH"
3+
aws xray get-service-graph --start-time $(($EPOCH-600)) --end-time $EPOCH

bin/trace-summaries.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
EPOCH=$(date +%s)
2+
echo "epoch is $EPOCH"
3+
aws xray get-trace-summaries --start-time $(($EPOCH-120)) --end-time $(($EPOCH-60))
4+

bin/trace-urls.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
EPOCH=$(date +%s)
2+
echo "epoch is $EPOCH"
3+
aws xray get-trace-summaries --start-time $(($EPOCH-120)) --end-time $(($EPOCH-60)) --query 'TraceSummaries[*].Http.HttpURL'

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ dependencies {
3030
compile("org.springframework.boot:spring-boot-starter-web")
3131
testCompile("org.springframework.boot:spring-boot-starter-test")
3232
compile("com.amazonaws:aws-java-sdk-dynamodb")
33+
compile("com.amazonaws:aws-xray-recorder-sdk-core")
34+
compile("com.amazonaws:aws-xray-recorder-sdk-aws-sdk")
35+
compile("com.amazonaws:aws-xray-recorder-sdk-aws-sdk-instrumentor")
3336
testCompile("junit:junit:4.11")
3437
compile("com.fasterxml.jackson.core:jackson-databind:2.8.4")
38+
compile("commons-validator:commons-validator:1.5.1")
3539
}
3640

3741
dependencyManagement {
3842
imports {
39-
mavenBom("com.amazonaws:aws-java-sdk-bom:1.11.39")
43+
mavenBom("com.amazonaws:aws-java-sdk-bom:1.11.52")
44+
mavenBom("com.amazonaws:aws-xray-recorder-sdk-bom:1.0.0-beta")
4045
}
4146
}
4247
task wrapper(type: Wrapper) {
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
package scorekeep;
2-
import org.springframework.context.annotation.Configuration;
2+
3+
import com.amazonaws.xray.AWSXRay;
4+
import com.amazonaws.xray.AWSXRayRecorderBuilder;
5+
import com.amazonaws.xray.javax.servlet.AWSXRayServletFilter;
6+
import com.amazonaws.xray.plugins.EC2Plugin;
7+
import com.amazonaws.xray.strategy.sampling.DefaultSamplingStrategy;
38
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
411
import javax.servlet.Filter;
12+
import java.net.URL;
513

614
@Configuration
715
public class WebConfig {
816

17+
@Bean
18+
public Filter TracingFilter() {
19+
return new AWSXRayServletFilter();
20+
}
21+
922
@Bean
1023
public Filter SimpleCORSFilter() {
1124
return new SimpleCORSFilter();
1225
}
13-
}
26+
27+
static {
28+
AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard().withPlugin(new EC2Plugin());
29+
30+
URL ruleFile = WebConfig.class.getResource("/sampling-rules.json");
31+
builder.withSamplingStrategy(new DefaultSamplingStrategy(ruleFile));
32+
33+
AWSXRay.setGlobalRecorder(builder.build());
34+
}
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"rules": {
3+
"user": {
4+
"id": 1,
5+
"service_name": "*",
6+
"http_method": "POST",
7+
"url_path": "/api/user",
8+
"fixed_target": 10,
9+
"rate": 1.0
10+
},
11+
"move": {
12+
"id": 2,
13+
"service_name": "*",
14+
"http_method": "*",
15+
"url_path": "/api/move/*",
16+
"fixed_target": 1,
17+
"rate": 0.05
18+
},
19+
"base": {
20+
"id": 3,
21+
"service_name": "*",
22+
"http_method": "*",
23+
"url_path": "*",
24+
"fixed_target": 10,
25+
"rate": 0.25
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)