简体   繁体   中英

CorrelationId in Azure functions v2

I want to have a correlationId to be able to follow a request on Application insights and other places. I have installed the correlationId nuget package on my MVC part of the solution. How do I follow the same Id on my Azure functions?

As an example let's say user calls an API and that API will have a correlationId: xxxx-1 then as a part of the request, it writes to service bus that will be picked up by an Azure function:

[FunctionName("func1")]
public async Task Run([ServiceBusTrigger("topic","subscription", Connection = "ServiceBusConnectionString")] Message message)
{
 log.LogInformation("This is log");
}

How do I apply the correlationId in the function's context?

You can access the correlation id for that message with the CorrelationId property. See here .

[FunctionName("func1")]
public async Task Run([ServiceBusTrigger("topic","subscription", Connection = "ServiceBusConnectionString")]
    Message message)
{
 var id = message.CorrelationId;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM