Skip to content

Commit

Permalink
provide option to enable opentelemetry metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopar committed Dec 8, 2023
1 parent 4b01e9d commit a09c347
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The below property names can be changed in the following ways
| authorization.api.client.id | AUTHORIZATION_API_CLIENT_ID | | The ID value of the authorization server API client |
| authorization.api.client.secret | AUTHORIZATION_API_CLIENT_SECRET | | The secret value of the authorization server API client |
| authorization.swagger.ui.client.id | AUTHORIZATION_SWAGGER_UI_CLIENT_ID | | The ID value of the authorization server swagger-ui client |
| otel.exporter.otlp.endpoint | OTEL_EXPORTER_OTLP_ENDPOINT | http://localhost:4317 | URL of the OTEL collector |

## Run Application

Expand Down Expand Up @@ -136,4 +137,14 @@ All configuration parameters can be passed as environment variables to the conta

We also deliver a jar for each release and can be found in the asests list of each
release [here](https://github.com/eclipse-xpanse/terraform-boot/releases).
The jar can be started as mentioned in the same way we do for local development.
The jar can be started as mentioned in the same way we do for local development.

### Observability

`terraform-boot` provides an option to enable observability using [openTelemetry](https://opentelemetry.io/). This can
be enabled by starting the runtime with profile `opentelemetry`.

By enabling this profile, the application forwards metrics, traces and logs to the `otel-collector`.

By default, the application sends all telemetry data to `http://localhost:4317` and this can be changed by updating the
value of `otel.exporter.otlp.endpoint` configuration property.
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@
<logbook.version>3.5.0</logbook.version>
<nimbusds.oidc.sdk.version>10.7</nimbusds.oidc.sdk.version>
<lombok.version>1.18.30</lombok.version>
<opentelemetry.version>1.32.0</opentelemetry.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom</artifactId>
<version>${opentelemetry.version}</version>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -79,6 +90,11 @@
<artifactId>oauth2-oidc-sdk</artifactId>
<version>${nimbusds.oidc.sdk.version}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
<version>${opentelemetry.version}-alpha</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.terraform.boot.observability;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;

/**
* Configuration to workaround issues with ParameterNameDiscoverer bean which is instantiated by
* multiple libraries. Hence, this class defines a primary bean which will solve the duplicate
* bean exception.
*/
@Configuration
public class OpenTelemetryConfiguration {

@Bean
@ConditionalOnMissingBean
@Primary
ParameterNameDiscoverer parameterNameDiscoverer() {
return new DefaultParameterNameDiscoverer();
}

}
7 changes: 7 additions & 0 deletions src/main/resources/application-opentelemetry.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Huawei Inc.
#
#
otel.exporter.otlp.endpoint=http://localhost:4317
otel.exporter.otlp.enabled=true
5 changes: 4 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Huawei Inc.
#
spring.application.name=terraform-boot
server.port=9090
app.version=@project.version@
spring.banner.location=classpath:banner.txt
http.logging.enabled=true
http.logging.exclude.uri=/v3/**,/swagger-ui/**,/favicon.ico,/h2-console/**
log.terraform.stdout.stderr=false
terraform.binary.location=
terraform.log.level=INFO
terraform.log.level=INFO
otel.exporter.otlp.enabled=false
terraform.root.module.directory=
10 changes: 10 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
</Pattern>
</encoder>
</appender>
<springProfile name="opentelemetry">
<appender name="OpenTelemetry" class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
</appender>
<logger additivity="false" level="info" name="org.eclipse.xpanse">
<appender-ref ref="OpenTelemetry"/>
</logger>
<root level="error">
<appender-ref ref="OpenTelemetry"/>
</root>
</springProfile>

<logger additivity="false" level="info" name="org.eclipse.xpanse">
<appender-ref ref="Console"/>
Expand Down

0 comments on commit a09c347

Please sign in to comment.