def decompose_args(method, url, body, headers, encode_chunked=False): # skip httplib tracing for SDK built-in centralized sampling pollers if (('/GetSamplingRules' in args or '/SamplingTargets' in args) and type(instance).__name__ == 'botocore.awsrequest.AWSHTTPConnection'): return wrapped(*args, **kwargs) # Only injects headers when the subsegment for the outgoing # calls are opened successfully. subsegment = None try: subsegment = xray_recorder.current_subsegment() except SegmentNotFoundException: pass if subsegment: inject_trace_header(headers, subsegment) ssl_cxt = getattr(instance, '_context', None) scheme = 'https' if ssl_cxt and type( ssl_cxt).__name__ == 'SSLContext' else 'http' xray_url = '{}://{}{}'.format(scheme, instance.host, url) xray_data = _XRay_Data(method, instance.host, xray_url) setattr(instance, _XRAY_PROP, xray_data) # we add a segment here in case connect fails return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=strip_url(xray_data.url), namespace='remote', meta_processor=http_send_request_processor)
def _xray_traced_botocore(wrapped, instance, args, kwargs): service = instance._service_model.metadata["endpointPrefix"] return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=service, namespace='aws', meta_processor=aws_meta_processor, )
def _xray_traced_http_client_read(wrapped, instance, args, kwargs): xray_data = getattr(instance, _XRAY_PROP) return xray_recorder.record_subsegment(wrapped, instance, args, kwargs, name=strip_url(xray_data.url), namespace='remote', meta_processor=http_read_processor)
def _xray_traced_http_client_read(wrapped, instance, args, kwargs): xray_data = getattr(instance, _XRAY_PROP, None) if not xray_data: return wrapped(*args, **kwargs) return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=get_hostname(xray_data.url), namespace='remote', meta_processor=http_read_processor )
def _xray_traced_requests(wrapped, instance, args, kwargs): url = kwargs.get('url') or args[1] url = url.split('?')[0] return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=url, namespace='remote', meta_processor=requests_processor, )
def _xray_traced_requests(wrapped, instance, args, kwargs): url = kwargs.get('url') or args[1] return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=get_hostname(url), namespace='remote', meta_processor=requests_processor, )
def _xray_traced_http_getresponse(wrapped, instance, args, kwargs): if not PY2 and kwargs.get('buffering', False): # ignore py2 calls that fail as 'buffering` only exists in py2. return wrapped(*args, **kwargs) xray_data = getattr(instance, _XRAY_PROP, None) if not xray_data: return wrapped(*args, **kwargs) return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=get_hostname(xray_data.url), namespace='remote', meta_processor=http_response_processor, )
def _xray_traced_botocore(wrapped, instance, args, kwargs): service = instance._service_model.metadata["endpointPrefix"] if service == 'xray': # skip tracing for SDK built-in centralized sampling pollers if 'GetCentralizedSamplingRules' in args or 'GetSamplingTargets' in args: return wrapped(*args, **kwargs) return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=service, namespace='aws', meta_processor=aws_meta_processor, )
def _xray_traced_pynamodb(wrapped, instance, args, kwargs): # Check if it's a request to DynamoDB and return otherwise. try: service = args[0].headers['X-Amz-Target'].decode('utf-8').split('_')[0] except KeyError: return wrapped(*args, **kwargs) if service.lower() != 'dynamodb': return wrapped(*args, **kwargs) return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name='dynamodb', namespace='aws', meta_processor=pynamodb_meta_processor, )
def decompose_args(method, url, body, headers, encode_chunked=False): inject_trace_header(headers, xray_recorder.current_subsegment()) # we have to check against sock because urllib3's HTTPSConnection inherit's from http.client.HTTPConnection scheme = 'https' if isinstance(instance.sock, ssl.SSLSocket) else 'http' xray_url = '{}://{}{}'.format(scheme, instance.host, url) xray_data = _XRay_Data(method, instance.host, xray_url) setattr(instance, _XRAY_PROP, xray_data) # we add a segment here in case connect fails return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=strip_url(xray_data.url), namespace='remote', meta_processor=http_send_request_processor)
def decompose_args(method, url, body, headers, encode_chunked=False): # skip httplib tracing for SDK built-in centralized sampling pollers if (('/GetSamplingRules' in args or '/SamplingTargets' in args) and type(instance).__name__ == 'botocore.awsrequest.AWSHTTPConnection'): return wrapped(*args, **kwargs) # Only injects headers when the subsegment for the outgoing # calls are opened successfully. subsegment = None try: subsegment = xray_recorder.current_subsegment() except SegmentNotFoundException: pass if subsegment: inject_trace_header(headers, subsegment) if issubclass(instance.__class__, urllib3.connection.HTTPSConnection): ssl_cxt = getattr(instance, 'ssl_context', None) elif issubclass(instance.__class__, httplib.HTTPSConnection): ssl_cxt = getattr(instance, '_context', None) else: # In this case, the patcher can't determine which module the connection instance is from. # We default to it to check ssl_context but may be None so that the default scheme would be # (and may falsely be) http. ssl_cxt = getattr(instance, 'ssl_context', None) scheme = 'https' if ssl_cxt and type( ssl_cxt).__name__ == 'SSLContext' else 'http' xray_url = '{}://{}{}'.format(scheme, instance.host, url) xray_data = _XRay_Data(method, instance.host, xray_url) setattr(instance, _XRAY_PROP, xray_data) # we add a segment here in case connect fails return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, name=get_hostname(xray_data.url), namespace='remote', meta_processor=http_send_request_processor)