EventGrid触发器-如何从Triggerbody设置clienttrackingid?

时间:2019-07-01 20:21:10

标签: azure-logic-apps

在微服务环境中,请求跨多个服务(包括eventgrid),我想配置一个使用correlationid的端到端日志记录。 受此博客https://toonvanhoutte.wordpress.com/2018/08/05/end-to-end-correlation-across-logic-apps/

的启发

如何从事件数据有效负载中使用我的correlationnr配置EventGrid触发器clientTrackingId?

签出我的下面的定义不起作用。 如果我将“ @ {coalesce(json(triggerBody()。Data)?. CorrelationNr,guid())}}”替换为字符串值,甚至用“ @parameters('$ connections')['azureeventgrid'] ['connectionId' ]”,就像魅力一样。

"triggers": {
            "When_a_resource_event_occurs": {
                "correlation": {
                    "clientTrackingId": "@{coalesce(json(triggerBody().Data)?.CorrelationNr, guid())}"
                },
                "inputs": {
                    "body": {
                        "properties": {
                            "destination": {
                                "endpointType": "webhook",
                                "properties": {
                                    "endpointUrl": "@{listCallbackUrl()}"
                                }
                            },
                            "filter": {
                                "includedEventTypes": [
                                    "webhook.sp.updated"
                                ]
                            },
                            "topic": "/subscriptions/xxxx/resourceGroups/xxx/providers/Microsoft.EventGrid/topics/WebHookManager"
                        }
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureeventgrid']['connectionId']"
                        }
                    },
                    "path": "/subscriptions/@{encodeURIComponent('xxx')}/providers/@{encodeURIComponent('Microsoft.EventGrid.Topics')}/resource/eventSubscriptions",
                    "queries": {
                        "x-ms-api-version": "2017-06-15-preview"
                    }
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnectionWebhook"
            }
        }

Logic App不会触发。没有错误消息。

1 个答案:

答案 0 :(得分:1)

请检查有关clientTrackingId的描述,并且您的逻辑应用没有运行历史记录是因为您的triggerBody()没有CorrelationNr且显示的定义。

实际上,您的事件网格触发器已检测到该事件,但无法与逻辑一起运行。您可以转到EVALUATION并检查触发历史记录。这是因为该值为null,然后它将无法运行。

enter image description here

如果使用HTTP请求触发器,则可以设置x-my-custom-correlation-id标头。或在json主体中设置任何键值,然后将clientTrackingId设置为@{coalesce(json(triggerBody())['keyname'], guid())}

如果您使用的是没有标题的触发器,则必须使用字符串或其他参数来指向值,如您所说的connectionid或您自定义的参数值,如下所示。

enter image description here

enter image description here

因此,要点是clientTrackingId必须在运行之前设置好,并且值可以被接受。