Distributed Tracing for Java Azure Functions - Azure/azure-functions-java-worker GitHub Wiki

What is distributed tracing?

Distributed tracing is the equivalent of call stacks for modern cloud and microservices architectures, with the addition of a simplistic performance profiler thrown in. In Azure Monitor, we provide two experiences for consuming distributed trace data. The first is our transaction diagnostics view, which is like a call stack with a time dimension added in. The transaction diagnostics view provides visibility into one single transaction/request, and is helpful for finding the root cause of reliability issues and performance bottlenecks on a per request basis.

Azure Monitor also offers an application map view which aggregates many transactions to show a topological view of how the systems interact, and what the average performance and error rates are.

What is being supported by Java Azure Functions ?

You can now view richer data from your function applications pertaining to the following requests, dependencies, logs and metrics.

How to enable it for Java Function Apps?

Navigate to the functions app Overview blade, go to configurations. Under Application Settings click "+ New application setting". Add the following two application settings with below values, then click Save on the upper left. DONE!

Public Preivew 1

Windows:

  • XDT_MicrosoftApplicationInsights_Java -> 1
  • ApplicationInsightsAgent_EXTENSION_VERSION -> ~2

Linux Dedicated/Premium

  • ApplicationInsightsAgent_EXTENSION_VERSION -> ~3

Linux Consumption

  • APPLICATIONINSIGHTS_ENABLE_AGENT: true

Public Preivew 2

(Just one single appsetting for all OS types and all skus)

  • APPLICATIONINSIGHTS_ENABLE_AGENT: true

What would you expect to see in Application Insights?

  • Application Map - Application Map helps you spot performance bottlenecks or failure hotspots across all components and dependencies of your distributed application.

  • End-to-end transaction monitoring - Use end-to-end transaction monitoring to view one single distributed trace . This enables easy diagnostics for the application component, dependency, or exception that caused a transaction slowdown or failure.

  • Dashboards - Application Insights provides you an overview dashboard to allow quick, at-a-glance assessment of your application's health and performance. The dashboard allows you to drill-down into failures, performance etc.

  • Live Stream Metrics - Live Metrics Stream provides near-real-time performance indicators to make sure everything works as expected. Live stream can be used for various scenarios such as to validate a fix while it is released, by watching performance and failure counts, or observing the effect of test loads, and diagnosing issues live.

  • Smart Detection - Smart detections needs no configuration and provides automatic alerts that adapt to your app's normal patterns of telemetry and trigger when there's something outside the usual pattern.

  • Metrics Explorer - Explore, filter, and segment aggregated data such as rates of requests, failures, and exceptions, response times, and page load times.

  • Analytics - Answer tough questions about your app's performance and usage with KQL – a powerful query language.

Customize Distribute Agent

If you don't want to use the default version of distribute agent, you can follow below steps to point to a specific version of distribute agent.

  1. Get the target agent jar and put it into your project directory.
  2. Create an empty file functions.codeless and put it at the same location as 1
  3. Use maven plugin maven-resources-plugin to copy the agent jar into the build directory. Example:
<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <overwrite>true</overwrite>
                <outputDirectory>${stagingDirectory}</outputDirectory>
                <resources>
                    <resource>
                        <directory>${project.basedir}</directory>
                        <includes>
                            <include>applicationinsights-agent-3.3.2-SNAPSHOT.jar</include>
                            <include>functions.codeless</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

The ${stagingDirectory} has value

<stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}</stagingDirectory>
  1. Redeploy the function app by running mvn azure-functions:deploy.
  2. Remove appsetting accordingly at here and Add a new appsetting to point to the target agent in azure portal
    • For dedicate and elasticpremium plan add appsetting JAVA_OPTS with value -javaagent:applicationinsights-agent-3.3.2-SNAPSHOT.jar
    • For Windows consumption plan add appsetting languageWorkers:java:arguments with value -javaagent:applicationinsights-agent-3.3.2-SNAPSHOT.jar -DaiAgentOptOut
    • For Linux consumption plan add appsetting languageWorkers__java__arguments with value -javaagent:applicationinsights-agent-3.3.2-SNAPSHOT.jar -DaiAgentOptOut

Note: please wait few mins after you update the appsetttings. It takes some time to restart the worker process.

appsetting
  1. After all those steps, the customized applicationn insight agent will be the agent in use.

Few things to keep in mind:

  • This feature is currently in public preview for Java Azure Functions, and has a cold start implication of 8-9 seconds in the Windows Consumption plan. For Linux Consumption plan there will be no cold start implication.
  • We would love to hear if you find this feature useful for your scenario and any other feedback that you may have so as to improve on its various aspects. We will consider making this functionality available out of the box by default with an optimized cold start based on demand.

Feedback

You can reach out to us with any feedback on [email protected]

⚠️ **GitHub.com Fallback** ⚠️