Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Add support for qldb driver cs 273 #417

Merged
merged 21 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
757c1f7
fix(fastapi): support async endpoint handlers
sagivr2020 Jul 13, 2022
23e9524
fix(fastapi): lint fix
sagivr2020 Jul 14, 2022
49e471e
fix(fastapi): test fixes
sagivr2020 Jul 14, 2022
59b3722
fix(fastapi): lint disable for global statement
sagivr2020 Jul 14, 2022
b7c3614
fix(fastapi): fix get_event_loop to support multiple python versions
sagivr2020 Jul 17, 2022
cb30ec9
fix(fastapi): fix current_task to support multiple python versions
sagivr2020 Jul 17, 2022
04c53da
fix(fastapi): fix get event loop for python 3_6
sagivr2020 Jul 18, 2022
089bc6a
fix(fastapi): fix lint for python 2_7
sagivr2020 Jul 18, 2022
3cf5e64
fix(fastapi): fix CR comments
sagivr2020 Jul 19, 2022
4e8727b
fix(fastapi): add to README and lint fix
sagivr2020 Jul 19, 2022
f27ceb2
fix(fastapi): fix CR-2 comments
sagivr2020 Jul 19, 2022
14595ec
add support for aws qldb driver
sagivr2020 Aug 21, 2022
963bae5
Merge branch 'master' into add-support-for-qldb-driver-cs-273
sagivr2020 Aug 21, 2022
41da418
fix lint
sagivr2020 Aug 21, 2022
89a87cb
fix lint
sagivr2020 Aug 21, 2022
016575d
add python 3.6 to be removed from acceptance tests
sagivr2020 Aug 21, 2022
4008566
return acceptance tests
sagivr2020 Aug 21, 2022
4459b82
fixes for pr review and run acceptance tests
sagivr2020 Aug 23, 2022
9775895
ignore python version 3_6 in run acceptance tests
sagivr2020 Aug 23, 2022
dd600d9
add ignore python version 3_6 in run acceptance tests
sagivr2020 Aug 23, 2022
217c906
ignore python version 3_6 and 2.7 in run acceptance tests
sagivr2020 Aug 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions epsagon/events/pyqldb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
pymongo events module.
"""

from __future__ import absolute_import
from uuid import uuid4
import traceback

from epsagon.utils import add_data_if_needed
from ..event import BaseEvent
from ..trace import trace_factory


class QldbEvent(BaseEvent):
"""
Represents base pymongo event.
"""

ORIGIN = 'qldb'
RESOURCE_TYPE = 'qldb'

#pylint: disable=W0613
def __init__(self, wrapped, instance, args, kwargs, start_time, response,
exception):
"""
Initialize.
:param wrapped: wrapt's wrapped
:param instance: wrapt's instance
:param args: wrapt's args
:param kwargs: wrapt's kwargs
:param start_time: Start timestamp (epoch)
:param response: response data
:param exception: Exception (if happened)
"""
super(QldbEvent, self).__init__(start_time)

self.event_id = 'qldb-{}'.format(str(uuid4()))
self.resource['name'] = \
getattr(instance.__getattribute__('_transaction')._session,# pylint: disable=W0212
'_ledger_name')
self.resource['operation'] = wrapped.__func__.__name__

self.resource['metadata']['query'] = args[0]
add_data_if_needed(self.resource['metadata'], 'parameters',
[args[i] for i in range(1, len(args))])

add_data_if_needed(self.resource['metadata'], 'transaction_id',
getattr(instance, 'transaction_id'))

if response is not None:
self.update_response(response)

if exception is not None:
self.set_exception(exception, traceback.format_exc())


def update_response(self, response):
"""
Adds response data to event.
:param response: Response from botocore
:return: None
"""

self.resource['metadata']['Results'] = [str(x) for x in response]
self.resource['metadata']['response.consumed_information'] = \
response.get_consumed_ios()
self.resource['metadata']['response.timing_information'] = \
response.get_timing_information()



class QldbEventFactory(object):
"""
Factory class, generates Qldb event.
"""

@staticmethod
def create_event(wrapped, instance, args, kwargs, start_time, response,
exception):
"""
Create a Qldb event.
:param wrapped:
:param instance:
:param args:
:param kwargs:
:param start_time:
:param response:
:param exception:
:return:
"""
event = QldbEvent(
wrapped,
instance,
args,
kwargs,
start_time,
response,
exception
)
trace_factory.add_event(event)
31 changes: 31 additions & 0 deletions epsagon/modules/pyqldb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
pymysql patcher module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyqldb

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"""
from __future__ import absolute_import
import wrapt
from epsagon.modules.general_wrapper import wrapper
from ..events.pyqldb import QldbEventFactory


def _wrapper(wrapped, instance, args, kwargs):
"""
General wrapper for PynamoDB instrumentation.
:param wrapped: wrapt's wrapped
:param instance: wrapt's instance
:param args: wrapt's args
:param kwargs: wrapt's kwargs
:return: None
"""
return wrapper(QldbEventFactory, wrapped, instance, args, kwargs)


def patch():
"""
patch module.
:return: None
"""
wrapt.wrap_function_wrapper(
'pyqldb.execution.executor',
'Executor.execute_statement',
_wrapper
)