1

As part of a Microservice based solution that we are building we have a number of Azure Functions sitting in one Azure Function App. The functions Orchestrate numerous requests to different APIs some of which take a long time to complete. We added Application Insights to the functions to allow for some tracking of the requests made, but dependency tracking is not working yet in Azure Functions. It is possible to manually track dependencies but that involves inserting some tracking code around each dependency call, however we want to avoid manually tracking dependencies on each and every call.

One of the solutions I have thought of would be to create a request tracker that tracks all outgoing web requests from the functions. Within the request tracker I could then track the dependency requests including their time. I want to hook the request tracker into some sort of web traffic handler, unfortunately I was unable to find much about doing this. A lot of posts mention using System.Net trace writer for this, but as far as I can see this requires a Web.config to setup and functions do not have one.

I have seen a few posts mentioning to create a request wrapper and place that on my outgoing requests, but unfortantely that is not an option as we use a number of packages that make requests internally. If you have any ideas that could get me going in the right direction please let me know. Thanks


Update:

I added the following helper method which allows me to manually track tasks as dependency requests

 public static async Task<T> TrackDependency<T>(this Task<T> task, string dependecyName, string callName, string operationId)
    {
        var telemtryClient = new TelemetryClient();
        var startTime = DateTime.UtcNow;
        var timer = System.Diagnostics.Stopwatch.StartNew();
        var success = true;
        T result = default(T);
        try
        {
            result = await task;
        }
        catch (Exception)
        {
            success = false;
        }
        finally
        {
            timer.Stop();
            var dependencyTelemetry = new DependencyTelemetry(dependecyName, callName, startTime, timer.Elapsed, success);
            dependencyTelemetry.Context.Operation.Id = operationId;
            telemtryClient.Track(dependencyTelemetry);
        }
        return result;
    }

It can then be used as follows:

client.Accounts.UpdateWithHttpMessagesAsync(accountId, account).TrackDependency("Accounts", "UpdateAccounts", requestContextProvider.CorrelationId);

I can now see individual request dependencies in Application Insights, but obviously the actual telemetry on them is very limited, it does not contain path info or much else.

ObiEff
  • 640
  • 8
  • 24

1 Answers1

1

So when you say dependency tracking is not working in Azure Functions, what exactly do you mean? Have you actually added and configured the Application Insights SDK to your actual function yet? The out-of-the-box monitoring experience with Azure Functions doesn't automatically add dependency tracing, but if you actually add/configure the Application Insights SDK in your function project it should start tracking everything going on in there.

Drew Marsh
  • 33,111
  • 3
  • 82
  • 100
  • Well, what I mean is that I followed the guide I found for configuring Application Insights in Azure functions. After configuring it I can see telemetry flowing through, but cannot see dependencies. I did some digging and found that it was a known issue as mentioned on the github. I have added the SDK to the function and all dependencies as required. I assume you need to convert the AppInsights.Config into a code based initialization? If it's a matter of adding the telemetry initializers and associated bits, that seems like a fairly simple fix – ObiEff Feb 27 '18 at 09:42
  • I've added in dependency tracking throught the extension method I have put in my original post, this gives me a bit of information about the dependencies but, it has to be placed on each call and I do not think it is a good solution since it does not actually provide me with much information about the request – ObiEff Feb 28 '18 at 09:57