Skip to content
13 changes: 11 additions & 2 deletions azure/durable_functions/models/DurableOrchestrationClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def __init__(self, context: str):
async def start_new(self,
orchestration_function_name: str,
instance_id: Optional[str] = None,
client_input: Optional[Any] = None) -> str:
client_input: Optional[Any] = None,
trace_parent: Optional[str] = None,
trace_state: Optional[str] = None) -> str:
"""Start a new instance of the specified orchestrator function.

If an orchestration instance with the specified ID already exists, the
Expand All @@ -62,6 +64,10 @@ async def start_new(self,
the Durable Functions extension will generate a random GUID (recommended).
client_input : Optional[Any]
JSON-serializable input value for the orchestrator function.
trace_parent : str
The traceparent header to send with the request.
trace_state : str
The tracestate header to send with the request.

Returns
-------
Expand All @@ -72,7 +78,10 @@ async def start_new(self,
instance_id=instance_id, orchestration_function_name=orchestration_function_name)

response: List[Any] = await self._post_async_request(
request_url, self._get_json_input(client_input))
request_url,
self._get_json_input(client_input),
trace_parent,
trace_state)

status_code: int = response[0]
if status_code <= 202 and response[1]:
Expand Down
17 changes: 14 additions & 3 deletions azure/durable_functions/models/utils/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import aiohttp


async def post_async_request(url: str, data: Any = None) -> List[Union[int, Any]]:
async def post_async_request(url: str,
data: Any = None,
trace_parent: str = None,
trace_state: str = None) -> List[Union[int, Any]]:
"""Post request with the data provided to the url provided.

Parameters
Expand All @@ -12,15 +15,23 @@ async def post_async_request(url: str, data: Any = None) -> List[Union[int, Any]
url to make the post to
data: Any
object to post
trace_parent: str
traceparent header to send with the request
trace_state: str
tracestate header to send with the request

Returns
-------
[int, Any]
Tuple with the Response status code and the data returned from the request
"""
async with aiohttp.ClientSession() as session:
async with session.post(url,
json=data) as response:
headers = {}
if trace_parent:
headers["x-client-traceparent"] = trace_parent
if trace_state:
headers["x-client-tracestate"] = trace_state
async with session.post(url, json=data, headers=headers) as response:
# We disable aiohttp's input type validation
# as the server may respond with alternative
# data encodings. This is potentially unsafe.
Expand Down
Loading