RequestIdPolicy Class
A simple policy that sets the given request id in the header.
This will overwrite request id that is already defined in the request. Request id can be configured up front, where the request id will be applied to all outgoing operations, and additional request id can also be set dynamically per operation.
Constructor
RequestIdPolicy(*, request_id: str | ~typing.Any = <class 'azure.core.pipeline.policies._universal._Unset'>, auto_request_id: bool = True, request_id_header_name: str = 'x-ms-client-request-id', **kwargs: ~typing.Any)
Keyword-Only Parameters
Name | Description |
---|---|
request_id
|
The request id to be added into header. Default value: <class 'azure.core.pipeline.policies._universal._Unset'>
|
auto_request_id
|
Auto generates a unique request ID per call if true which is by default. Default value: True
|
request_id_header_name
|
Header name to use. Default is "x-ms-client-request-id". Default value: x-ms-client-request-id
|
Examples
Configuring a request id policy.
from azure.core.pipeline.policies import HeadersPolicy
request_id_policy = RequestIdPolicy()
request_id_policy.set_request_id("azconfig-test")
# Or headers can be added per operation. These headers will supplement existing headers
# or those defined in the config headers policy. They will also overwrite existing
# identical headers.
policies.append(request_id_policy)
client: PipelineClient[HttpRequest, HttpResponse] = PipelineClient(base_url=url, policies=policies)
request = HttpRequest("GET", url)
pipeline_response = client._pipeline.run(request, request_id="azconfig-test")
Methods
on_exception |
Is executed if an exception is raised while executing the next policy. This method is executed inside the exception handler. |
on_request |
Updates with the given request id before sending the request to the next policy. |
on_response |
Is executed after the request comes back from the policy. |
set_request_id |
Add the request id to the configuration to be applied to all requests. |
on_exception
Is executed if an exception is raised while executing the next policy.
This method is executed inside the exception handler.
on_exception(request: PipelineRequest[HTTPRequestType]) -> None
Parameters
Name | Description |
---|---|
request
Required
|
The Pipeline request object |
on_request
Updates with the given request id before sending the request to the next policy.
on_request(request: PipelineRequest[HttpRequest | HttpRequest]) -> None
Parameters
Name | Description |
---|---|
request
Required
|
The PipelineRequest object |
on_response
Is executed after the request comes back from the policy.
on_response(request: PipelineRequest[HTTPRequestType], response: PipelineResponse[HTTPRequestType, HTTPResponseType]) -> None | Awaitable[None]
Parameters
Name | Description |
---|---|
request
Required
|
Request to be modified after returning from the policy. |
response
Required
|
Pipeline response object |
set_request_id
Add the request id to the configuration to be applied to all requests.
set_request_id(value: str) -> None
Parameters
Name | Description |
---|---|
value
Required
|
The request id value. |