Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize Spring Boot content #4554

Merged
merged 31 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
23f47c4
Reorganize Spring Boot content
jeanbisutti May 29, 2024
0d48cbc
Polishing
jeanbisutti May 29, 2024
056fd13
Report content of #4552
jeanbisutti May 29, 2024
0a02ea0
Additional instrumentations menu entry
jeanbisutti May 29, 2024
89c5582
Other Spring autoconfigurations
jeanbisutti May 29, 2024
b83ed75
Remove starter subfolder
jeanbisutti May 29, 2024
40a96cd
Try to fix out of the box instrumentation link
jeanbisutti May 29, 2024
ebb02b5
Fix Spring Boot starter menu entry
jeanbisutti May 29, 2024
a73899e
Results from /fix:format
opentelemetrybot May 29, 2024
5621058
Fix typo for menu entry
jeanbisutti May 29, 2024
acd4da2
Rename page title
jeanbisutti May 29, 2024
055c8d6
Add /docs/zero-code/java/spring-boot/ alias
jeanbisutti May 29, 2024
3ef24d8
fix link
zeitlinger May 29, 2024
31c6bb2
format
zeitlinger May 29, 2024
5b12a2d
better spring boot landing page
zeitlinger May 30, 2024
7ca1730
Update _index.md
jeanbisutti May 30, 2024
133125b
Update _index.md
jeanbisutti May 30, 2024
6fe70b3
Update _index.md
jeanbisutti May 30, 2024
b4d35f0
better spring boot landing page
zeitlinger May 30, 2024
ac03d9b
Update _index.md
jeanbisutti May 30, 2024
50f800b
Update _index.md
jeanbisutti May 30, 2024
eb2aa6b
Merge pull request #1 from zeitlinger/spring-boot-reorganization-land…
jeanbisutti May 30, 2024
dd20197
Results from /fix:all
opentelemetrybot May 30, 2024
fe0f291
Bold
jeanbisutti May 30, 2024
dfa4167
Bold
jeanbisutti May 30, 2024
d664b92
Results from /fix:all
opentelemetrybot May 30, 2024
f3ac395
better spring boot landing page
zeitlinger May 30, 2024
19f5a7f
Fix bullet point display
jeanbisutti May 30, 2024
75fcc53
Results from /fix:all
opentelemetrybot May 30, 2024
d638bcb
Bold
jeanbisutti May 30, 2024
59c8619
Merge branch 'main' into spring-boot-reorganization
cartermp May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Spring Boot starter
description: Spring Boot instrumentation for OpenTelemetry Java
aliases: [/docs/languages/java/automatic/spring-boot/, /docs/zero-code/java/spring-boot/]
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Additional instrumentations
description:
Additional instrumentations in addition to the out of the box instrumentation
of the starter
weight: 50
---

The OpenTelemetry Spring Boot starter provides
of the box instrumentation](../out-of-the-box-instrumentation) that you
can complete with additional instrumentations.

## Log4j2 Instrumentation

You have to add the OpenTelemetry appender to your `log4j2.xml` file:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="io.opentelemetry.instrumentation.log4j.appender.v2_17">
<Appenders>
<OpenTelemetry name="OpenTelemetryAppender"/>
</Appenders>
<Loggers>
<Root>
<AppenderRef ref="OpenTelemetryAppender" level="All"/>
</Root>
</Loggers>
</Configuration>
```

You can find more configuration options for the OpenTelemetry appender in the
[Log4j](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/log4j/log4j-appender-2.17/library/README.md)
instrumentation library.

| System property | Type | Default | Description |
| --------------------------------------------- | ------- | ------- | ----------------------------------------------------------------------------------------------- |
| `otel.instrumentation.log4j-appender.enabled` | Boolean | true | Enables the configuration of the Log4j OpenTelemetry appender with an `OpenTelemetry` instance. |

## OpenTelemetry instrumentations libraries

You can configure other instrumentations with
[OpenTelemetry instrumentations libraries](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/supported-libraries.md#libraries--frameworks).
jeanbisutti marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Agent VS starter
description:
Comparison between the OpenTelemetry Java agent and the OpenTelemetry Spring
starter
weight: 10
---

## How to instrument Spring Boot with OpenTelemetry

The [OpenTelemetry Java agent](..) with byte code instrumentation can cover most
of your needs when instrumenting
[Spring Boot](https://spring.io/projects/spring-boot) applications.

Alternatively, the OpenTelemetry [Spring Boot starter] can help you in the
following cases:

- Spring Boot Native image applications for which the OpenTelemetry Java agent
does not work
- Startup overhead of the OpenTelemetry Java agent exceeds your requirements
- OpenTelemetry Java agent might not work if your application already uses
another Java monitoring agent
- You can use the Spring Boot configuration files (`application.properties`,
`application.yml`) to configure the OpenTelemetry Spring Boot starter which
doesn't work with the OpenTelemetry Java agent

[Spring Boot starter]:
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.build-systems.starters

The OpenTelemetry Java agent has more automatic instrumentation features than
the OpenTelemetry starter.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Annotations
description: Using instrumentation annotations with the Spring starter.
aliases: [../annotations]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be this alias here.

weight: 60
---

For most users, the out-of-the-box instrumentation is completely sufficient and
nothing more has to be done. Sometimes, however, users wish to create
[spans](/docs/concepts/signals/traces/#spans) for their own custom code without
doing too much code change.

## Available annotations

This feature uses spring-aop to wrap methods annotated with `@WithSpan` in a
span. The arguments to the method can be captured as attributed on the created
span by annotating the method parameters with `@SpanAttribute`.

> **Note**: this annotation can only be applied to bean methods managed by the
> spring application context. To learn more about aspect weaving in spring, see
> [spring-aop](https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#aop).

| Feature | Property | Default Value | Description |
| ----------- | ------------------------------------------ | ------------- | --------------------------------- |
| `@WithSpan` | `otel.instrumentation.annotations.enabled` | true | Enables the WithSpan annotations. |

```java
import org.springframework.stereotype.Component;

import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;

/**
* Test WithSpan
*/
@Component
public class TracedClass {

@WithSpan
public void tracedMethod() {
}

@WithSpan(value="span name")
public void tracedMethodWithName() {
Span currentSpan = Span.current();
currentSpan.addEvent("ADD EVENT TO tracedMethodWithName SPAN");
currentSpan.setAttribute("isTestAttribute", true);
}

@WithSpan(kind = SpanKind.CLIENT)
public void tracedClientSpan() {
}

public void tracedMethodWithAttribute(@SpanAttribute("attributeName") String parameter) {
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: Getting Started
description: Getting Started of the OpenTelemetry starter
weight: 20
# prettier-ignore
cSpell:ignore: springboot
---

## OpenTelemetry Spring Boot starter

### Compatibility

The OpenTelemetry Spring Boot starter works with Spring Boot 2.0 and 3.0, 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.

Importing the `opentelemetry-bom` and `opentelemetry-instrumentation-bom-alpha`
BOMs when using the OpenTelemetry starter is important to ensure version
alignment across all OpenTelemetry dependencies.

The following example shows how to import both BOMs using Maven:

```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom</artifactId>
<version>{{% param vers.otel %}}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-bom-alpha</artifactId>
<version>{{% param vers.instrumentation %}}-alpha</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
```

With Gradle and Spring Boot, you have
[two ways](https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/)
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:opentelemetry-bom:{{% param vers.otel %}}"))
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:{{% param vers.instrumentation %}}-alpha"))
}
```

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:opentelemetry-bom:{{% param vers.otel %}}")
mavenBom("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:{{% param vers.instrumentation %}}-alpha")
}
}
```

{{% alert title="Note" color="info" %}}

Be careful not to mix up the different ways of configuring things with Gradle.
For example, don't use
`implementation(platform("io.opentelemetry:opentelemetry-bom:{{% param vers.otel %}}"))`
with the `io.spring.dependency-management` plugin.

{{% /alert %}}

#### 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/docs/current/reference/html/using.html#using.auto-configuration).

{{< tabpane text=true >}} {{% tab header="Maven (`pom.xml`)" lang=Maven %}}

```xml
<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
</dependency>
</dependencies>
```

{{% /tab %}} {{% tab header="Gradle (`gradle.build`)" lang=Gradle %}}

```kotlin
dependencies {
implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter")
}
```

{{% /tab %}} {{< /tabpane>}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: Other Spring autoconfigurations
description: Spring autoconfigurations without the OpenTelemetry Spring starter
cSpell:ignore: autoconfigurations
weight: 70
---

Instead of using the OpenTelemetry Spring starter, you can use the OpenTelemetry
autoconfiguration features with an annotation or the Zipkin starter.

## Spring support

Autoconfiguration is natively supported by Spring Boot applications. To enable
these features in "vanilla" use `@EnableOpenTelemetry` to complete a component
scan of this package.

```java
import io.opentelemetry.instrumentation.spring.autoconfigure.EnableOpenTelemetry;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableOpenTelemetry
public class OpenTelemetryConfig {}
```

## Zipkin starter

OpenTelemetry Zipkin Exporter Starter is a starter package that includes the
opentelemetry-api, opentelemetry-sdk, opentelemetry-extension-annotations,
opentelemetry-logging-exporter, opentelemetry-spring-boot-autoconfigurations and
spring framework starters required to setup distributed tracing. It also
provides the
[opentelemetry-exporters-zipkin](https://github.com/open-telemetry/opentelemetry-java/tree/main/exporters/zipkin)
artifact and corresponding exporter autoconfiguration. Check out
[opentelemetry-spring-boot-autoconfigure](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/spring/spring-boot-autoconfigure/README.md#features)
for the list of supported libraries and features.

If an exporter is present in the classpath during runtime and a spring bean of
the exporter is missing from the spring application context, an exporter bean is
initialized and added to a simple span processor in the active tracer provider.
Check out the implementation
[here](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java).

{{< tabpane text=true >}} {{% tab header="Maven (`pom.xml`)" lang=Maven %}}

```xml
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
<version>{{% param vers.otel %}}</version>
</dependency>
</dependencies>
```

{{% /tab %}} {{% tab header="Gradle (`gradle.build`)" lang=Gradle %}}

```kotlin
dependencies {
implementation("io.opentelemetry:opentelemetry-exporter-zipkin:{{% param vers.otel %}}")
}
```

{{% /tab %}} {{< /tabpane>}}

### Configurations

| Property | Default Value | ConditionalOnClass |
| ------------------------------ | ------------- | -------------------- |
| `otel.exporter.zipkin.enabled` | true | `ZipkinSpanExporter` |
Loading
Loading