Durable Function Doesn't Correlate Telemetry - c#

According to this developer blog post
Durable functions can be configured (and according the the host.json schema are configured by default) to automatically create and correlate trace telemetry with the W3C tracing protocol.
Currently, my host.json looks like this, and includes the properties shown in the blog.
{
"version": "2.0",
"logging": {
"applicationInsights": {
"httpAutoCollectionOptions": {
"enableW3CDistributedTracing": true
},
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
},
"logLevel": {
"default": "Information",
"blueprints_webcp_gateway": "Debug"
}
},
"functionTimeout": "00:10:00",
"extensions": {
"queues": {
"visibilityTimeout": "00:00:10",
"batchSize": 4
},
"durableTask": {
"tracing": {
"DistributedTracingProtocol": "W3CTraceContext"
}
}
}
}
Yet, when I go to the Activity Log page in Azure Portal, each orchestrator and activity shows up as its own operation, which is definitely not what I'm expecting to see. Is any additional configuration needed? As far as I can tell, telemetry logged by the durable function host should be correlated by default.

I face same issue and have exactly same results(durable functions traces have different OperationId). Have not found the solution in bigger project I am working on. We have created smaller project to try full end-to-end functionality in more clear environment. I found out that some packages may break the correlation of DF traces f.e. (System.DiagnosticTool >= 4.7.0, MS.Azure.ServiceBus - this SDK is whole deprecated, ...) But there is a light in the end of the tunnel. When I have upgraded each package, target framework and version of Azure functions everything was working correctly in our smaller project. To update everything and make it work in bigger project will be another challenge.

Related

How do I disable Application Insights logging in Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" and upper?

I have an Asp.Net Core 6 Web Api.
I added Application Insights to it and I have stored the Connection string in a local Secrets.json file as is recommended.
I don't want to send telemetry when in debug while I am still developing the app.
I want to be able to switch it on and off while I develop.
What is the best way to do it?
The first thing that comes to my mind is to adjust the log level in appsettings.Development.json:
"ApplicationInsights": {
"LogLevel": {
"Default": "None"
}
}
I see this question here, but all the answers seem outdated because in the documentation it is recommended to make the configurations in appsettings.json, NOT in the code.
Is there a better alternative for Asp.net Core 6 and Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" than putting the LogLevel to none?
Edit: I use Secrets.json file as recommended here to store the connection string locally.
You could just not set the instrumentation key in debug/development mode so the telemetry is not send to azure but still visible in the Visual Studio tool

Azure Funtions C# How to log custom messages from a class using reflection to azure monitoring logs or analytics monitorlng logs

I'm using WebJobsStartup with my azure function. In Startup.cs file , I'm loading say abc.dll from my another project using reflection and invoking it's main method. I want to get logs from this called method(abc.dll) along with HttpTrigger function.
In main method of abc.dll, I'm using ILogger to log messages and same with my azure function.
When I deploy this function to azure (Azure functions), I'm able to see logs related to azure function only and not of abc.dll (called method). I have checked that abc.dll is getting loaded (by calling logging on webpage)
I've tried application insights and live metrics, updated host.json as various options provided at in documentation of Azure links below:
"fileLoggingMode": "debugOnly",
"logLevel": {
"Function.HttpTriggerAzureCSharp1":"Information",
"Host.Results": "Error",
"Host.Aggregator": "Trace",
"default": "Information"
},
which seems not working.
Please suggest options to show logs of abc.dll (called method) with azure function.
I am using azure funtions with below details:
OS : Linux
Plan : consumption
Platform : .net-core
Dev Env:Visual Studio Code
Language : C#
I have already tried this this2
As Peter mentioned in comments, you can register them in DI configuration of the function.
Here is a sample for your reference, you can refer to it to know how to develop the code of your service and log provider.

Turn off HttpClient Logging in .net core 3.1 [duplicate]

When using the HttpClientFactory of .NET Core, is it possible to somehow remove the default LoggingHttpMessageHandler?
I expect something like the below but it doesn't seem to exists
services.AddHttpClient("minos")
.RemoveHttpMessageHandler<LoggingHttpMessageHandler>();
You can configure it in appsettings.json by setting HttpClient's log level to none:
However, this will also enable informational messages from all other
components in the System root namespace. Therefore it may be better to
configure the logging by limiting the configuration to
“System.Net.Http.HttpClient” so that you only add in the messages from
the HTTP requests through clients created via the HttpClientFactory:
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"System.Net.Http.HttpClient": "Information"
}
}
}
https://www.stevejgordon.co.uk/httpclientfactory-asp-net-core-logging
Just for anyone needing this, I had opened an issue on the GitHub repo, and one of the contributors had replied with the following
services.RemoveAll<IHttpMessageHandlerBuilderFilter>();
Just Add this line AFTER the adding of the HttpClient
Make sure to use Microsoft.Extensions.DependencyInjection.Extensions namespace
https://github.com/aspnet/HttpClientFactory/issues/196#issuecomment-432755765

Disable Attribute nor Application Settings on HttpTrigger Azure Function not working

I've implemented an Azure Function (v2 running on .Net Core 2.2) triggered by an HttpTrigger. Upon specifying either the Disable attribute or using the Application Settings ("AzureWebJobs.Function1.Disabled": "true"), I'm still able to hit this endpoint through Postman. This is ONLY happening with HttpTriggers. The ChangeFeed Triggers and QueueTriggers I am also using, are working as expected.
A few things I've tried when running locally:
1. Withing local.settings.json, I've added just the AzureWebJobs..Disabled value
2. I've added the Disable attribute
3. I've added the Disable attribute with a setting defined.
When starting up the function project, the console does show "Function Function1 is disabled."
I've tried it with my local.settings.json as such
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobs.Function1.Disabled": "true"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
}
}
The Function has a general format as such:
[Disable, FunctionName("Function1")]
public async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
Binder binder, ILogger log)
{}
I would think I would receive a 404 within Postman. Any thoughts, direction, or other information is appreciated.
I could repro your issue as well. Despite the log saying that the function is disabled, you can still call the HTTP trigger. Looks like a bug to me. I opened an issue on Github here: https://github.com/Azure/azure-functions-host/issues/4764
Update from the github issue:
Does this only happen when running locally with the CLI (or VS)? Http
requests should return 404s unless invoked via an Admin request --
this allows the portal to continue to be able to test functions. When
running via the CLI, though, I believe all requests are treated as
admin requests.
Yes, I can confirm this is indeed different when deployed in Azure.
When I use the app setting there AND use the function key (not the
master key), the call returns 404.
I test local and got the same result as yours, and I found it could not only disable HTTP trigger function, if disable other like Timer function simultaneously, only HTTP could run. But I test with Azure It will respond 404.
So maybe you could use host.json to disable it, actually it should say run functions you want. If you only have only one or want to disable all functions, you could set the array with null string like below code.
{
"functions": [ null ],
"version": "2.0"
}
Or like this to only run Function2 then disable Function1 :
{
"functions": [ "Function2" ],
"version": "2.0"
}
Hope this could help you.
You can also disable by going to the portal:

Remove http client logging handler in ASP.NET Core

When using the HttpClientFactory of .NET Core, is it possible to somehow remove the default LoggingHttpMessageHandler?
I expect something like the below but it doesn't seem to exists
services.AddHttpClient("minos")
.RemoveHttpMessageHandler<LoggingHttpMessageHandler>();
You can configure it in appsettings.json by setting HttpClient's log level to none:
However, this will also enable informational messages from all other
components in the System root namespace. Therefore it may be better to
configure the logging by limiting the configuration to
“System.Net.Http.HttpClient” so that you only add in the messages from
the HTTP requests through clients created via the HttpClientFactory:
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"System.Net.Http.HttpClient": "Information"
}
}
}
https://www.stevejgordon.co.uk/httpclientfactory-asp-net-core-logging
Just for anyone needing this, I had opened an issue on the GitHub repo, and one of the contributors had replied with the following
services.RemoveAll<IHttpMessageHandlerBuilderFilter>();
Just Add this line AFTER the adding of the HttpClient
Make sure to use Microsoft.Extensions.DependencyInjection.Extensions namespace
https://github.com/aspnet/HttpClientFactory/issues/196#issuecomment-432755765

Categories