async def _nr_wrapper_Aredis_method_(wrapped, instance, args, kwargs):
        transaction = current_transaction()
        if transaction is None:
            return await wrapped(*args, **kwargs)

        dt = DatastoreTrace(product="Redis", target=None, operation=operation)

        transaction._nr_datastore_instance_info = (None, None, None)

        with dt:
            result = await wrapped(*args, **kwargs)

            host, port_path_or_id, db = transaction._nr_datastore_instance_info
            dt.host = host
            dt.port_path_or_id = port_path_or_id
            dt.database_name = db
            return result
    def _nr_datastore_trace_wrapper_(wrapped, instance, args, kwargs):
        transaction = current_transaction()

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

        transaction._nr_datastore_instance_info = (None, None, None)

        dt = DatastoreTrace(product, target, operation)

        with dt:
            result = wrapped(*args, **kwargs)

            instance_info = transaction._nr_datastore_instance_info
            (host, port_path_or_id, db) = instance_info
            dt.host = host
            dt.port_path_or_id = port_path_or_id

            return result
Exemplo n.º 3
0
    def _nr_wrapper_Elasticsearch_method_(wrapped, instance, args, kwargs):
        transaction = current_transaction()

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

        # When arg_extractor is None, it means there is no target field
        # associated with this method. Hence this method will only
        # create an operation metric and no statement metric. This is
        # handled by setting the target to None when calling the
        # DatastoreTrace.

        if arg_extractor is None:
            index = None
        else:
            index = arg_extractor(*args, **kwargs)

        if prefix:
            operation = '%s.%s' % (prefix, name)
        else:
            operation = name

        transaction._nr_datastore_instance_info = (None, None, None)

        dt = DatastoreTrace(transaction=transaction,
                            product='Elasticsearch',
                            target=index,
                            operation=operation)

        with dt:
            result = wrapped(*args, **kwargs)

            instance_info = transaction._nr_datastore_instance_info
            host, port_path_or_id, _ = instance_info

            dt.host = host
            dt.port_path_or_id = port_path_or_id

            return result
Exemplo n.º 4
0
def wrap_connect(wrapped, instance, args, kwargs):
    host = port = database_name = None
    if "addr" in kwargs:
        host, port, database_name = PostgresApi._instance_info(
            kwargs["addr"], None, kwargs.get("params"))

    with DatastoreTrace(
            PostgresApi._nr_database_product,
            None,
            "connect",
            host=host,
            port_path_or_id=port,
            database_name=database_name,
    ):
        return wrapped(*args, **kwargs)
Exemplo n.º 5
0
def _nr_Connection_send_command_wrapper_(wrapped, instance, args, kwargs):
    transaction = current_transaction()

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

    host, port_path_or_id, db = (None, None, None)

    try:
        dt = transaction.settings.datastore_tracer
        if (dt.instance_reporting.enabled
                or dt.database_name_reporting.enabled):
            conn_kwargs = _conn_attrs_to_dict(instance)
            host, port_path_or_id, db = _instance_info(conn_kwargs)
    except:
        pass

    transaction._nr_datastore_instance_info = (host, port_path_or_id, db)

    # Older Redis clients would when sending multi part commands pass
    # them in as separate arguments to send_command(). Need to therefore
    # detect those and grab the next argument from the set of arguments.

    operation = args[0].strip().lower()

    # If it's not a multi part command, there's no need to trace it, so
    # we can return early.

    if operation.split()[0] not in _redis_multipart_commands:
        return wrapped(*args, **kwargs)

    # Convert multi args to single arg string

    if operation in _redis_multipart_commands and len(args) > 1:
        operation = '%s %s' % (operation, args[1].strip().lower())

    operation = _redis_operation_re.sub('_', operation)

    with DatastoreTrace(transaction,
                        product='Redis',
                        target=None,
                        operation=operation,
                        host=host,
                        port_path_or_id=port_path_or_id,
                        database_name=db):
        return wrapped(*args, **kwargs)
Exemplo n.º 6
0
def wrap_kazoo(wrapped, instance, args, kwargs):
    transaction = current_transaction()
    host, port, db = (None, None, None)
    operation = wrapped.__name__

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

    if instance._connection and instance._connection._socket:
        host, port = instance._connection._socket.getsockname()

    with DatastoreTrace(transaction,
                        product='Zookeeper',
                        target=None,
                        operation=operation,
                        host=host,
                        port_path_or_id=port,
                        database_name=db):
        return wrapped(*args, **kwargs)
    def _nr_wrapper_ElasticSearch_method_(wrapped, instance, args, kwargs):
        transaction = current_transaction()

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

        # When arg_extractor is None, it means there is no target field
        # associated with this method. Hence this method will only
        # create an operation metric and no statement metric. This is
        # handled by setting the target to None when calling the
        # DatastoreTrace.

        if arg_extractor is None:
            index = None
        else:
            index = arg_extractor(*args, **kwargs)

        with DatastoreTrace(transaction, product='Elasticsearch',
                target=index, operation=name):
            return wrapped(*args, **kwargs)
Exemplo n.º 8
0
def test_datastore_db_instance_truncation():
    with DatastoreTrace('db_product',
                        'db_target',
                        'db_operation',
                        database_name='a' * 256):
        pass
Exemplo n.º 9
0
    def _test():
        transaction = current_transaction()
        transaction._sampled = True

        with DatastoreTrace(**kwargs):
            pass