AzureMapUpdater log stream doesn't show monitoring updates about a digital twins based on sensor template

Anonymous
2022-12-22T13:24:11.653+00:00

Hi,
i'm focusing on building the integration between Event Grid and Azure Account maps, as shown in the followin diagram (I'm following an example from "Hands-on Azure Digial Twins" book):

273274-immagine.png

So i started with building, uploading and creating a map; based on the map i creates a dataset, tileset and a featureset. I updated the feauture set, i setup ad update azure function and published it. I configured application settings and subscribed to event grid. Finally i monitored updates using log stream funcionality in the azure portal.

Here is the ouput result of Log stream:

Connected!
2022-12-22T11:32:44Z [Verbose] Initiating background SyncTriggers operation
2022-12-22T11:38:39Z [Information] Executing ChallengeResult with authentication schemes (ArmToken, WebJobsAuthLevel, Bearer).
2022-12-22T11:39:07Z [Information] Executing ChallengeResult with authentication schemes (ArmToken, WebJobsAuthLevel, Bearer).
2022-12-22T11:39:25Z [Information] Executing ChallengeResult with authentication schemes (ArmToken, WebJobsAuthLevel, Bearer).
2022-12-22T11:40:34Z [Information] Executing ChallengeResult with authentication schemes (ArmToken, WebJobsAuthLevel, Bearer).
2022-12-22T11:41:25Z [Information] Executing StatusCodeResult, setting HTTP status code 200
2022-12-22T11:53:22Z [Verbose] [HostMonitor] Host process CPU stats (PID 5968): History=(0,0,0,0,0), AvgCpuLoad=0, MaxCpuLoad=0
2022-12-22T11:53:22Z [Verbose] [HostMonitor] Host aggregate CPU load 0
2022-12-22T11:53:22Z [Information] Executing StatusCodeResult, setting HTTP status code 200
2022-12-22T12:13:40Z [Verbose] Hosting stopping
2022-12-22T12:13:40Z [Verbose] Stopping file watchers.
2022-12-22T12:13:40Z [Verbose] Waiting for RpcFunctionInvocationDispatcher to shutdown
2022-12-22T12:13:40Z [Verbose] Draining invocations from language worker channel timed out. Shutting down 'RpcFunctionInvocationDispatcher'
2022-12-22T12:13:40Z [Information] Stopping JobHost
2022-12-22T12:13:40Z [Verbose] Stopping ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Information] Stopping the listener 'Microsoft.Azure.WebJobs.Extensions.EventGrid.EventGridListener' for function 'AzureMapUpdater'
2022-12-22T12:13:40Z [Information] Stopped the listener 'Microsoft.Azure.WebJobs.Extensions.EventGrid.EventGridListener' for function 'AzureMapUpdater'
2022-12-22T12:13:40Z [Information] Job host stopped
2022-12-22T12:13:40Z [Verbose] Stopped ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Verbose] Hosting stopped
2022-12-22T12:13:40Z [Verbose] Disposing ScriptHost.
2022-12-22T12:13:40Z [Verbose] Disposing ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Verbose] Disposing FunctionDispatcher
2022-12-22T12:13:40Z [Verbose] Disposed ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Verbose] Host instance 'b30287cbee699cda1201e2d3178d34d3' released lock lease.
2022-12-22T12:13:40Z [Verbose] Disposing ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Verbose] Disposed ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
....

However the updates are very slow and despite the "HTTP status code 200", i can't see any references related to the sensor and any temperature update in the digital twin based on a sensor template has no effect in the logs.

Here is the Azure function code i created using Visual Studio Community 2022 (64 bit) - Current Version17.4.3:

Hi,
i'm focusing on building the integration between Event Grid and Azure Account maps, as shown in the followin diagram (I'm following an example from "Hands-on Azure Digial Twins" book):

273274-immagine.png

So i started with building, uploading and creating a map; based on the map i creates a dataset, tileset and a featureset. I updated the feauture set, i setup ad update azure function and published it. I configured application settings and subscribed to event grid. Finally i monitored updates using log stream funcionality in the azure portal.

Connected!
2022-12-22T11:32:44Z [Verbose] Initiating background SyncTriggers operation
2022-12-22T11:38:39Z [Information] Executing ChallengeResult with authentication schemes (ArmToken, WebJobsAuthLevel, Bearer).
2022-12-22T11:39:07Z [Information] Executing ChallengeResult with authentication schemes (ArmToken, WebJobsAuthLevel, Bearer).
2022-12-22T11:39:25Z [Information] Executing ChallengeResult with authentication schemes (ArmToken, WebJobsAuthLevel, Bearer).
2022-12-22T11:40:34Z [Information] Executing ChallengeResult with authentication schemes (ArmToken, WebJobsAuthLevel, Bearer).
2022-12-22T11:41:25Z [Information] Executing StatusCodeResult, setting HTTP status code 200
2022-12-22T11:53:22Z [Verbose] [HostMonitor] Host process CPU stats (PID 5968): History=(0,0,0,0,0), AvgCpuLoad=0, MaxCpuLoad=0
2022-12-22T11:53:22Z [Verbose] [HostMonitor] Host aggregate CPU load 0
2022-12-22T11:53:22Z [Information] Executing StatusCodeResult, setting HTTP status code 200
2022-12-22T12:13:40Z [Verbose] Hosting stopping
2022-12-22T12:13:40Z [Verbose] Stopping file watchers.
2022-12-22T12:13:40Z [Verbose] Waiting for RpcFunctionInvocationDispatcher to shutdown
2022-12-22T12:13:40Z [Verbose] Draining invocations from language worker channel timed out. Shutting down 'RpcFunctionInvocationDispatcher'
2022-12-22T12:13:40Z [Information] Stopping JobHost
2022-12-22T12:13:40Z [Verbose] Stopping ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Information] Stopping the listener 'Microsoft.Azure.WebJobs.Extensions.EventGrid.EventGridListener' for function 'AzureMapUpdater'
2022-12-22T12:13:40Z [Information] Stopped the listener 'Microsoft.Azure.WebJobs.Extensions.EventGrid.EventGridListener' for function 'AzureMapUpdater'
2022-12-22T12:13:40Z [Information] Job host stopped
2022-12-22T12:13:40Z [Verbose] Stopped ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Verbose] Hosting stopped
2022-12-22T12:13:40Z [Verbose] Disposing ScriptHost.
2022-12-22T12:13:40Z [Verbose] Disposing ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Verbose] Disposing FunctionDispatcher
2022-12-22T12:13:40Z [Verbose] Disposed ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Verbose] Host instance 'b30287cbee699cda1201e2d3178d34d3' released lock lease.
2022-12-22T12:13:40Z [Verbose] Disposing ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
2022-12-22T12:13:40Z [Verbose] Disposed ScriptHost instance 'd7ab58f2-373c-487a-9c8e-ae207b7fc034'.
....

However the updates are very slow and despite the "HTTP status code 200", i can't see any references related to the sensor and any temperature update in the digital twin based on a sensor template has no effect in the logs.

Here is the Azure function code i created using Visual Studio Community 2022 (64 bit) - Current
Version17.4.3:

using System;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;

namespace AzureMapUpdater
{
public class AzureMapUpdater
{

    private static string statesetID = Environment.GetEnvironmentVariable("statesetid");  
    private static string subscriptionKey = Environment.GetEnvironmentVariable("subscriptionkey");  
 
    static async void UpdateMapStateset(string featureId, string value, ILogger log)  
    {  
            HttpClient httpclient = new HttpClient();  
          
            log.LogInformation("$AZUREMAP-START");  
              
            try  
            {  

            var postcontent = new JObject(  
                new JProperty(  
                    "States",  
                    new JArray(  
                        new JObject(  
                            new JProperty("keyName",  
                            "temperature"),  
                            new JProperty("value", value),  
                            new JProperty("eventTimestamp", DateTime.UtcNow.ToString("s"))  
                            )  
                          )  
                    )  
             );  

            log.LogInformation($"AZUREMAP-VALUES FeatureId:{featureId} Value:{value}subscription - Key: {subscriptionKey}");  

            //think it need to be a putasync  
            //var response = await httpClient.PostAsync(  

            var response= await httpclient.PutAsync($"https://eu.atlas.microsoft.com/featurestatesets/{statesetID}/featureStates/{featureId}?api-version=2.0&subscripiont-key={subscriptionKey}", new StringContent(postcontent.ToString()));  
            
            string result = await response.Content.ReadAsStringAsync();  

                log.LogInformation($"AZUREMAP-RESULT:{result}");  
                           
            }  
            catch (Exception ex)   
            {  
                log.LogInformation($"AZUREMAP-UPDATEERROR: {ex.Message}");  
            }  
              
            log.LogInformation($"AZUREMAP-END");  
        }  

    [FunctionName("AzureMapUpdater")]  
    public static void Run([EventGridTrigger] EventGridEvent EventGridEvent, ILogger log)  
    {  

        /*  
           BlobTrigger("samples-workitems/{name}", Connection = "azuremapupdater_string_connection")]Stream myBlob, string name, ILogger log)  
       {  
           log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");  
       }  
        */  

        JObject message = (JObject)JsonConvert.DeserializeObject(EventGridEvent.Data.ToString());  

        string twinId = EventGridEvent.Subject;  
        string modelId = message["data"]["modelId"].ToString();  

        //Parse updates to "space" twins  
        if (modelId == "dtmi.com:smartbuilding:Sensor;1")  
        {  
            //Iterate through the properties that have changed  
            foreach (var operation in message["data"]["patch"])  
            {  
                if (operation["op"].ToString() == "replace" && operation["path"].ToString() == "/temperature")  
                {  
                    string value = operation["value"].ToString();  

                    log.LogInformation($"AZUREMAP-RECEIVED twinId:{twinId} modelId:{modelId} temperaturevalue: {value}");  

                    //Update the maps features stateset  
                    UpdateMapStateset(twinId, value, log);  


                }  
            }  
        }  



    }  
}  

}

The code is correct: there are no errors.

Any suggestions?
Available for all clarifications.
Thanks in advance.
Guido

Azure Digital Twins
Azure Digital Twins
An Azure platform that is used to create digital representations of real-world things, places, business processes, and people.
213 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,112 questions
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
577 questions
{count} votes