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

Move the Spring Auto-Configuration doc to opentelemetry.io #3758

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
7358798
rebase to remove docsy changes
jaydeluca Jan 18, 2024
2c80dae
add back in spaces for formatting links
jaydeluca Jan 18, 2024
e0f90e1
Results from /fix:format
opentelemetrybot Jan 18, 2024
d240e97
rebase to remove docsy changes
jaydeluca Jan 18, 2024
5288d28
add back in spaces for formatting links
jaydeluca Jan 18, 2024
cf6c4f6
Results from /fix:format
opentelemetrybot Jan 18, 2024
4381ab0
Merge branch 'update-spring-boot-docs' of github.com:jaydeluca/opente…
jaydeluca Jan 19, 2024
ef72a6a
move section, implement code review notes
jaydeluca Jan 20, 2024
3044e93
Results from /fix:format
opentelemetrybot Jan 20, 2024
b0b1348
Merge branch 'main' into update-spring-boot-docs
jaydeluca Jan 20, 2024
a19951d
Update spring boot docs (#1)
jeanbisutti Jan 25, 2024
efb9937
Merge branch 'main' into update-spring-boot-docs
jaydeluca Jan 25, 2024
5d6416c
pull in new changes from main
jaydeluca Jan 29, 2024
991b0df
lint and spellcheck fixes
jaydeluca Jan 29, 2024
f365896
Merge branch 'main' into update-spring-boot-docs
jaydeluca Jan 29, 2024
a727601
undo capitalize http, fix default endpoint
jaydeluca Jan 30, 2024
37a7cf6
remove trace examples, update link format, fix typo
jaydeluca Jan 30, 2024
81f25c4
remove exporter properties table for reference link, update spelling …
jaydeluca Jan 30, 2024
f2c4f28
move spelling ignores to local file
jaydeluca Jan 30, 2024
662b8dd
fix spelling ignore
jaydeluca Jan 30, 2024
88d5651
fix formatting
jaydeluca Jan 30, 2024
03109f5
Merge branch 'main' into update-spring-boot-docs
jaydeluca Jan 30, 2024
31f1c4d
fix build issues
jaydeluca Jan 30, 2024
e738911
fix sentence
jaydeluca Jan 30, 2024
2ab61e3
Merge branch 'main' into update-spring-boot-docs
jeanbisutti Jan 30, 2024
cf7ed67
Refcache updates 2024-01-18 (#3805)
chalin Jan 18, 2024
b2b48eb
Update opamp-spec (#3806)
chalin Jan 18, 2024
9d991f9
Update Ruby metrics and logs status to "in development" (#3807)
kaylareopelle Jan 18, 2024
f470b95
[Demo] Telemetry features: better name pages following refactor (#3817)
chalin Jan 19, 2024
1d9de66
Added vendor information of Alibaba Cloud (#3797)
steverao Jan 19, 2024
35e8f02
Remove Teletrace from vendor list (#3822)
ophiryael Jan 19, 2024
40133f7
rebase
jaydeluca Jan 30, 2024
3be726b
rebase
jaydeluca Jan 31, 2024
2deffca
rebase
jaydeluca Jan 31, 2024
f981d31
move section, implement code review notes
jaydeluca Jan 20, 2024
a3d7e19
Results from /fix:format
opentelemetrybot Jan 20, 2024
562a73a
Registry updates Jan 2024 (#3821)
svrnm Jan 19, 2024
5ff222c
Refcache updates 2024-01-19 (#3823)
chalin Jan 19, 2024
a37036f
Update .NET libraries page with new intro (#3827)
svrnm Jan 19, 2024
3b7f534
Update spring boot docs (#1)
jeanbisutti Jan 25, 2024
efa24c2
[demo] move services table into service index page (#3833)
puckpuck Jan 20, 2024
265103e
Fix typos in "Signals" documentation section (#3825)
fabrideci Jan 20, 2024
4e8d84f
Fix community meeting time (#3843)
cijothomas Jan 22, 2024
76d7dc1
Add script to auto update registry entries (#3840)
svrnm Jan 22, 2024
d829c7d
Add ruby gems to ruby registry entries (#3842)
svrnm Jan 22, 2024
601d86a
Registry: put 'offical' languages first in dropdown (#3844)
svrnm Jan 22, 2024
da11633
Auto-update registry versions (7f561fb7b86ada3acd30461a32354e5ceea9fc…
opentelemetrybot Jan 22, 2024
db52920
add package version to JS entries in registry (#3841)
svrnm Jan 22, 2024
6245209
[Go] Bump to newer semconv (#3838)
pellared Jan 22, 2024
a4f3167
Rust registry updates (#3830)
svrnm Jan 22, 2024
df7d379
fix typo (#3850)
binfeiruci Jan 24, 2024
6ef9078
Update getting-started.md to specify java version (#3831)
arifcse019 Jan 25, 2024
888674f
java library instrumentation doc (#3568)
nerudadhich Jan 26, 2024
18214f0
[Go] Getting started: Do not use semconv (#3860)
pellared Jan 26, 2024
ec95c7d
Update go libraries page with new intro (#3826)
svrnm Jan 26, 2024
cacdde4
Add github.com/dnwe/otelsarama to registry (#3858)
pellared Jan 26, 2024
96b0f0f
[PHP] Documenting the option to disable all auto-instrumentations (#3…
joaojacome Jan 27, 2024
466602a
Fix bug in registry update script (#3863)
svrnm Jan 27, 2024
e122979
Auto-update registry versions (ffc6d9775fcba8629ae06cda271674a341e587…
svrnm Jan 27, 2024
82c8505
Update opentelemetry-collector-releases version to 0.93.0 (#3861)
opentelemetrybot Jan 27, 2024
f15c135
describe how to disable spring boot starter / use sys property widget…
zeitlinger Jan 27, 2024
1f404cf
Auto-update registry versions (4a79d2bb968c1ba246962231561dfa14cac26b…
opentelemetrybot Jan 28, 2024
9b48107
Collector quick start (#3787)
chalin Jan 29, 2024
cdcf501
lint and spellcheck fixes
jaydeluca Jan 29, 2024
5b6a2c4
[demo] Add and recover aliases for service-table + copyedit (#3875)
chalin Jan 29, 2024
db6dedd
updated autoinstrumentation description to match other languages (#3868)
sy-be Jan 29, 2024
390d58d
undo capitalize http, fix default endpoint
jaydeluca Jan 30, 2024
1add2a6
remove trace examples, update link format, fix typo
jaydeluca Jan 30, 2024
e5a9b7d
remove exporter properties table for reference link, update spelling …
jaydeluca Jan 30, 2024
1cedb8b
move spelling ignores to local file
jaydeluca Jan 30, 2024
6463fe0
fix spelling ignore
jaydeluca Jan 30, 2024
31e6ffa
fix formatting
jaydeluca Jan 30, 2024
68df44c
Supply example on Document baggage propagation (#3716)
pegasas Jan 30, 2024
42b2037
Bump @opentelemetry/exporter-trace-otlp-http from 0.47.0 to 0.48.0 (#…
dependabot[bot] Jan 30, 2024
65ba92b
Bump @opentelemetry/instrumentation from 0.47.0 to 0.48.0 (#3870)
dependabot[bot] Jan 30, 2024
ac18ce3
[Java] getting-started: tweak JDK version constraint (#3877)
chalin Jan 30, 2024
8a0fc02
Auto-update registry versions (6906807dde6d4eda38c2a67569d6fdc5f917f1…
opentelemetrybot Jan 30, 2024
01db458
Update community submodule (#3876)
chalin Jan 30, 2024
6f6ff97
[CI/textlint] Enforce "backend" as one word (#3883)
chalin Jan 30, 2024
fbc8b0d
[CI/textlint] Enforce "bug fix" as two words (#3884)
chalin Jan 30, 2024
7454ff0
Community-page copyedits (#3885)
chalin Jan 30, 2024
79f7462
Edits to follow up contribution guidelines work (#3846)
theletterf Jan 30, 2024
c0b3459
fix build issues
jaydeluca Jan 30, 2024
7cbf0ef
fix sentence
jaydeluca Jan 30, 2024
2897698
[CI/textlint] Enforce "backend" rather than "back-end" (#3892)
chalin Jan 30, 2024
5cbee21
[CI] Refcache refresh for entries before 2023-08-01 (#3890)
chalin Jan 30, 2024
a8c951e
PHP: Updates to instrumentation docs (#3855)
svrnm Jan 30, 2024
6e672de
Drop unnecessary `api/propagation` aliases and local dictionary (#3887)
chalin Jan 30, 2024
f25c8c2
Bump @opentelemetry/auto-instrumentations-web from 0.35.0 to 0.36.0 (…
dependabot[bot] Jan 30, 2024
91ff998
Fix config example (#3881)
austindrenski Jan 30, 2024
c300273
rebase
jaydeluca Jan 31, 2024
89ec61f
Merge branch 'main' into update-spring-boot-docs
jaydeluca Jan 31, 2024
c58c73a
update url to reference new sdk exporter config page
jaydeluca Jan 31, 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
298 changes: 286 additions & 12 deletions content/en/docs/languages/java/automatic/spring-boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ title: Spring Boot
linkTitle: Spring Boot
weight: 30
description: Spring Boot instrumentation for OpenTelemetry Java
cSpell:ignore: autoconfigure datasource logback springboot springframework
# prettier-ignore
cSpell:ignore: autoconfiguration autoconfigurations autoconfigure autoconfigures classpath datasource logback springboot springframework webflux webmvc
---

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.

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

- with Spring Boot Native image applications for which the OpenTelemetry Java
agent does not work
- the startup overhead of the OpenTelemetry Java agent exceeds your requirements
- the OpenTelemetry Java agent might not work if your application already uses
- 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

[Spring Boot starter]:
Expand All @@ -31,9 +33,7 @@ Boot 2.0 and 3.0.

## OpenTelemetry Spring starter

### Configuration

#### Dependency management
### Dependency management

A Bill of Material
([BOM](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms))
Expand Down Expand Up @@ -70,7 +70,7 @@ 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:
You can use the Gradle’s native BOM support by adding `dependencies`:

```kotlin
plugins {
Expand Down Expand Up @@ -154,7 +154,134 @@ Set the value to `true` to disable data export, e.g. for testing purposes.

{{% /config_option %}}

### Additional instrumentations
### OTLP Exporter

This package provides auto configuration for the
[OTLP](https://github.com/open-telemetry/opentelemetry-java/tree/main/exporters/otlp)
and
[Logging](https://github.com/open-telemetry/opentelemetry-java/tree/main/exporters/logging)
Span Exporters.

As of 2.0.0+ the default protocol is `http/protobuf`. For more details on
exporter configuration, see
[OTLP Exporter Configuration](/docs/languages/sdk-configuration/otlp-exporter/).

#### Enabling/Disabling Exporters

All exporters can be enabled or disabled as in the
[SDK auto-configuration](https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md#exporters).
This is the preferred way to enable/disable exporters and takes precedence over
the properties below.

| Feature | Property | Default Value | ConditionalOnMissingBean |
|-----------------------|--------------------------------------|---------------|----------------------------------------------------------|
| OTLP Exporter | `otel.exporter.otlp.enabled` | true | - |
| OTLP Span Exporter | `otel.exporter.otlp.traces.enabled` | true | `OtlpHttpSpanExporter`, `OtlpGrpcSpanExporter` |
| OTLP Metrics Exporter | `otel.exporter.otlp.metrics.enabled` | true | `OtlpHttpMetricExporter`, `OtlpGrpcMetricExporter` |
| OTLP Logs Exporter | `otel.exporter.otlp.logs.enabled` | true | `OtlpHttpLogRecordExporter`, `OtlpGrpcLogRecordExporter` |
| Logging Exporter | `otel.exporter.logging.enabled` | false | `LoggingSpanExporter` |

### Tracer Properties

| Feature | Property | Default Value |
| ------- | --------------------------------- | ------------- |
| Tracer | `otel.traces.sampler.probability` | 1.0 |

### Resource Properties

| Feature | Property | Default Value |
| -------- | ----------------------------------------------------------------------- | ------------- |
| Resource | `otel.springboot.resource.enabled` | true |
| | `otel.resource.attributes` (old: `otel.springboot.resource.attributes`) | empty map |

`otel.resource.attributes` supports a pattern-based resource configuration in
the application.properties like this:

```properties
otel.resource.attributes.environment=dev
otel.resource.attributes.xyz=foo
```

It's also possible to specify the resource attributes in `application.yaml`:

```yaml
otel:
resource:
attributes:
environment: dev
xyz: foo
```

Finally, the resource attributes can be specified as a comma-separated list, as
described in the
[specification](/docs/concepts/sdk-configuration/general-sdk-configuration/#otel_resource_attributes):

```shell
export OTEL_RESOURCE_ATTRIBUTES="key1=value1,key2=value2"
```

The service name is determined by the following precedence rules, in accordance
with the OpenTelemetry
[specification](/docs/concepts/sdk-configuration/general-sdk-configuration/#otel_service_name):

1. `otel.service.name` spring property or `OTEL_SERVICE_NAME` environment
variable (highest precedence)
2. `service.name` in `otel.resource.attributes` system/spring property or
`OTEL_RESOURCE_ATTRIBUTES` environment variable
3. `service.name` in `otel.springboot.resource.attributes` system/spring
property
4. `spring.application.name` spring property
5. The default value is `unknown_service:java` (lowest precedence)

### Automatic instrumentation

Auto-configures OpenTelemetry instrumentation for
[spring-web](#spring-web-auto-configuration) ,
[spring-webmvc](#spring-web-mvc-auto-configuration), and
[spring-webflux](#spring-webflux-auto-configuration). Leverages Spring Aspect
Oriented Programming, dependency injection, and bean post-processing to trace
spring applications.

| Feature | Property | Default Value | ConditionalOnClass |
| -------------- | --------------------------------------------- | ------------- | ---------------------- |
| spring-web | `otel.instrumentation.spring-webmvc.enabled` | true | `RestTemplate` |
| spring-webmvc | `otel.instrumentation.spring-web.enabled` | true | `OncePerRequestFilter` |
| spring-webflux | `otel.instrumentation.spring-webflux.enabled` | true | `WebClient` |

#### Spring Web Auto Configuration

Provides auto-configuration for the OpenTelemetry RestTemplate trace interceptor
defined in
[opentelemetry-spring-web-3.1](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/spring/spring-web/spring-web-3.1).
This auto-configuration instruments all requests sent using Spring RestTemplate
beans by applying a RestTemplate bean post processor. This feature is supported
for spring web versions 3.1+. Check out
[opentelemetry-spring-web-3.1](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/spring/spring-web/spring-web-3.1)
to learn more about the OpenTelemetry RestTemplateInterceptor.

#### Spring Web MVC Auto Configuration

This feature autoconfigures instrumentation for Spring WebMVC controllers by
adding a
[telemetry producing servlet `Filter`](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/WebMvcTelemetryProducingFilter.java)
bean to the application context. This filter decorates the request execution
with an OpenTelemetry server span, propagating the incoming tracing context if
received in the HTTP request. Check out
[`opentelemetry-spring-webmvc-5.3` instrumentation library](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library)
to learn more about the OpenTelemetry Spring WebMVC instrumentation.

#### Spring WebFlux Auto Configuration

Provides auto-configurations for the OpenTelemetry WebClient ExchangeFilter
defined in
[opentelemetry-spring-webflux-5.3](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/spring/spring-webflux/spring-webflux-5.3).
This auto-configuration instruments all outgoing HTTP requests sent using
Spring's WebClient and WebClient Builder beans by applying a bean post
processor. This feature is supported for spring webflux versions 5.0+. Check out
[opentelemetry-spring-webflux-5.3](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/spring/spring-webflux/spring-webflux-5.3)
to learn more about the OpenTelemetry WebClientFilter.

### Additional Instrumentations

#### JDBC Instrumentation

Expand Down Expand Up @@ -263,7 +390,154 @@ and
[Log4j](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/log4j/log4j-appender-2.17/library/README.md)
instrumentation libraries.

#### Other Instrumentation
#### Instrumentation 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. Check out
[spring-aop](https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#aop)
to learn more about aspect weaving in spring.

| Feature | Property | Default Value | ConditionalOnClass |
| ----------- | ------------------------------------------ | ------------- | ------------------ |
| `@WithSpan` | `otel.instrumentation.annotations.enabled` | true | WithSpan, Aspect |

##### Dependency

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

```xml
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>SPRING_VERSION</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-extension-annotations</artifactId>
<version>{{% param vers.otel %}}</version>
</dependency>
</dependencies>
```

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

```kotlin
dependencies {
implementation("org.springframework:spring-aop:SPRING_VERSION")
implementation("io.opentelemetry:opentelemetry-extension-annotations:{{% param vers.otel %}}")
}
```

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

##### Usage

```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) {
}
}
```

#### 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).

### Other configurations

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

#### Spring support

Auto-configuration is natively supported by Springboot 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 auto-configuration. 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` |
4 changes: 4 additions & 0 deletions static/refcache.json
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,10 @@
"StatusCode": 200,
"LastSeen": "2023-11-14T09:30:42.69906-05:00"
},
"https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#aop": {
"StatusCode": 206,
"LastSeen": "2024-01-30T20:07:21.056466-05:00"
},
"https://docs.thousandeyes.com/product-documentation/api/opentelemetry": {
"StatusCode": 206,
"LastSeen": "2024-01-30T05:18:01.115211-05:00"
Expand Down