Skip to content

Observability with Spring :: Learn how to send application metrics to Tanzu Observability

License

Notifications You must be signed in to change notification settings

spring-guides/gs-tanzu-observability

This guide walks you through your first Spring Boot project with Tanzu Observability by Wavefront.

What You Will Build

You will create a simple web application and configure it to send metrics to a freemium cluster.

Starting with Spring Initializr

You can use this pre-initialized project and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.

If you want to initialize the project manually, follow the steps given below:

  1. Navigate to https://start.spring.io. This service pulls in all the dependencies you need for an application and does most of the setup for you.

  2. Select your favorite build system and language. This guide assumes you’ve selected Java and Maven.

  3. Click Add dependencies and select Spring Web and then Wavefront.

  4. Click Generate. You download a ZIP file, which is an archive of a web application that includes Tanzu Observability.

Note
If your IDE has the Spring Initializr integration, you can complete the steps above from your IDE.

Out-of-the-Box Observability

Follow these steps to start the project and to automatically send several auto-configured metrics to Tanzu Observability by Wavefront.

  1. Add the Wavefront for Spring Boot 3 starter to the Maven dependencies. Open the pom.xml and add the following to the <dependencies> block:

    <dependency>
      <groupId>com.wavefront</groupId>
      <artifactId>wavefront-spring-boot-starter</artifactId>
      <version>3.0.1</version>
    </dependency>
  2. Before you start the service, configure the project so that you can identify the metrics sent by the application and service. Open the application.properties file and add the following:

    management.wavefront.application.name=demo
    management.wavefront.application.service-name=getting-started
    Note
    The properties above configure the integration to send metrics to Tanzu Observability by Wavefront using the demo application and the getting-started service. An application can consist of an arbitrary number of microservices.
  3. Run the application from your IDE by invoking the main method of DemoApplication. You see the following:

    INFO 58371 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint(s) beneath base path '/actuator'
    INFO 58371 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
    INFO 58371 --- [           main] hello.DemoApplication                    : Started DemoApplication in 1.705 seconds (process running for 2.038)
    
    A Wavefront account has been provisioned successfully and the API token has been saved to disk.
    
    To share this account, make sure the following is added to your configuration:
    
        management.wavefront.api-token=ee1f454b-abcd-efgh-1234-bb449f6a25ed
        management.wavefront.uri=https://wavefront.surf
    
    Connect to your Wavefront dashboard using this one-time use link:
    https://wavefront.surf/us/AtoKen

What Happened?

  • Without any extra information, an account on a Freemium cluster was automatically provisioned for you.

  • An API token was created for you.

  • To let you access your dashboard on the Freemium cluster, a one-time use link was logged when the application started. The link starts with https://wavefront.surf. Copy this link into your favorite browser and explore the out-of-the-box Spring Boot dashboard:

Wavefront Dashboard
Note

It takes a minute for the data to show up. When you can see the data in Tanzu Observability by Wavefront, make sure that the Application and Service names in the filters match what you configured in the application.properties file.

**Application** and **Service** names in the filters match what you configured in the `application.properties` file.

Create a Simple Controller

Next, you can create a simple controller to see how HTTP traffic is automatically instrumented. The following listing shows how to do so:

link:complete/src/main/java/hello/DemoController.java[role=include]
  1. Restart the application and trigger http://localhost:8080 from your browser multiple times.

  2. You’ll notice an extra HTTP section on the dashboard. This feature is called conditional dashboards and lets you display sections according to a filter.

    Wavefront HTTP section
  3. Optionally, access http://localhost:8080/does-not-exist to trigger a client-side 404 error.

Summary

Congratulations! You just developed a web application that sends metrics to Tanzu Observability by Wavefront.

See Also

The following may also be helpful:

About

Observability with Spring :: Learn how to send application metrics to Tanzu Observability

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published