Skip to content

Feat/request context #83

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 18 commits into from
May 27, 2021
Merged

Feat/request context #83

merged 18 commits into from
May 27, 2021

Conversation

samwelkanda
Copy link
Contributor

@samwelkanda samwelkanda commented Apr 27, 2021

Overview

This PR attaches a request context object to the native Http Request object, or Graph Request Object, to control the behavior of middleware in the Python SDK.  A request context contains data that is persisted throughout the request and includes a ClientRequestId property, MiddlewareControl property to control behavior of middleware   as well as a FeatureUsage  property to keep track of middleware used in making the request. The request context is also be accessible to middleware components to override the options provided during middleware instantiation.

Demo

Sample usage by telemetry handler to add specific headers

client_request_id=request.context.client_request_idfeature_usage=request.context.feature_usagerequest.headers.update({'client-request-id': f'{client_request_id}'})  
request.headers.update({'feature-usage': '{feature_usage}'})  
request.headers.update({'sdkVersion':   
           f'graph-python-core/{SDK_VERSION} (featureUsage=feature_usage)'})

Notes

This design uses keyword arguments to pass request-specific options to middleware as opposed to a middleware options dictionary. Consequently, this means that per-request config for custom middleware is not supported for now.

Testing Instructions

  • Pull the feat/request-context branch
  • Instantiate a client and make a call to the graph api e.g
resp = client.get('/me')
  • Observe that a context object was attached to the original request, and has the required properties
print(resp.request.context)
print(resp.request.context.client_request_id)
print(resp.request.context.feature_usage)

Fixes #79
Fixes #59
Fixes #43
Fixes #17

@samwelkanda samwelkanda changed the base branch from dev to feat/graph-client-factory April 27, 2021 13:50
Base automatically changed from feat/graph-client-factory to dev May 13, 2021 08:42
@samwelkanda samwelkanda requested a review from ddyett as a code owner May 13, 2021 08:42
@MIchaelMainer
Copy link
Contributor

@samwelkanda Besides the questions above, what else do we need to do on this PR? Do we need to re-review with the design changes?

@MIchaelMainer MIchaelMainer requested a review from shemogumbe May 26, 2021 17:25
@samwelkanda samwelkanda merged commit 01c1311 into dev May 27, 2021
@samwelkanda samwelkanda deleted the feat/request-context branch May 27, 2021 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RequestContext Object/Alternative Don't Override User Provided Request ID Pass scopes through GraphSession RequestContext
3 participants