Can all communication logs between devices and the cloud be obtained from IoT Hub logs, associated with each device ID?

KURAMOTOAHUJATAIRA-3118 250 Reputation points
2023-05-11T11:16:45.6033333+00:00

Is it possible to retrieve all communication logs between devices and the cloud in IoT Hub's logs associated with device IDs? I want to count the number of communications between each device and the cloud.

I have tried the following query and confirmed that I can retrieve the Connect/Disconnect logs for the devices:

AzureDiagnostics
| where ResourceProvider == "MICROSOFT.DEVICES" and ResourceType == "IOTHUBS"
| where Category == "Connections"

However, when I tried to retrieve the logs for direct methods using the following query within the date range in which I sent the direct methods to the devices, no results were returned:

AzureDiagnostics
| where ResourceProvider == "MICROSOFT.DEVICES" and ResourceType == "IOTHUBS"
| where Category == "DirectMethods"

Could you please let me know if there is anything you can share on this matter? Thank you.

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,146 questions
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 13,951 Reputation points
    2023-05-11T15:24:14.0433333+00:00

    Hi @KURAMOTOAHUJATAIRA-3118 Greetings! Thank you for posting the question on this forum.

    Inspect the Diagnostic settings of the Azure IoT Hub and verify if Direct Methods category is enabled to be logged into the Diagnostic logs? To check this, navigate to the Diagnostic Settings under the Monitoring section of the Azure IoT Hub. If you have an existing set up that is created to log the events, Edit it to check if Direct Method is selected. Refer the below image for details.

    User's image

    User's image

    Kindly note that the approach of your DirectMethod implementation impacts the Category of the event logs. For example, if you create the Direct method using the azure-iot-device.Client class to design Direct Method, the event generated when the method is triggered will be categorized as DirectMethods. However, if you use azure-iothub.JobClient class to create a job, the generated event will be categorized as JobsOperations.

    Please refer the following resources for reference.

    Let us know if you have any additional questions or need further clarification in the comments below.


    If the response helped, please do click Accept Answer and Yes. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful