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

explain spring boot attribute override #4241

Merged
merged 11 commits into from
Apr 15, 2024
43 changes: 38 additions & 5 deletions content/en/docs/languages/java/automatic/spring-boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ or the `application.yaml` file, or with environment variables.

```properties
otel.propagators=tracecontext,b3
otel.resource.attributes=environment=dev,xyz=foo
otel.resource.attributes.deployment.environment=dev
otel.resource.attributes.service.name=cart
otel.resource.attributes.service.namespace=shop
```

`application.yaml` example:
Expand All @@ -186,18 +188,49 @@ otel:
- b3
resource:
attributes:
environment: dev
xyz: foo
deployment.environment: dev
service:
name: cart
namespace: shop
```

Environment variables example:

```shell
export OTEL_PROPAGATORS="tracecontext,b3"
export OTEL_RESOURCE_ATTRIBUTES="environment=dev,xyz=foo"
jeanbisutti marked this conversation as resolved.
Show resolved Hide resolved
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment=dev,service.name=cart,service.namespace=shop"
```

Disable the OpenTelemetry Starter:
#### Overriding Resource Attributes

As usual in Spring Boot, you can override properties in the
`application.properties` and `application.yaml` files with environment
variables.

For example, you can set or override the `deployment.environment` resource
attribute (not changing `service.name` or `service.namespace`) by setting the
standard `OTEL_RESOURCE_ATTRIBUTES` environment variable:

```shell
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment=prod"
```

Alternatively, you can use the `OTEL_RESOURCE_ATTRIBUTES_DEPLOYMENT_ENVIRONMENT`
environment variable to set or override a single resource attribute:

```shell
export OTEL_RESOURCE_ATTRIBUTES_DEPLOYMENT_ENVIRONMENT="prod"
```

The second option supports
[SpEL](https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/expressions.html)
expressions.

Note that `DEPLOYMENT_ENVIRONMENT` gets converted to `deployment.environment` by
Spring Boot's
[Relaxed Binding](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding.environment-variables).

#### Disable the OpenTelemetry Starter

{{% config_option name="otel.sdk.disabled" %}}

Expand Down
8 changes: 8 additions & 0 deletions static/refcache.json
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,10 @@
"StatusCode": 206,
"LastSeen": "2024-02-19T17:27:38.673604461+01:00"
},
"https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding.environment-variables": {
"StatusCode": 200,
"LastSeen": "2024-04-11T13:40:26.805402963+02:00"
},
"https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.auto-configuration": {
"StatusCode": 206,
"LastSeen": "2024-01-30T16:15:14.908906-05:00"
Expand All @@ -1643,6 +1647,10 @@
"StatusCode": 200,
"LastSeen": "2024-01-30T16:14:53.797365-05:00"
},
"https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/expressions.html": {
"StatusCode": 206,
"LastSeen": "2024-04-03T12:51:54.758528517+02:00"
},
"https://docs.spring.io/spring-security/reference/servlet/authorization/architecture.html#authz-authorities": {
"StatusCode": 206,
"LastSeen": "2024-02-12T22:02:33.483262-05:00"
Expand Down