docs: def extract_aws_metadata(wrapped, instance, args, kwargs, return_value):
      """Provide AWS metadata for improved visualization.
  
      See documentation for this data structure:
      http://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-aws
      """
      response = return_value
      LOGGER.debug(
          'Extracting AWS metadata',
          args=args,
          kwargs=kwargs,
      )
      if 'operation_name' in kwargs:
          operation_name = kwargs['operation_name']
      else:
          operation_name = args[0]
  
      # Most of the time the actual keyword arguments to the client call are
      # passed in as a positial argument after the operation name.
      if len(kwargs) == 0 and len(args) == 2:
          kwargs = args[1]
  
      region_name = instance._client_config.region_name
  
      response_metadata = response.get('ResponseMetadata')
  
      metadata = {
          'aws': {
              'operation': operation_name,
              'region': region_name,
          }
      }
  
      if 'TableName' in kwargs:
          metadata['aws']['table_name'] = kwargs['TableName']
      if 'QueueUrl' in kwargs:
          metadata['aws']['queue_url'] = kwargs['QueueUrl']
  
      if response_metadata is not None:
          metadata['http'] = {
              'response': {
                  'status': response_metadata['HTTPStatusCode'],
              },
          }
          metadata['aws']['request_id'] = response_metadata['RequestId']
  
      return metadata