Skip to content

Commit 8563afc

Browse files
authored
[Documentation] Improve API reference for patch and patch_all (#407)
1 parent 6dd6b07 commit 8563afc

9 files changed

+157
-2
lines changed

aws_xray_sdk/core/patcher.py

+22
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@
4747

4848

4949
def patch_all(double_patch=False):
50+
"""
51+
The X-Ray Python SDK supports patching aioboto3, aiobotocore, boto3, botocore, pynamodb, requests,
52+
sqlite3, mysql, httplib, pymongo, pymysql, psycopg2, pg8000, sqlalchemy_core, httpx, and mysql-connector.
53+
54+
To patch all supported libraries::
55+
56+
from aws_xray_sdk.core import patch_all
57+
58+
patch_all()
59+
60+
:param bool double_patch: enable or disable patching of indirect dependencies.
61+
"""
5062
if double_patch:
5163
patch(SUPPORTED_MODULES, raise_errors=False)
5264
else:
@@ -66,6 +78,16 @@ def _is_valid_import(module):
6678

6779

6880
def patch(modules_to_patch, raise_errors=True, ignore_module_patterns=None):
81+
"""
82+
To patch specific modules::
83+
84+
from aws_xray_sdk.core import patch
85+
86+
i_want_to_patch = ('botocore') # a tuple that contains the libs you want to patch
87+
patch(i_want_to_patch)
88+
89+
:param tuple modules_to_patch: a tuple containing the list of libraries to be patched
90+
"""
6991
enabled = global_sdk_config.sdk_enabled()
7092
if not enabled:
7193
log.debug("Skipped patching modules %s because the SDK is currently disabled." % ', '.join(modules_to_patch))

aws_xray_sdk/core/recorder.py

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def configure(self, sampling=None, plugins=None,
8888
8989
Configure needs to run before patching thrid party libraries
9090
to avoid creating dangling subsegment.
91+
9192
:param bool sampling: If sampling is enabled, every time the recorder
9293
creates a segment it decides whether to send this segment to
9394
the X-Ray daemon. This setting is not used if the recorder

docs/aws_xray_sdk.ext.httpx.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
aws\_xray\_sdk.ext.httpx package
2+
================================
3+
4+
Submodules
5+
----------
6+
7+
aws\_xray\_sdk.ext.httpx.patch module
8+
-------------------------------------
9+
10+
.. automodule:: aws_xray_sdk.ext.httpx.patch
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: aws_xray_sdk.ext.httpx
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:

docs/aws_xray_sdk.ext.pg8000.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
aws\_xray\_sdk.ext.pg8000 package
2+
=================================
3+
4+
Submodules
5+
----------
6+
7+
aws\_xray\_sdk.ext.pg8000.patch module
8+
--------------------------------------
9+
10+
.. automodule:: aws_xray_sdk.ext.pg8000.patch
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: aws_xray_sdk.ext.pg8000
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:

docs/aws_xray_sdk.ext.psycopg2.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
aws\_xray\_sdk.ext.psycopg2 package
2+
===================================
3+
4+
Submodules
5+
----------
6+
7+
aws\_xray\_sdk.ext.psycopg2.patch module
8+
----------------------------------------
9+
10+
.. automodule:: aws_xray_sdk.ext.psycopg2.patch
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: aws_xray_sdk.ext.psycopg2
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:

docs/aws_xray_sdk.ext.pymongo.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
aws\_xray\_sdk.ext.pymongo package
2+
==================================
3+
4+
Submodules
5+
----------
6+
7+
aws\_xray\_sdk.ext.pymongo.patch module
8+
---------------------------------------
9+
10+
.. automodule:: aws_xray_sdk.ext.pymongo.patch
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: aws_xray_sdk.ext.pymongo
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:

docs/aws_xray_sdk.ext.pymysql.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
aws\_xray\_sdk.ext.pymysql package
2+
==================================
3+
4+
Submodules
5+
----------
6+
7+
aws\_xray\_sdk.ext.pymysql.patch module
8+
---------------------------------------
9+
10+
.. automodule:: aws_xray_sdk.ext.pymysql.patch
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: aws_xray_sdk.ext.pymysql
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
aws\_xray\_sdk.ext.sqlalchemy\_core package
2+
===========================================
3+
4+
Submodules
5+
----------
6+
7+
aws\_xray\_sdk.ext.sqlalchemy\_core.patch module
8+
------------------------------------------------
9+
10+
.. automodule:: aws_xray_sdk.ext.sqlalchemy_core.patch
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: aws_xray_sdk.ext.sqlalchemy_core
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:

docs/thirdparty.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Third Party Library Support
66
Patching Supported Libraries
77
----------------------------
88

9-
The SDK supports aioboto3, aiobotocore, boto3, botocore, pynamodb, requests, sqlite3, httplib and
10-
mysql-connector.
9+
The X-Ray Python SDK supports patching aioboto3, aiobotocore, boto3, botocore, pynamodb, requests,
10+
sqlite3, mysql, httplib, pymongo, pymysql, psycopg2, pg8000, sqlalchemy_core, httpx, and mysql-connector.
1111

1212
To patch, use code like the following in the main app::
1313

@@ -36,6 +36,12 @@ The following modules are availble to patch::
3636
'sqlite3',
3737
'mysql',
3838
'httplib',
39+
'pymongo',
40+
'pymysql',
41+
'psycopg2',
42+
'pg8000',
43+
'sqlalchemy_core',
44+
'httpx',
3945
)
4046

4147
Patching boto3 and botocore are equivalent since boto3 depends on botocore.

0 commit comments

Comments
 (0)