Use distributed tracing with Azure Spring Apps (deprecated)

Note

Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.

Note

Distributed Tracing is deprecated. For more information, see Application Insights Java In-Process Agent in Azure Spring Apps.

With the distributed tracing tools in Azure Spring Apps, you can easily debug and monitor complex issues. Azure Spring Apps integrates Spring Cloud Sleuth with Azure's Application Insights. This integration provides powerful distributed tracing capability from the Azure portal.

In this article, you learn how to enable a .NET Core Steeltoe app to use distributed tracing.

Prerequisites

To follow these procedures, you need a Steeltoe app that is already prepared for deployment to Azure Spring Apps.

Dependencies

For Steeltoe 2.4.4, add the following NuGet packages:

For Steeltoe 3.0.0, add the following NuGet package:

Update Startup.cs

  1. For Steeltoe 2.4.4, call AddDistributedTracing and AddZipkinExporter in the ConfigureServices method.

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDistributedTracing(Configuration);
        services.AddZipkinExporter(Configuration);
    }
    

    For Steeltoe 3.0.0, call AddDistributedTracing in the ConfigureServices method.

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDistributedTracing(Configuration, builder => builder.UseZipkinWithTraceOptions(services));
    }
    
  2. For Steeltoe 2.4.4, call UseTracingExporter in the Configure method.

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
         app.UseEndpoints(endpoints =>
         {
             endpoints.MapControllers();
         });
         app.UseTracingExporter();
    }
    

    For Steeltoe 3.0.0, no changes are required in the Configure method.

Update configuration

Add the following settings to the configuration source that will be used when the app runs in Azure Spring Apps:

  1. Set management.tracing.alwaysSample to true.

  2. If you want to see tracing spans sent between the Eureka server, the Configuration server, and user apps: set management.tracing.egressIgnorePattern to "/api/v2/spans|/v2/apps/./permissions|/eureka/.|/oauth/.*".

For example, appsettings.json would include the following properties:

"management": {
    "tracing": {
      "alwaysSample": true,
      "egressIgnorePattern": "/api/v2/spans|/v2/apps/.*/permissions|/eureka/.*|/oauth/.*"
    }
  }

For more information about distributed tracing in .NET Core Steeltoe apps, see Distributed tracing in the Steeltoe documentation.

In this article, you learn how to:

  • Enable distributed tracing in the Azure portal.
  • Add Spring Cloud Sleuth to your application.
  • View dependency maps for your Spring applications.
  • Search tracing data with different filters.

Prerequisites

To follow these procedures, you need an Azure Spring Apps service that is already provisioned and running. Complete the Deploy your first Spring Boot app in Azure Spring Apps quickstart to provision and run an Azure Spring Apps service.

Add dependencies

  1. Add the following line to the application.properties file:

    spring.zipkin.sender.type = web
    

    After this change, the Zipkin sender can send to the web.

  2. Skip this step if you followed our guide to preparing an application in Azure Spring Apps. Otherwise, go to your local development environment and edit your pom.xml file to include the following Spring Cloud Sleuth dependency:

    • Spring boot version < 2.4.x.

      <dependencyManagement>
          <dependencies>
              <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-sleuth</artifactId>
                  <version>${spring-cloud-sleuth.version}</version>
                  <type>pom</type>
                  <scope>import</scope>
              </dependency>
          </dependencies>
      </dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-starter-sleuth</artifactId>
          </dependency>
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-starter-zipkin</artifactId>
          </dependency>
      </dependencies>
      
    • Spring boot version >= 2.4.x.

      <dependencyManagement>
          <dependencies>
            <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-sleuth</artifactId>
                  <version>${spring-cloud-sleuth.version}</version>
                  <type>pom</type>
                  <scope>import</scope>
              </dependency>
          </dependencies>
      </dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-starter-sleuth</artifactId>
          </dependency>
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-sleuth-zipkin</artifactId>
           </dependency>
      </dependencies>
      
  3. Build and deploy again for your Azure Spring Apps service to reflect these changes.

Modify the sample rate

You can change the rate at which your telemetry is collected by modifying the sample rate. For example, if you want to sample half as often, open your application.properties file, and change the following line:

spring.sleuth.sampler.probability=0.5

If you have already built and deployed an application, you can modify the sample rate. Do so by adding the previous line as an environment variable in the Azure CLI or the Azure portal.

Enable Application Insights

  1. Go to your Azure Spring Apps service page in the Azure portal.
  2. On the Monitoring page, select Distributed Tracing.
  3. Select Edit setting to edit or add a new setting.
  4. Create a new Application Insights query, or select an existing one.
  5. Choose which logging category you want to monitor, and specify the retention time in days.
  6. Select Apply to apply the new tracing.

View the application map

Return to the Distributed Tracing page and select View application map. Review the visual representation of your application and monitoring settings. To learn how to use the application map, see Application Map: Triage distributed applications.

Use the search function to query for other specific telemetry items. On the Distributed Tracing page, select Search. For more information on how to use the search function, see Using Search in Application Insights.

Use Application Insights

Application Insights provides monitoring capabilities in addition to the application map and search function. Search the Azure portal for your application's name, and then open an Application Insights page to find monitoring information. For more guidance on how to use these tools, check out Azure Monitor log queries.

Disable Application Insights

  1. Go to your Azure Spring Apps service page in the Azure portal.
  2. On Monitoring, select Distributed Tracing.
  3. Select Disable to disable Application Insights.

Next steps

In this article, you learned how to enable and understand distributed tracing in Azure Spring Apps. To learn about binding services to an application, see Bind an Azure Cosmos DB database to an application in Azure Spring Apps.