Intercept low-level cursor execute() events before execution.
    If executemany is True, this is an executemany call, else an execute call.

    Note: If enabled tracing both SQLAlchemy and the database it connected,
          the communication between SQLAlchemy and the database will also
          be traced. To avoid the verbose spans, you can just trace SQLAlchemy.

    See: http://docs.sqlalchemy.org/en/latest/core/events.html#sqlalchemy.
         events.ConnectionEvents.before_cursor_execute

def _before_cursor_execute(conn, cursor, statement, parameters,
                           context, executemany):
    """Intercept low-level cursor execute() events before execution.
    If executemany is True, this is an executemany call, else an execute call.

    Note: If enabled tracing both SQLAlchemy and the database it connected,
          the communication between SQLAlchemy and the database will also
          be traced. To avoid the verbose spans, you can just trace SQLAlchemy.

    See: http://docs.sqlalchemy.org/en/latest/core/events.html#sqlalchemy.
         events.ConnectionEvents.before_cursor_execute
    """
    # Find out the func name
    if executemany:
        query_func = 'executemany'
    else:
        query_func = 'execute'

    _tracer = execution_context.get_opencensus_tracer()
    _span = _tracer.start_span()
    _span.name = '{}.query'.format(MODULE_NAME)
    _span.span_kind = span_module.SpanKind.CLIENT

    # Set query statement attribute
    _tracer.add_attribute_to_current_span(
        '{}.query'.format(MODULE_NAME), statement)

    # Set query parameters attribute
    _tracer.add_attribute_to_current_span(
        '{}.query.parameters'.format(MODULE_NAME), str(parameters))

    # Set query function attribute
    _tracer.add_attribute_to_current_span(
        '{}.cursor.method.name'.format(MODULE_NAME),
        query_func)