Debashish
Debashish

Reputation: 43

X ray trace not appearing from ec2, getting exceptions

I am writing a code which will run in a ec2 and list the buckets in s3 for my account.Code is working fine. However, when I try to instrument x-ray into it the x-ray traces are not coming. I have included the x-ray dependencies in the pom.xml

I tried a number of methods like introduction of the Config, but it didn't work.

Someone having a sample code will be helpful as there is not many resource regarding it and AWS official sample project is not very clear.

@Configuration
public class WebConfig {

    @Bean
    public Filter TracingFilter() {
        return new AWSXRayServletFilter(new DynamicSegmentNamingStrategy("MyApp", "*"));
    }
}


@RestController
public class HelloController {

    @RequestMapping("/")
    public String index() throws IOException{
        test();
        return "Greetings from Spring Boot!";
    }

    public static void test() throws IOException {
        final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
        List<Bucket> buckets = s3.listBuckets();
        System.out.println("Your Amazon S3 buckets are:");
        for (Bucket b : buckets) {
            System.out.println("* " + b.getName());
        }
    }
}

Getting the following exception

2019-04-27 10:46:28.706 ERROR 3865 --- [pool-1-thread-1] c.a.x.s.sampling.pollers.RulePoller : Encountered error polling GetSamplingRules:

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to 127.0.0.1:2000 [/127.0.0.1] failed: Connection refused (Connection refused) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1163) ~[aws-java-sdk-core-1.11.430.jar!/:na]

Upvotes: 1

Views: 1960

Answers (1)

Imran
Imran

Reputation: 6265

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to 127.0.0.1:2000

It looks like X-Ray Daemon is not running the EC2 instance where your app is running.

Your App on EC2 --> X-Ray Daemon on EC2 --> AWS X-Ray API

Try spinning up X-Ray Daemon(listens on default 2000 port) first before your app and see logs are propagating.

https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-ec2.html

Upvotes: 1

Related Questions