| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  | import boto3 | 
					
						
							|  |  |  | import json | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | from moto import mock_xray | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import datetime | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_xray | 
					
						
							|  |  |  | def test_put_telemetry(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("xray", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_telemetry_records( | 
					
						
							|  |  |  |         TelemetryRecords=[ | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Timestamp": datetime.datetime(2015, 1, 1), | 
					
						
							|  |  |  |                 "SegmentsReceivedCount": 123, | 
					
						
							|  |  |  |                 "SegmentsSentCount": 123, | 
					
						
							|  |  |  |                 "SegmentsSpilloverCount": 123, | 
					
						
							|  |  |  |                 "SegmentsRejectedCount": 123, | 
					
						
							|  |  |  |                 "BackendConnectionErrors": { | 
					
						
							|  |  |  |                     "TimeoutCount": 123, | 
					
						
							|  |  |  |                     "ConnectionRefusedCount": 123, | 
					
						
							|  |  |  |                     "HTTPCode4XXCount": 123, | 
					
						
							|  |  |  |                     "HTTPCode5XXCount": 123, | 
					
						
							|  |  |  |                     "UnknownHostCount": 123, | 
					
						
							|  |  |  |                     "OtherCount": 123, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  |         ], | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         EC2InstanceId="string", | 
					
						
							|  |  |  |         Hostname="string", | 
					
						
							|  |  |  |         ResourceARN="string", | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_xray | 
					
						
							|  |  |  | def test_put_trace_segments(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("xray", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_trace_segments( | 
					
						
							|  |  |  |         TraceSegmentDocuments=[ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             json.dumps( | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "name": "example.com", | 
					
						
							|  |  |  |                     "id": "70de5b6f19ff9a0a", | 
					
						
							|  |  |  |                     "start_time": 1.478293361271e9, | 
					
						
							|  |  |  |                     "trace_id": "1-581cf771-a006649127e371903a2de979", | 
					
						
							|  |  |  |                     "end_time": 1.478293361449e9, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_xray | 
					
						
							|  |  |  | def test_trace_summary(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("xray", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_trace_segments( | 
					
						
							|  |  |  |         TraceSegmentDocuments=[ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             json.dumps( | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "name": "example.com", | 
					
						
							|  |  |  |                     "id": "70de5b6f19ff9a0a", | 
					
						
							|  |  |  |                     "start_time": 1.478293361271e9, | 
					
						
							|  |  |  |                     "trace_id": "1-581cf771-a006649127e371903a2de979", | 
					
						
							|  |  |  |                     "in_progress": True, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             json.dumps( | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "name": "example.com", | 
					
						
							|  |  |  |                     "id": "70de5b6f19ff9a0b", | 
					
						
							|  |  |  |                     "start_time": 1478293365, | 
					
						
							|  |  |  |                     "trace_id": "1-581cf771-a006649127e371903a2de979", | 
					
						
							|  |  |  |                     "end_time": 1478293385, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.get_trace_summaries( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         StartTime=datetime.datetime(2014, 1, 1), EndTime=datetime.datetime(2017, 1, 1) | 
					
						
							| 
									
										
										
										
											2017-09-22 23:36:26 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_xray | 
					
						
							|  |  |  | def test_batch_get_trace(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("xray", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.put_trace_segments( | 
					
						
							|  |  |  |         TraceSegmentDocuments=[ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             json.dumps( | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "name": "example.com", | 
					
						
							|  |  |  |                     "id": "70de5b6f19ff9a0a", | 
					
						
							|  |  |  |                     "start_time": 1.478293361271e9, | 
					
						
							|  |  |  |                     "trace_id": "1-581cf771-a006649127e371903a2de979", | 
					
						
							|  |  |  |                     "in_progress": True, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             json.dumps( | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     "name": "example.com", | 
					
						
							|  |  |  |                     "id": "70de5b6f19ff9a0b", | 
					
						
							|  |  |  |                     "start_time": 1478293365, | 
					
						
							|  |  |  |                     "trace_id": "1-581cf771-a006649127e371903a2de979", | 
					
						
							|  |  |  |                     "end_time": 1478293385, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = client.batch_get_traces( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         TraceIds=[ | 
					
						
							|  |  |  |             "1-581cf771-a006649127e371903a2de979", | 
					
						
							|  |  |  |             "1-581cf772-b006649127e371903a2de979", | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(resp["UnprocessedTraceIds"]).should.equal(1) | 
					
						
							|  |  |  |     len(resp["Traces"]).should.equal(1) | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Following are not implemented, just testing it returns what boto expects | 
					
						
							|  |  |  | @mock_xray | 
					
						
							|  |  |  | def test_batch_get_service_graph(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("xray", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.get_service_graph( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         StartTime=datetime.datetime(2014, 1, 1), EndTime=datetime.datetime(2017, 1, 1) | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_xray | 
					
						
							|  |  |  | def test_batch_get_trace_graph(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("xray", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.batch_get_traces( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         TraceIds=[ | 
					
						
							|  |  |  |             "1-581cf771-a006649127e371903a2de979", | 
					
						
							|  |  |  |             "1-581cf772-b006649127e371903a2de979", | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2017-09-23 11:02:25 +01:00
										 |  |  |     ) |