Skip to main content

Setting Up BitDive in a Spring Boot Project

Adding BitDive to your Spring Boot project takes less than 2 minutes. You just need to add one dependency and a quick configuration file.

This guide will walk you through the process for Spring Boot 2 and 3, using Maven or Gradle.

Step 1: Add the BitDive Profile Dependency

The BitDive producer detects runtime execution and sends traces to your BitDive dashboard. The version you need depends entirely on your Spring Boot version, not your language (Java vs. Kotlin).

🔍 Always use the latest version! Check Maven Central here for the most up-to-date versions of all BitDive libraries.

For Spring Boot 3.x

Maven (pom.xml):

<dependency>
<groupId>io.bitdive</groupId>
<artifactId>bitdive-producer-spring-3</artifactId>
<version>LATEST_VERSION</version>
</dependency>

Gradle (build.gradle):

implementation 'io.bitdive:bitdive-producer-spring-3:LATEST_VERSION'

For Spring Boot 2.x

Maven (pom.xml):

<dependency>
<groupId>io.bitdive</groupId>
<artifactId>bitdive-producer-spring-2</artifactId>
<version>LATEST_VERSION</version>
</dependency>

Gradle (build.gradle):

implementation 'io.bitdive:bitdive-producer-spring-2:LATEST_VERSION'

Note: You only need to add this ONE dependency. Core and parent modules are pulled in transitively.


Step 2: Add BitDive Configuration

Create a new file named config-profiling-api.yml in your src/main/resources/ directory.

Add the following configuration:

bitdive:
monitoring:
moduleName: "YOUR_PROJECT_ID"
serviceName: "my-microservice"
packedScanner:
- "com.yourcompany.app"
serverUrl: "https://cloud.bitdive.io"
token: "YOUR_BITDIVE_TOKEN"

Configuration Details:

  • moduleName: Your Project ID from the BitDive dashboard.
  • serviceName: The name of your application as it will appear in the BitDive UI.
  • packedScanner: Your application's main base package (e.g., com.microservices.faculty). BitDive will scan this package for instrumentation. Do not use a broader parent package; focus on your specific service package.
  • serverUrl: The URL of your BitDive server (use https://cloud.bitdive.io for SaaS).
  • token: Your authentication token from the BitDive dashboard.

Step 3 (Optional): Add Replay Test Dependency

If you want to use BitDive Replay to run deterministic tests using recorded production traces locally or in your CI/CD pipeline, you will need the Replay library.

For Spring Boot 3.x

Maven (pom.xml):

<dependency>
<groupId>io.bitdive</groupId>
<artifactId>bitdive-replay-spring3</artifactId>
<version>LATEST_VERSION</version>
<scope>test</scope>
</dependency>

Gradle (build.gradle):

testImplementation 'io.bitdive:bitdive-replay-spring3:LATEST_VERSION'

For Spring Boot 2.x

Substitute bitdive-replay-spring3 with bitdive-replay-spring2.


Step 4 (Optional): Create a Replay Test Class

After adding the replay dependency, you can create a test class extending ReplayTestBase to automatically replay recorded traces.

Create a class in src/test/java/<main_package>/TestControllerTestAbstract.java.

package com.yourcompany.app;

import io.bitdive.replay.ReplayTestBase;
import io.bitdive.replay.dto.ReplayTestConfiguration;
import io.bitdive.replay.dto.ReplayTestUtils;

import java.util.Arrays;
import java.util.List;

class TestControllerTestAbstract extends ReplayTestBase {

@Override
protected List<ReplayTestConfiguration> getTestConfigurations() {
// Replace with actual Trace IDs from your BitDive dashboard
return ReplayTestUtils.fromRestApiWithJsonContentConfigFile(
Arrays.asList("TRACE_ID_1", "TRACE_ID_2")
);
}
}

Make sure that the package of this test matches your application's base package so Spring component scanning works correctly.

Next Steps

Now simply run your Spring Boot application! Make a request to one of your endpoints, wait a few seconds, and watch the traces appear in your BitDive dashboard.