Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
737 stars 358 forks source link

No dependency telemetry logging in custom binding attribute #2928

Open vrooijen opened 1 year ago

vrooijen commented 1 year ago

I've created a custom binding attribute as described here and here In this binding a http call is executed, which doesn't show up as a dependency in Application Insights, however TraceTelemetry is visible. Also tried to implement TelementryClient and use TrackDependency manually like described here but this it still won't show up.

When executing the http call in the function itself, and also the custom TrackDependency execution, both show up in Application Insights

Azure Function version v4 linuxFxVersion DOTNET|6.0

image

sampling is disabled in host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false
      }
    },
    "logLevel": {
      "default": "Information",
      "Host.Results": "Information",
      "Function": "Information",
      "Host.Aggregator": "Information"
    }
  }
}
ramya894 commented 1 year ago

@vrooijen We will check this issue with our next level team and update you.

jviau commented 1 year ago

Thank you for bringing this to our attention. This is not entirely unexpected with how our observability works today. The HTTP call made in your function directly and in the custom binding happen at completely different points in time during the function invocation. In v4, they may also even happen in different processes (host vs worker). It is interesting the explicit TrackDependency call is not working at all. Does the TrackDependency call work for you in other parts of the application?

We are working on improving our observability, and this is something we can definitely evaluate as part of that work. I see value in having this properly correlated.

vrooijen commented 1 year ago

Yes so in the binding attribute TrackTrace is working, but not TrackDependency (this is noticed because HttpClient also doens't track dependencies in Application Insights in the custom binding)

In the function itself, both are working

However this is not only on Azure but also when debugging locally, I guess in that case it woudn't be a different process right?

vrooijen commented 1 year ago

I've created an repo to reproduce this https://github.com/vrooijen/CustomBindingAttribute Notice the MyLogic.Track method is called twice, once in the CustomBindingAttribute and once in the function itself.

I've noticed, when the APPINSIGHTS_INSTRUMENTATIONKEY setting is not configured in the local.settings.json, it does output someting when calling TrackDependency, strangey there is not any record of this when the instrumentationkey is configured, however in the function itself it does work als described previously

All able to reproduce both in Azure as well as running locally

Application Insights Telemetry (unconfigured): {"name":"AppDependencies","time":"2022-11-03T13:25:31.4313764Z","tags":{"ai.cloud.roleInstance":"*","ai.internal.sdkVersion":"azurefunctionscoretools: 4.0.4829"},"data":{"baseType":"RemoteDependencyData","baseData":{"ver":2,"name":"http://localhost","id":"99b12e28faa02df9","data":"/api","duration":"00:00:00.1000000","success":true,"type":"HTTP"}}}

jviau commented 1 year ago

Can you clarify for me:

When executing the http call in the function itself, and also the custom TrackDependency execution, both show up in Application Insights however in the function itself it does work als described previously

Do you mean when you make the manual .TraceDependency() call within your function body, does it show up in Application Insights or not? And in your shared repro, does the TrackDependency in MyLogic.Track() work? If you can provide a table of scenario and app insights call (trace, dependency, etc) and the result that would be helpful.

vrooijen commented 1 year ago

In binding: tracktrace is working, trackdependency is not In function: both are working

mindraptor commented 1 year ago

Any update on this issue? I am also missing dependency tracking in app insights. A workaround would also be appreciated :)