コード例 #1
0
        public async Task TestDDBScanUnsuccessful()
#endif
        {
            var processor = new Mock <BaseProcessor <Activity> >();

            var parent = new Activity("parent").Start();

            using (Sdk.CreateTracerProviderBuilder()
                   .SetSampler(new AlwaysOnSampler())
                   .AddXRayTraceId()
                   .AddAWSInstrumentation()
                   .AddProcessor(processor.Object)
                   .Build())
            {
                var    ddb       = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);
                string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere";
                AmazonServiceException amazonServiceException = new AmazonServiceException();
                amazonServiceException.StatusCode = System.Net.HttpStatusCode.NotFound;
                amazonServiceException.RequestId  = requestId;
                CustomResponses.SetResponse(ddb, (request) => { throw amazonServiceException; });
                var scan_request = new ScanRequest();

                scan_request.TableName       = "SampleProduct";
                scan_request.AttributesToGet = new List <string>()
                {
                    "Id", "Name"
                };

                try
                {
#if NET452
                    ddb.Scan(scan_request);
#else
                    await ddb.ScanAsync(scan_request);
#endif
                }
                catch (AmazonServiceException)
                {
                    var count = processor.Invocations.Count;
                    Assert.Equal(3, count);

                    Activity awssdk_activity = (Activity)processor.Invocations[2].Arguments[0];

                    this.ValidateAWSActivity(awssdk_activity, parent);
                    this.ValidateDynamoActivityTags(awssdk_activity);

                    Assert.Equal(requestId, Utils.GetTagValue(awssdk_activity, "aws.requestId"));
                    Assert.Equal(Status.Error.WithDescription("Exception of type 'Amazon.Runtime.AmazonServiceException' was thrown."), awssdk_activity.GetStatus());
                    Assert.Equal("exception", awssdk_activity.Events.First().Name);
                }
            }
        }
コード例 #2
0
        public void TestDDBScanSuccessful()
        {
            var processor = new Mock <BaseProcessor <Activity> >();

            var parent = new Activity("parent").Start();

            using (Sdk.CreateTracerProviderBuilder()
                   .SetSampler(new AlwaysOnSampler())
                   .AddXRayTraceId()
                   .AddAWSInstrumentation()
                   .AddProcessor(processor.Object)
                   .Build())
            {
                var    ddb       = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);
                string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere";
                CustomResponses.SetResponse(ddb, null, requestId, true);
                var scan_request = new ScanRequest();

                scan_request.TableName       = "SampleProduct";
                scan_request.AttributesToGet = new List <string>()
                {
                    "Id", "Name"
                };
#if NET452
                ddb.Scan(scan_request);
#else
                ddb.ScanAsync(scan_request).Wait();
#endif
                var count = processor.Invocations.Count;

                Assert.Equal(3, count);

                Activity awssdk_activity = (Activity)processor.Invocations[2].Arguments[0];

                this.ValidateAWSActivity(awssdk_activity, parent);
                this.ValidateDynamoActivityTags(awssdk_activity);

                Assert.Equal(Status.Unset, awssdk_activity.GetStatus());
                Assert.Equal(requestId, Utils.GetTagValue(awssdk_activity, "aws.requestId"));
            }
        }
コード例 #3
0
        public void TestSQSSendMessageSuccessful()
        {
            var processor = new Mock <BaseProcessor <Activity> >();

            var parent = new Activity("parent").Start();

            using (Sdk.CreateTracerProviderBuilder()
                   .AddXRayTraceId()
                   .SetSampler(new AlwaysOnSampler())
                   .AddAWSInstrumentation()
                   .AddProcessor(processor.Object)
                   .Build())
            {
                var    sqs           = new AmazonSQSClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);
                string requestId     = @"fakerequ-esti-dfak-ereq-uestidfakere";
                string dummyResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                                       "<ReceiveMessageResponse>SomeDummyResponse</ReceiveMessageResponse>";
                CustomResponses.SetResponse(sqs, dummyResponse, requestId, true);
                var send_msg_req = new SendMessageRequest();
                send_msg_req.QueueUrl    = "https://sqs.us-east-1.amazonaws.com/123456789/MyTestQueue";
                send_msg_req.MessageBody = "Hello from OT";
#if NET452
                sqs.SendMessage(send_msg_req);
#else
                sqs.SendMessageAsync(send_msg_req).Wait();
#endif

                var count = processor.Invocations.Count;
                Assert.Equal(3, count);
                Activity awssdk_activity = (Activity)processor.Invocations[2].Arguments[0];

                this.ValidateAWSActivity(awssdk_activity, parent);
                this.ValidateSqsActivityTags(awssdk_activity);

                Assert.Equal(Status.Unset, awssdk_activity.GetStatus());
                Assert.Equal(requestId, Utils.GetTagValue(awssdk_activity, "aws.requestId"));
            }
        }