# Getting started

LLMS index: [llms.txt](/llms.txt)

---

> [!NOTE]
>
> You can also use the [Java agent](../../agent) to instrument your Spring Boot
> application. For the pros and cons, see [Java zero-code instrumentation](..).

## Compatibility

The OpenTelemetry Spring Boot starter works with Spring Boot 2.6+ and 3.1+, and
Spring Boot native image applications. The
[opentelemetry-java-examples/spring-native](https://github.com/open-telemetry/opentelemetry-java-examples/tree/main/spring-native)
repository contains an example of a Spring Boot Native image application
instrumented using the OpenTelemetry Spring Boot starter.

## Dependency management

A Bill of Material
([BOM](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms))
ensures that versions of dependencies (including transitive ones) are aligned.

To ensure version alignment across all OpenTelemetry dependencies, you must
import the `opentelemetry-instrumentation-bom` BOM when using the OpenTelemetry
starter.

> [!NOTE]
>
> When using Maven, import the OpenTelemetry BOMs before any other BOMs in your
> project. For example, if you import the `spring-boot-dependencies` BOM, you
> have to declare it after the OpenTelemetry BOMs.
>
> Gradle selects the
> [latest version](https://docs.gradle.org/current/userguide/dependency_resolution.html#2_perform_conflict_resolution)
> of a dependency when multiple BOMs, so the order of BOMs is not important.

The following example shows how to import the OpenTelemetry BOMs using Maven:

```xml
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.opentelemetry.instrumentation</groupId>
            <artifactId>opentelemetry-instrumentation-bom</artifactId>
            <version>2.26.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
```

With Gradle and Spring Boot, you have two ways to import a BOM.

You can use the Gradle’s native BOM support by adding `dependencies`:

```kotlin
import org.springframework.boot.gradle.plugin.SpringBootPlugin

plugins {
  id("java")
  id("org.springframework.boot") version "3.2.O"
}

dependencies {
  implementation(platform(SpringBootPlugin.BOM_COORDINATES))
  implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.26.1"))
}
```

The other way with Gradle is to use the `io.spring.dependency-management` plugin
and to import the BOMs in `dependencyManagement`:

```kotlin
plugins {
  id("java")
  id("org.springframework.boot") version "3.2.O"
  id("io.spring.dependency-management") version "1.1.0"
}

dependencyManagement {
  imports {
    mavenBom("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.26.1")
  }
}
```

> [!NOTE]
>
> Be careful not to mix up the different ways of configuring things with Gradle.
> For example, don't use
> `implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.26.1"))`
> with the `io.spring.dependency-management` plugin.

### OpenTelemetry Starter dependency

Add the dependency given below to enable the OpenTelemetry starter.

The OpenTelemetry starter uses OpenTelemetry Spring Boot
[autoconfiguration](https://docs.spring.io/spring-boot/reference/using/auto-configuration.html).

   <ul class="nav nav-tabs" id="tabs-4" role="tablist">
  <li class="nav-item">
      <button class="nav-link active"
          id="tabs-04-00-tab" data-bs-toggle="tab" data-bs-target="#tabs-04-00" role="tab"
          data-td-tp-persist="maven (`pom.xml`)" aria-controls="tabs-04-00" aria-selected="true">
        Maven (<code>pom.xml</code>)
      </button>
    </li><li class="nav-item">
      <button class="nav-link"
          id="tabs-04-01-tab" data-bs-toggle="tab" data-bs-target="#tabs-04-01" role="tab"
          data-td-tp-persist="gradle (`build.gradle`)" aria-controls="tabs-04-01" aria-selected="false">
        Gradle (<code>build.gradle</code>)
      </button>
    </li>
</ul>

<div class="tab-content" id="tabs-4-content">
    <div class="tab-body tab-pane fade show active"
        id="tabs-04-00" role="tabpanel" aria-labelled-by="tabs-04-00-tab" tabindex="4">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-xml" data-lang="xml"><span class="line"><span class="cl"><span class="nt">&lt;dependency&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;groupId&gt;</span>io.opentelemetry.instrumentation<span class="nt">&lt;/groupId&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;artifactId&gt;</span>opentelemetry-spring-boot-starter<span class="nt">&lt;/artifactId&gt;</span>
</span></span><span class="line"><span class="cl"><span class="nt">&lt;/dependency&gt;</span>
</span></span></code></pre></div>
    </div>
    <div class="tab-body tab-pane fade"
        id="tabs-04-01" role="tabpanel" aria-labelled-by="tabs-04-01-tab" tabindex="4">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-kotlin" data-lang="kotlin"><span class="line"><span class="cl"><span class="n">implementation</span><span class="p">(</span><span class="s2">&#34;io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter&#34;</span><span class="p">)</span>
</span></span></code></pre></div>
    </div>
</div>
