Skip to content
New issue

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

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

Already on GitHub? # to your account

FastAPI: capture custom request response headers in span attributes #1032

Conversation

sanketmehta28
Copy link
Member

Description

This PR contains py tests for FastAPI framework. Actual code has been merged in this PR: capture custom request response header for ASGI
It also contains the doc update for FastAPI as well as for ASGI framework

Fixes #916

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Added unit tests for request and response headers for http and websocket applications.

Same test cases for both http/websocket application

Test A: check for request header which is set in OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST env variable, is present in the span as attribute
Test B: check for request header which is NOT set in OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST env variable, is NOT present in the span as attribute
Test C: check for response header which is set in OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE env variable, is present in the span as attribute
Test D: check for response header which is NOT set in OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE env variable, is NOT present in the span as attribute

Does This PR Require a Core Repo Change?

  • No.

Checklist:

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

@sanketmehta28 sanketmehta28 requested a review from a team April 6, 2022 06:42

def tearDown(self) -> None:
super().tearDown()
self.env_patch.stop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App should be uninstrumented in teardown. (example)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sanketmehta28
Copy link
Member Author

@lzchen, @srikanthccv Please do review this PR and if it looks fine, please do merge it

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FastAPI: Capture request/response headers as span attributes
4 participants