Azure V1 Function App, Cosmos DB trigger, unable to see logs

1

I am adding a simple Cosmos DB function app trigger to act on documents added or changed, I can see that I get the change feed but then the simply function crashes with the following output and I cannot figure out why and I am unsure how to debug this further? I have not yet added any logic into the function itself as I want to make sure I can get the basic change feed to trigger properly before I go and add more advanced logic there.

DocDBTrace Information: 0 : DocumentClient with id 1 initialized at endpoint: https://nwcloud-trstore-test.documents.azure.com/ with ConnectionMode: Direct, connection Protocol: Tcp, and consistency level: null
'func.exe' (CLR v4.0.30319: func.exe): Loaded '\\?\C:\Users\MattDouhan\AppData\Local\AzureFunctionsTools\Releases\1.4.0\cli\edge\x86\edge_nativeclr.node'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations
DocDBTrace Information: 0 : Set WriteEndpoint https://nwcloud-trstore-test-northeurope.documents.azure.com/ ReadEndpoint https://nwcloud-trstore-test-northeurope.documents.azure.com/
DocDBTrace Information: 0 : DocumentClient with id 2 initialized at endpoint: https://nwcloud-trstore-test.documents.azure.com/ with ConnectionMode: Direct, connection Protocol: Tcp, and consistency level: null
DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations
DocDBTrace Information: 0 : Set WriteEndpoint https://nwcloud-trstore-test-northeurope.documents.azure.com/ ReadEndpoint https://nwcloud-trstore-test-northeurope.documents.azure.com/
func.exe Warning: 0 : Added stats for partition '0' for which the lease was picked up after the host was started.
The thread 0x4b2c has exited with code 0 (0x0).
The thread 0x3d74 has exited with code 0 (0x0).
The thread 0x15c8 has exited with code 0 (0x0).
The thread 0x442c has exited with code 0 (0x0).
The thread 0x31f0 has exited with code 0 (0x0).
The thread 0x5f4 has exited with code 0 (0x0).
The thread 0x2f10 has exited with code 0 (0x0).
The thread 0x678 has exited with code 0 (0x0).
The thread 0x1b94 has exited with code 0 (0x0).
The thread 0x5a0 has exited with code 0 (0x0).
The thread 0x2558 has exited with code 0 (0x0).
The thread 0x37b4 has exited with code 0 (0x0).
The thread 0x286c has exited with code 0 (0x0).
The thread 0x4cc has exited with code 0 (0x0).
The thread 0x30cc has exited with code 0 (0x0).
The thread 0x3884 has exited with code 0 (0x0).
The thread 0x330 has exited with code 0 (0x0).
The thread 0x4240 has exited with code 0 (0x0).
DocDBTrace Error: 0 : DocumentClientException with status code PreconditionFailed, message: Message: {"Errors":["One of the specified pre-condition is not met"]}, inner exception: null, and response headers: {
"x-ms-last-state-change-utc": "Fri, 21 Sep 2018 22:56:50.384 GMT",
"lsn": "27",
"x-ms-schemaversion": "1.6",
"x-ms-quorum-acked-lsn": "27",
"x-ms-current-write-quorum": "3",
"x-ms-current-replica-set-size": "4",
"x-ms-documentdb-partitionkeyrangeid": "0",
"x-ms-xp-role": "1",
"x-ms-request-charge": "1.24",
"x-ms-serviceversion": " version=2.0.0.0",
"x-ms-activity-id": "11848201-4229-4723-9271-b22e5a2ef0a1",
}
DocDBTrace Error: 0 : Operation will NOT be retried. Current attempt 0, Exception: Microsoft.Azure.Documents.PreconditionFailedException: Message: {"Errors":["One of the specified pre-condition is not met"]}
ActivityId: 11848201-4229-4723-9271-b22e5a2ef0a1, Request URI: rntbd://cdb-ms-prod-northeurope1-fd11.documents.azure.com:14126/apps/4bfa4180-1add-4ab6-9446-56e102bf3194/services/ab30350b-a783-4963-a901-2e32760be93f/partitions/1ee407af-d621-4529-959a-ae738aa64194/replicas/131816515549144981p/
   at Microsoft.Azure.Documents.RntbdTransportClient.ThrowIfFailed(String resourceAddress, StoreResponse storeResponse, Uri physicalAddress, Guid activityId)
   at Microsoft.Azure.Documents.RntbdTransportClient.<InvokeStoreAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<WriteAsync>d__1b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<InvokeAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<>c__DisplayClass1.<<InvokeAsync>b__0>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClassf`1.<<ExecuteAsync>b__d>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__1b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__1b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteAsync>d__18`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<InvokeAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.StoreClient.<ProcessMessageAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.Client.DocumentClient.<UpdateAsync>d__320.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.Client.DocumentClient.<ReplaceDocumentPrivateAsync>d__13a.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.Client.DocumentClient.<ReplaceDocumentPrivateAsync>d__132.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClass2.<<ExecuteAsync>b__0>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__1b.MoveNext() 
The program '[17072] func.exe' has exited with code -1 (0xffffffff).

The function itself is very simple as follows

using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

namespace NWCloudTransactionEventHandler
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([CosmosDBTrigger(
            databaseName: "XXX",
            collectionName: "YYY",
            ConnectionStringSetting = "CosmosDb",
            LeaseCollectionName = "leases")]IReadOnlyList<Document> documents, TraceWriter log)
        {
            if (documents != null && documents.Count > 0)
            {
                log.Verbose("Documents modified " + documents.Count);
                log.Verbose("First document Id " + documents[0].Id);
            }
        }
    }
}
azure-functions
azure-cosmosdb
asked on Stack Overflow Sep 25, 2018 by Matt Douhan • edited Sep 25, 2018 by Matt Douhan

1 Answer

0

The Cosmos DB Trigger is indeed working and not crashing. Depending on how the logging is wired up, try with log.Info instead of log.Verbose.

Verify your Azure Functions logging configuration when deployed to see if the Monitor tab shows the Function executions. Here is the official article for the App Insights integration: https://github.com/Azure/Azure-Functions/wiki/App-Insights

You should be able to see the logs querying the App Insights:

requests
| where timestamp > ago(30m) 
| summarize count() by cloud_RoleInstance, bin(timestamp, 1m)
| render timechart
answered on Stack Overflow Sep 25, 2018 by Matias Quaranta

User contributions licensed under CC BY-SA 3.0