Azure V1 函数应用,Cosmos DB 触发器,无法查看日志



我正在添加一个简单的 Cosmos DB 函数应用触发器来对添加或更改的文档进行操作,我可以看到我得到了更改源,但随后简单函数崩溃并显示以下输出,我无法弄清楚原因,我不确定如何进一步调试?我还没有在函数本身中添加任何逻辑,因为我想确保我可以在我去那里添加更高级的逻辑之前正确触发基本的更改源。

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:UsersMattDouhanAppDataLocalAzureFunctionsToolsReleases1.4.0cliedgex86edge_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).

函数本身非常简单,如下所示

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);
}
}
}
}

Cosmos DB 触发器确实正常工作且不会崩溃。根据日志记录的连接方式,尝试使用log.Info而不是log.Verbose

部署时验证 Azure 函数日志记录配置,以查看"监视"选项卡是否显示函数执行。以下是应用洞察集成的官方文章:https://github.com/Azure/Azure-Functions/wiki/App-Insights

您应该能够看到查询应用见解的日志:

requests
| where timestamp > ago(30m) 
| summarize count() by cloud_RoleInstance, bin(timestamp, 1m)
| render timechart

最新更新