Esempio n. 1
0
    def trace_node(self, stats, root, connections):

        operation = self.operation

        # TODO Verify that these are the correct names to use.
        # Could possibly cache this if necessary.

        if operation in ('select', 'update', 'insert', 'delete'):
            target = self.target
            if target:
                name = 'Database/%s/%s' % (target, operation)
            else:
                name = 'Database/%s' % operation
        elif operation in ('show',):
            name = 'Database/%s' % operation
        else:
            name = 'Database/other/sql'

        name = root.string_table.cache(name)

        start_time = newrelic.core.trace_node.node_start_time(root, self)
        end_time = newrelic.core.trace_node.node_end_time(root, self)

        children = []

        root.trace_node_count += 1

        params = {}

        sql = self.formatted

        if sql:
            # Limit the length of any SQL that is reported back.

            limit = root.settings.agent_limits.sql_query_length_maximum

            params['sql'] = root.string_table.cache(sql[:limit])

            if self.stack_trace:
                params['backtrace'] = [root.string_table.cache(x) for x in
                        self.stack_trace]

            # Only perform an explain plan if this node ended up being
            # flagged to have an explain plan. This is applied when cap
            # on number of explain plans for whole harvest period is
            # applied across all transaction traces just prior to the
            # transaction traces being generated.

            if getattr(self, 'generate_explain_plan', None):
                explain_plan_data = explain_plan(connections,
                        self.statement, self.connect_params,
                        self.cursor_params, self.sql_parameters,
                        self.execute_params, self.sql_format)

                if explain_plan_data:
                    params['explain_plan'] = explain_plan_data

        return newrelic.core.trace_node.TraceNode(start_time=start_time,
                end_time=end_time, name=name, params=params, children=children,
                label=None)
    def trace_node(self, stats, root, connections):
        product = self.product
        operation = self.operation or 'other'
        target = self.target

        if target:
            name = 'Datastore/statement/%s/%s/%s' % (product, target,
                    operation)
        else:
            name = 'Datastore/operation/%s/%s' % (product, operation)

        name = root.string_table.cache(name)

        start_time = newrelic.core.trace_node.node_start_time(root, self)
        end_time = newrelic.core.trace_node.node_end_time(root, self)

        children = []

        root.trace_node_count += 1

        params = {}

        # Only send datastore instance params if not empty.

        if self.host:
            params['host'] = self.instance_hostname

        if self.port_path_or_id:
            params['port_path_or_id'] = self.port_path_or_id

        if self.database_name:
            params['database_name'] = self.database_name

        sql = self.formatted

        if sql:
            # Limit the length of any SQL that is reported back.

            limit = root.settings.agent_limits.sql_query_length_maximum

            params['sql'] = root.string_table.cache(sql[:limit])

            if self.stack_trace:
                params['backtrace'] = [root.string_table.cache(x) for x in
                        self.stack_trace]

            # Only perform an explain plan if this node ended up being
            # flagged to have an explain plan. This is applied when cap
            # on number of explain plans for whole harvest period is
            # applied across all transaction traces just prior to the
            # transaction traces being generated.

            if getattr(self, 'generate_explain_plan', None):
                explain_plan_data = explain_plan(connections,
                        self.statement, self.connect_params,
                        self.cursor_params, self.sql_parameters,
                        self.execute_params, self.sql_format)

                if explain_plan_data:
                    params['explain_plan'] = explain_plan_data

        return newrelic.core.trace_node.TraceNode(start_time=start_time,
                end_time=end_time, name=name, params=params, children=children,
                label=None)
Esempio n. 3
0
    def trace_node(self, stats, root, connections):
        product = self.product
        operation = self.operation or 'other'
        target = self.target

        if target:
            name = 'Datastore/statement/%s/%s/%s' % (product, target,
                                                     operation)
        else:
            name = 'Datastore/operation/%s/%s' % (product, operation)

        name = root.string_table.cache(name)

        start_time = newrelic.core.trace_node.node_start_time(root, self)
        end_time = newrelic.core.trace_node.node_end_time(root, self)

        children = []

        root.trace_node_count += 1

        params = {}

        # Only send datastore instance params if not empty.

        if self.host:
            params['host'] = self.instance_hostname

        if self.port_path_or_id:
            params['port_path_or_id'] = self.port_path_or_id

        if self.database_name:
            params['database_name'] = self.database_name

        sql = self.formatted

        if sql:
            # Limit the length of any SQL that is reported back.

            limit = root.settings.agent_limits.sql_query_length_maximum

            params['sql'] = root.string_table.cache(sql[:limit])

            if self.stack_trace:
                params['backtrace'] = [
                    root.string_table.cache(x) for x in self.stack_trace
                ]

            # Only perform an explain plan if this node ended up being
            # flagged to have an explain plan. This is applied when cap
            # on number of explain plans for whole harvest period is
            # applied across all transaction traces just prior to the
            # transaction traces being generated.

            if getattr(self, 'generate_explain_plan', None):
                explain_plan_data = explain_plan(connections, self.statement,
                                                 self.connect_params,
                                                 self.cursor_params,
                                                 self.sql_parameters,
                                                 self.execute_params,
                                                 self.sql_format)

                if explain_plan_data:
                    params['explain_plan'] = explain_plan_data

        return newrelic.core.trace_node.TraceNode(start_time=start_time,
                                                  end_time=end_time,
                                                  name=name,
                                                  params=params,
                                                  children=children,
                                                  label=None)
    def trace_node(self, stats, root, connections):

        operation = self.operation

        # TODO Verify that these are the correct names to use.
        # Could possibly cache this if necessary.

        if operation in ('select', 'update', 'insert', 'delete'):
            target = self.target
            if target:
                name = 'Database/%s/%s' % (target, operation)
            else:
                name = 'Database/%s' % operation
        elif operation in ('show', ):
            name = 'Database/%s' % operation
        else:
            name = 'Database/other/sql'

        name = root.string_table.cache(name)

        start_time = newrelic.core.trace_node.node_start_time(root, self)
        end_time = newrelic.core.trace_node.node_end_time(root, self)

        children = []

        root.trace_node_count += 1

        params = {}

        sql = self.formatted

        if sql:
            # Limit the length of any SQL that is reported back.

            limit = root.settings.agent_limits.sql_query_length_maximum

            params['sql'] = root.string_table.cache(sql[:limit])

            if self.stack_trace:
                params['backtrace'] = [
                    root.string_table.cache(x) for x in self.stack_trace
                ]

            # Only perform an explain plan if this node ended up being
            # flagged to have an explain plan. This is applied when cap
            # on number of explain plans for whole harvest period is
            # applied across all transaction traces just prior to the
            # transaction traces being generated.

            if getattr(self, 'generate_explain_plan', None):
                explain_plan_data = explain_plan(connections, self.statement,
                                                 self.connect_params,
                                                 self.cursor_params,
                                                 self.sql_parameters,
                                                 self.execute_params,
                                                 self.sql_format)

                if explain_plan_data:
                    params['explain_plan'] = explain_plan_data

        return newrelic.core.trace_node.TraceNode(start_time=start_time,
                                                  end_time=end_time,
                                                  name=name,
                                                  params=params,
                                                  children=children,
                                                  label=None)
Esempio n. 5
0
 def explain_plan(self, connections):
     return explain_plan(connections, self.statement, self.connect_params,
                         self.cursor_params, self.sql_parameters,
                         self.execute_params, self.sql_format)