Skip to content

[Documentation] Improve API reference for patch and patch_all #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions aws_xray_sdk/core/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@


def patch_all(double_patch=False):
"""
The X-Ray Python SDK supports patching aioboto3, aiobotocore, boto3, botocore, pynamodb, requests,
sqlite3, mysql, httplib, pymongo, pymysql, psycopg2, pg8000, sqlalchemy_core, httpx, and mysql-connector.

To patch all supported libraries::

from aws_xray_sdk.core import patch_all

patch_all()

:param bool double_patch: enable or disable patching of indirect dependencies.
"""
if double_patch:
patch(SUPPORTED_MODULES, raise_errors=False)
else:
Expand All @@ -66,6 +78,16 @@ def _is_valid_import(module):


def patch(modules_to_patch, raise_errors=True, ignore_module_patterns=None):
"""
To patch specific modules::

from aws_xray_sdk.core import patch

i_want_to_patch = ('botocore') # a tuple that contains the libs you want to patch
patch(i_want_to_patch)

:param tuple modules_to_patch: a tuple containing the list of libraries to be patched
"""
enabled = global_sdk_config.sdk_enabled()
if not enabled:
log.debug("Skipped patching modules %s because the SDK is currently disabled." % ', '.join(modules_to_patch))
Expand Down
1 change: 1 addition & 0 deletions aws_xray_sdk/core/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def configure(self, sampling=None, plugins=None,

Configure needs to run before patching thrid party libraries
to avoid creating dangling subsegment.

:param bool sampling: If sampling is enabled, every time the recorder
creates a segment it decides whether to send this segment to
the X-Ray daemon. This setting is not used if the recorder
Expand Down
21 changes: 21 additions & 0 deletions docs/aws_xray_sdk.ext.httpx.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
aws\_xray\_sdk.ext.httpx package
================================

Submodules
----------

aws\_xray\_sdk.ext.httpx.patch module
-------------------------------------

.. automodule:: aws_xray_sdk.ext.httpx.patch
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: aws_xray_sdk.ext.httpx
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/aws_xray_sdk.ext.pg8000.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
aws\_xray\_sdk.ext.pg8000 package
=================================

Submodules
----------

aws\_xray\_sdk.ext.pg8000.patch module
--------------------------------------

.. automodule:: aws_xray_sdk.ext.pg8000.patch
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: aws_xray_sdk.ext.pg8000
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/aws_xray_sdk.ext.psycopg2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
aws\_xray\_sdk.ext.psycopg2 package
===================================

Submodules
----------

aws\_xray\_sdk.ext.psycopg2.patch module
----------------------------------------

.. automodule:: aws_xray_sdk.ext.psycopg2.patch
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: aws_xray_sdk.ext.psycopg2
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/aws_xray_sdk.ext.pymongo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
aws\_xray\_sdk.ext.pymongo package
==================================

Submodules
----------

aws\_xray\_sdk.ext.pymongo.patch module
---------------------------------------

.. automodule:: aws_xray_sdk.ext.pymongo.patch
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: aws_xray_sdk.ext.pymongo
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/aws_xray_sdk.ext.pymysql.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
aws\_xray\_sdk.ext.pymysql package
==================================

Submodules
----------

aws\_xray\_sdk.ext.pymysql.patch module
---------------------------------------

.. automodule:: aws_xray_sdk.ext.pymysql.patch
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: aws_xray_sdk.ext.pymysql
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/aws_xray_sdk.ext.sqlalchemy_core.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
aws\_xray\_sdk.ext.sqlalchemy\_core package
===========================================

Submodules
----------

aws\_xray\_sdk.ext.sqlalchemy\_core.patch module
------------------------------------------------

.. automodule:: aws_xray_sdk.ext.sqlalchemy_core.patch
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: aws_xray_sdk.ext.sqlalchemy_core
:members:
:undoc-members:
:show-inheritance:
10 changes: 8 additions & 2 deletions docs/thirdparty.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Third Party Library Support
Patching Supported Libraries
----------------------------

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

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

Expand Down Expand Up @@ -36,6 +36,12 @@ The following modules are availble to patch::
'sqlite3',
'mysql',
'httplib',
'pymongo',
'pymysql',
'psycopg2',
'pg8000',
'sqlalchemy_core',
'httpx',
)

Patching boto3 and botocore are equivalent since boto3 depends on botocore.
Expand Down