diff --git a/README.md b/README.md index b63f340..be8f710 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8d34529..446a870 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,18 @@ 3.5.0 10.7 1.18.30 + 1.32.0 + + + + io.opentelemetry + opentelemetry-bom + ${opentelemetry.version} + pom + + + org.springframework.boot @@ -79,6 +90,11 @@ oauth2-oidc-sdk ${nimbusds.oidc.sdk.version} + + io.opentelemetry.instrumentation + opentelemetry-spring-boot-starter + ${opentelemetry.version}-alpha + diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/observability/OpenTelemetryConfiguration.java b/src/main/java/org/eclipse/xpanse/terraform/boot/observability/OpenTelemetryConfiguration.java new file mode 100644 index 0000000..9e777d1 --- /dev/null +++ b/src/main/java/org/eclipse/xpanse/terraform/boot/observability/OpenTelemetryConfiguration.java @@ -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(); + } + +} diff --git a/src/main/resources/application-opentelemetry.properties b/src/main/resources/application-opentelemetry.properties new file mode 100644 index 0000000..61942eb --- /dev/null +++ b/src/main/resources/application-opentelemetry.properties @@ -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 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b61af01..32521fb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,6 +2,7 @@ # 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 @@ -9,4 +10,6 @@ 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 \ No newline at end of file +terraform.log.level=INFO +otel.exporter.otlp.enabled=false +terraform.root.module.directory= \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 365bf32..671af4b 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -15,6 +15,16 @@ + + + + + + + + + +