[英]where to use aws x-ray patch all (python)
As documented, we can use patch_all
to automatically create subsegments for aws services such as s3 and sqs.如文档所述,我们可以使用
patch_all
自动为 s3 和 sqs 等 aws 服务创建子分段。 My question is where should I call this method.我的问题是我应该在哪里调用这个方法。
For example, let's assume there are 2 files which use boto3 and we want to patch.例如,假设有 2 个使用 boto3 的文件,我们要修补。 Because they are independent, we must call
patch_all
in both of them.因为它们是独立的,所以我们必须在它们两个中调用
patch_all
。 Hence, we would have:因此,我们将有:
File a.py
:文件
a.py
:
import boto3
from xray_recorder import patch_all
patch_all()
File b.py
:文件
b.py
:
import boto3
from xray_recorder import patch_all
patch_all()
Now, lets assume we have a module named c.py
which import both a.py
and b.py
:现在,假设我们有一个名为
c.py
的模块,它同时导入a.py
和b.py
:
import a
import b
In this flow, boto3
would be patched twice.在此流程中,
boto3
将被修补两次。
The only solution I found for it is to import boto3
only from inside a file, named for example my_boto3.py
which imports boto3
and patch it.我找到的唯一解决方案是
boto3
文件内部导入boto3
,例如my_boto3.py
,它导入boto3
并修补它。
What is the good practice to patch boto3
?修补
boto3
的好做法是什么? Thanks谢谢
You can simply call patch_all()
in the main function.您可以简单地在主函数中调用
patch_all()
。 Just follow instructions here , and it should work for all of the libraries( functions and classes ) patched within the same application.只需按照此处的说明进行操作,它应该适用于同一应用程序中修补的所有库( 函数和类)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.