Skip to content
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

suppress instrument boto3 XRay.put_trace_segments() #1291

Closed
wants to merge 4 commits into from
Closed

suppress instrument boto3 XRay.put_trace_segments() #1291

wants to merge 4 commits into from

Conversation

wangzlei
Copy link

@wangzlei wangzlei commented Oct 28, 2020

Description

I am going to create an AWS XRay exporter in OpenTelemetry-Python, to emit telemetry data to AWS XRay service via boto3 API XRay.put_trace_segments(). This PR is the prerequisite for this in-process exporter.
When I was working on the AWSXrayExporter, the botocore instrumentor would instrument function XRay.put_trace_segments() inside of AWSXrayExporter, causes infinite recursive loop. This PR is inspired from AWS XRay SDK, skip instrument this specific function to avoid infinite recursion.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • End to end test
    Have created the AWSXrayExporter in local and enable botocore instrumentor in my test App to instrument a boto3 S3.list_buckets function. No infinite recursion problem happen.

  • Covered by unit test

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@wangzlei wangzlei requested review from a team, aabmass and ocelotl and removed request for a team October 28, 2020 04:50
@owais
Copy link
Contributor

owais commented Oct 28, 2020

I think there is an existing mechanism to do exactly this. Have you seen how other exporters solve the same problem? I think they configure the active tracing context to disable tracing and then any instrumented code inside the exporter code-path is not traced. Recommend to look into that and replicate it in the xray exporter.

@owais
Copy link
Contributor

owais commented Oct 28, 2020

Found it. Examples:

token = attach(set_value("suppress_instrumentation", True))

token = attach(set_value("suppress_instrumentation", True))

token = attach(set_value("suppress_instrumentation", True))

@NathanielRN
Copy link
Contributor

@owais That's a sweet example, I also found this test which was useful to help me understand how it works:

def test_suppress_instrumentation(self):
token = context.attach(
context.set_value("suppress_instrumentation", True)
)
try:
result = self.perform_request(self.URL)
self.assertEqual(result.text, "Hello!")
finally:
context.detach(token)
self.assert_span(num_spans=0)

@wangzlei
Copy link
Author

wangzlei commented Oct 28, 2020

I think there is an existing mechanism to do exactly this. Have you seen how other exporters solve the same problem? I think they configure the active tracing context to disable tracing and then any instrumented code inside the exporter code-path is not traced. Recommend to look into that and replicate it in the xray exporter.

Thanks! now set context suppress_instrumentation to suppress further instrument botocore.

@wangzlei wangzlei changed the title skip instrument boto3 XRay.put_trace_segments() suppress instrument boto3 XRay.put_trace_segments() Oct 28, 2020
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
@wangzlei
Copy link
Author

wangzlei commented Nov 5, 2020

@owais Kindly ping that do I miss anything?

@codeboten codeboten added the instrumentation Related to the instrumentation of third party libraries or frameworks label Nov 5, 2020
@lzchen
Copy link
Contributor

lzchen commented Nov 5, 2020

@wangzlei

Can you open up the same pr in the contrib repo?

@lzchen lzchen closed this Nov 5, 2020
@wangzlei
Copy link
Author

wangzlei commented Nov 6, 2020

@wangzlei

Can you open up the same pr in the contrib repo?

Yes, will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
instrumentation Related to the instrumentation of third party libraries or frameworks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants