| 1 |
.. _thirdparty: |
| 2 |
|
| 3 |
Third Party Library Support |
| 4 |
=========================== |
| 5 |
|
| 6 |
Patching Supported Libraries |
| 7 |
---------------------------- |
| 8 |
|
| 9 |
The SDK supports aioboto3, aiobotocore, boto3, botocore, requests, sqlite3 and mysql-connector. |
| 10 |
|
| 11 |
To patch, use code like the following in the main app:: |
| 12 |
|
| 13 |
from aws_xray_sdk.core import patch_all |
| 14 |
|
| 15 |
patch_all() |
| 16 |
|
| 17 |
``patch_all`` ignores any libraries that are not installed. |
| 18 |
|
| 19 |
To patch specific modules:: |
| 20 |
|
| 21 |
from aws_xray_sdk.core import patch |
| 22 |
|
| 23 |
i_want_to_patch = ('botocore') # a tuple that contains the libs you want to patch |
| 24 |
patch(i_want_to_patch) |
| 25 |
|
| 26 |
The following modules are availble to patch:: |
| 27 |
|
| 28 |
SUPPORTED_MODULES = ( |
| 29 |
'aioboto3', |
| 30 |
'aiobotocore', |
| 31 |
'boto3', |
| 32 |
'botocore', |
| 33 |
'requests', |
| 34 |
'sqlite3', |
| 35 |
'mysql', |
| 36 |
) |
| 37 |
|
| 38 |
Patching boto3 and botocore are equivalent since boto3 depends on botocore |
| 39 |
|
| 40 |
Patching mysql |
| 41 |
---------------------------- |
| 42 |
|
| 43 |
For mysql, only the mysql-connector module is supported and you have to use |
| 44 |
code like the following to generate a subsegment for an SQL query:: |
| 45 |
|
| 46 |
def call_mysql(): |
| 47 |
conn = mysql.connector.connect( |
| 48 |
host='host', |
| 49 |
port='some_port', |
| 50 |
user='some_user', |
| 51 |
password='your_password', |
| 52 |
database='your_db_name' |
| 53 |
) |
| 54 |
|
| 55 |
conn.cursor().execute('SHOW TABLES') |
| 56 |
|
| 57 |
Patching aioboto3 and aiobotocore |
| 58 |
--------------------------------- |
| 59 |
|
| 60 |
On top of patching aioboto3 or aiobotocore, the xray_recorder also needs to be |
| 61 |
configured to use the ``AsyncContext``. The following snippet shows how to set |
| 62 |
up the X-Ray SDK with an Async Context, bear in mind this requires Python 3.5+:: |
| 63 |
|
| 64 |
from aws_xray_sdk.core.async_context import AsyncContext |
| 65 |
from aws_xray_sdk.core import xray_recorder |
| 66 |
# Configure X-Ray to use AsyncContext |
| 67 |
xray_recorder.configure(service='service_name', context=AsyncContext()) |
| 68 |
|
| 69 |
See :ref:`Configure Global Recorder <configurations>` for more information about |
| 70 |
configuring the ``xray_recorder``. |