예제 #1
0
 def _test():
     with MessageTrace('library',
                       'operation',
                       'dest_type',
                       'dest_name',
                       params={'secret': 'super secret'}):
         pass
def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs):
    transaction = current_transaction()

    if transaction is None:
        return wrapped(*args, **kwargs)

    from pika import BasicProperties

    (exchange, routing_key, body, properties, mandatory,
     immediate) = (_bind_basic_publish(*args, **kwargs))
    properties = properties or BasicProperties()
    properties.headers = properties.headers or {}
    user_headers = properties.headers.copy()

    # Do not record cat headers in the segment parameters
    if MessageTrace.cat_id_key in user_headers:
        del user_headers[MessageTrace.cat_id_key]
    if MessageTrace.cat_transaction_key in user_headers:
        del user_headers[MessageTrace.cat_transaction_key]
    if MessageTrace.cat_distributed_trace_key in user_headers:
        del user_headers[MessageTrace.cat_distributed_trace_key]

    args = (exchange, routing_key, body, properties, mandatory, immediate)

    params = {}
    if routing_key is not None:
        params['routing_key'] = routing_key
    if properties.correlation_id is not None:
        params['correlation_id'] = properties.correlation_id
    if properties.reply_to is not None:
        params['reply_to'] = properties.reply_to
    if user_headers:
        params['headers'] = user_headers

    with MessageTrace(transaction,
                      library='RabbitMQ',
                      operation='Produce',
                      destination_type='Exchange',
                      destination_name=exchange or 'Default',
                      params=params):
        cat_headers = MessageTrace.generate_request_headers(transaction)

        for name, value in cat_headers:
            properties.headers[name] = value
        return wrapped(*args)
def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs):
    transaction = current_transaction()

    if transaction is None:
        return wrapped(*args, **kwargs)

    from pika import BasicProperties

    (exchange, routing_key, body, properties, args,
     kwargs) = (_bind_basic_publish(*args, **kwargs))
    properties = properties or BasicProperties()
    properties.headers = properties.headers or {}
    user_headers = properties.headers.copy()

    # Do not record dt headers in the segment parameters
    user_headers.pop(MessageTrace.cat_id_key, None)
    user_headers.pop(MessageTrace.cat_transaction_key, None)
    user_headers.pop(MessageTrace.cat_distributed_trace_key, None)
    user_headers.pop("traceparent", None)
    user_headers.pop("tracestate", None)

    args = (exchange, routing_key, body, properties) + args

    params = {}
    if routing_key is not None:
        params['routing_key'] = routing_key
    if properties.correlation_id is not None:
        params['correlation_id'] = properties.correlation_id
    if properties.reply_to is not None:
        params['reply_to'] = properties.reply_to
    if user_headers:
        params['headers'] = user_headers

    with MessageTrace(library='RabbitMQ',
                      operation='Produce',
                      destination_type='Exchange',
                      destination_name=exchange or 'Default',
                      params=params,
                      source=wrapped):
        cat_headers = MessageTrace.generate_request_headers(transaction)
        properties.headers.update(cat_headers)
        return wrapped(*args, **kwargs)
예제 #4
0
def _add_consume_rabbitmq_trace(transaction, method, properties,
        nr_start_time, queue_name=None):

    routing_key = None
    if hasattr(method, 'routing_key'):
        routing_key = method.routing_key

    properties = properties and properties.__dict__ or {}

    correlation_id = properties.get('correlation_id')
    reply_to = properties.get('reply_to')
    headers = properties.get('headers')

    # Do not record dt headers in the segment parameters
    if headers:
        headers.pop(
                MessageTrace.cat_id_key, None)
        headers.pop(
                MessageTrace.cat_transaction_key, None)
        headers.pop(
                MessageTrace.cat_distributed_trace_key, None)
        headers.pop('traceparent', None)
        headers.pop('tracestate', None)

    # The transaction may have started after the message was received. In this
    # case, the start time is reset to the true transaction start time.
    transaction.start_time = min(nr_start_time,
            transaction.start_time)

    params = {}
    if routing_key is not None:
        params['routing_key'] = routing_key
    if correlation_id is not None:
        params['correlation_id'] = correlation_id
    if reply_to is not None:
        params['reply_to'] = reply_to
    if headers is not None:
        params['headers'] = headers
    if queue_name is not None:
        params['queue_name'] = queue_name

    # create a trace starting at the time the message was received
    trace = MessageTrace(library='RabbitMQ',
            operation='Consume',
            destination_type='Exchange',
            destination_name=method.exchange or 'Default',
            params=params)
    trace.__enter__()
    trace.start_time = nr_start_time
    trace.__exit__(None, None, None)
예제 #5
0
 def _test():
     with MessageTrace("library", "operation", "dest_type", "dest_name", params={"secret": "super secret"}):
         pass