Azure / Azure/azure-iot-sdk-csharp
[feature request] Provide the ability to pass along the requestId when invoking DirectMethods
- Dominant language
- C#
- Stars
- 477
- Forks
- 492
- Avg merge
- 9h 55m
- Merged PRs (30d)
- 2
Description
In our IoThub solution we make use of the functionality of DirectMethods with the C# sdk.
Some pseudo code
```
var methodInvocation = new CloudToDeviceMethod("SomeCommand", TimeSpan.FromSeconds(_deviceMethodResponseTimeoutInSeconds));
methodInvocation.SetPayloadJson(JsonSerializer.Serialize("CommandContent"));
var response = await _iothubServiceClient.InvokeDeviceMethodAsync(gatewayNo, methodInvocation);
```
For troubleshooting purposes, we would like to pass along a unique identifier to this request - so that both on Cloud side as on Embedded side audit log's can be created and in case of errors that we can correlate them.
Currently the Cloud2DeviceMethod or the ServiceClient does not expose any overload to pass along properties.
While in the source code - the requestId is in one of the internal classes.
```
internal MethodRequestInternal(string name, string requestId, Stream bodyStream, CancellationToken cancellationToken)
: this(cancellationToken)
```
On this page (https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-direct-methods) there is a section on how to invoke a DirectMethod with a HTTP post
`Headers that contain the authorization, request ID, content type, and content encoding`
From this I understand that the api's allow passing a request-id
I think having an overload to pass-along
- system properties - a messageId property is described in C2D messages - https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-construct like correlation-id
- custom properties - custom key/value property bag
Without a solution to dynamically assign identifiers to requests, we are forced to put this request in the body of the request message, while this is only for tracing and has nothing to do with the business case.
Contributor guide
Assessment
This issue has not been assessed yet.