【问题标题】:Azure V1 Function App, Cosmos DB trigger, unable to see logsAzure V1 函数应用,Cosmos DB 触发器,看不到日志
【发布时间】:2018-09-25 06:19:57
【问题描述】:

我正在添加一个简单的 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:\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).

函数本身很简单如下

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

【问题讨论】:

  • 您的 Lease 集合是否已分区?
  • 不,这是一个单独的分区,我只是把它设为最小的尝试一下
  • 您可以尝试从 Lease 集合中删除所有文档并重新启动吗?它似乎正在读取一组现有的租约。
  • 我删除了租约集合中的文档,当我启动应用程序时,它立即崩溃,说未找到内部异常资源,但它确实将两个文档写入租约集合,然后重新启动应用程序时我得到了又是原来的错误
  • 这确实很奇怪,你能把第一个和第二个错误日志发送到通常微软域的maquaran吗?另外,您使用的是哪个版本的 Webjobs Extensions DocumentDB 包,是最新的吗?

标签: azure-functions azure-cosmosdb


【解决方案1】:

Cosmos DB 触发器确实在工作并且没有崩溃。根据日志的连接方式,尝试使用log.Info 而不是log.Verbose

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

您应该能够看到查询 App Insights 的日志:

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

【讨论】:

  • 在控制台中运行它时在本地工作,但是当发布到 Azure 时,日志中没有任何内容,我查看了另一个具有完全相同日志设置的 HTTP 函数,它确实有效为什么 cosmos 触发函数不会写入 azure 日志,这令人困惑
猜你喜欢
  • 2023-01-31
  • 2022-06-23
  • 1970-01-01
  • 2019-01-04
  • 2020-05-14
  • 1970-01-01
  • 1970-01-01
  • 2021-10-03
  • 1970-01-01
相关资源
最近更新 更多