diff --git a/Dockerfile b/Dockerfile index 7dd4bd05..8f0cf15f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:25-jre-alpine ENV PORT=8080 +ENV JAVA_TOOL_OPTIONS="-Dotel.java.global-autoconfigure.enabled=true" RUN apk add --no-cache shadow && \ groupadd -r idp-core-group && \ diff --git a/pom.xml b/pom.xml index 456b4c59..a952b04f 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,13 @@ pom import + + io.opentelemetry + opentelemetry-bom + 1.54.0 + pom + import + @@ -337,6 +344,28 @@ camel-rest-starter + + io.opentelemetry + opentelemetry-api + + + io.opentelemetry + opentelemetry-sdk + + + io.opentelemetry + opentelemetry-sdk-extension-autoconfigure + + + io.opentelemetry + opentelemetry-exporter-otlp + + + + org.apache.camel.springboot + camel-opentelemetry-starter + + @@ -545,6 +574,7 @@ org.hibernate.orm:hibernate-core:6.6.29.Final ch.qos.logback:logback-classic:1.5.34 ch.qos.logback:logback-core:1.5.34 + org.codehaus.mojo:animal-sniffer-annotations:1.26 diff --git a/src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/OtelDebugController.java b/src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/OtelDebugController.java new file mode 100644 index 00000000..33e0b4b8 --- /dev/null +++ b/src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/OtelDebugController.java @@ -0,0 +1,44 @@ +package com.decathlon.idp_core.infrastructure.adapters.api.controller; + +import java.util.Map; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.StatusCode; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.context.Scope; + +/** + * Debug endpoint used to validate that OpenTelemetry spans are created and + * exported. + * + *

+ * This endpoint intentionally creates a custom span with attributes and logs an + * event so that Cloud Run logs can confirm whether the SDK is active and + * whether the exporter is called. + */ +@RestController +@RequestMapping("/debug") +public class OtelDebugController { + + private static final Tracer TRACER = GlobalOpenTelemetry.get().getTracer("idp-core-debug"); + + @GetMapping("/otel-test") + public ResponseEntity> triggerOtelTrace() { + Span span = TRACER.spanBuilder("debug.otel-test").setAttribute("debug.enabled", true) + .setAttribute("debug.route", "/debug/otel-test").startSpan(); + + try (Scope ignored = span.makeCurrent()) { + span.addEvent("debug-otel-triggered"); + span.setStatus(StatusCode.OK); + return ResponseEntity.ok(Map.of("status", "ok", "trace", "debug.otel-test")); + } finally { + span.end(); + } + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bd217e2e..0e0c44cc 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -170,27 +170,40 @@ idp: logging: level: - # Application log level, defaults to INFO. Override per environment via LOG_LEVEL env var. + io.opentelemetry: DEBUG + org.apache.camel.opentelemetry: DEBUG com.decathlon: ${LOG_LEVEL:INFO} - # Suppresses noisy Spring context startup logs at WARN level. org.springframework.context.support: WARN - # Suppresses a specific repetitive bean registration delegate log line. org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR +otel: + service: + name: ${OTEL_SERVICE_NAME:internal-developer-platform} + traces: + exporter: otlp + metrics: + exporter: otlp + logs: + exporter: none + exporter: + otlp: + endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT} + protocol: ${OTEL_EXPORTER_OTLP_PROTOCOL:http/protobuf} + resource: + attributes: + deployment.environment: ${OTEL_ENV} + service.namespace: ${OTEL_SERVICE_NAMESPACE} + X-Datadog-Org: ${ORG} + X-Backend: ${BACKEND} + +camel: + opentelemetry: + enabled: true + management: tracing: - # Tracing is disabled by default and only enabled via environment variables (OTEL_TRACING_ENABLED). - enabled: false - sampling: - probability: 1.0 # 100% des traces - - otlp: - tracing: - endpoint: ${OPEN_TELEMETRY_URL:""} - headers: - swagger: - enabled: ${APP_SECURITY_SWAGGER_ENABLED:true} - authorization: ${OPEN_TELEMETRY_TOKEN:""} + # Tracing is disabled by default and only enabled via environment variables. + enabled: ${OTEL_TRACING_ENABLED:false} endpoints: web: @@ -220,23 +233,3 @@ management: # Shows full health details only to authenticated users. # Avoids leaking internal infrastructure info to unauthenticated callers. show-details: when_authorized - -camel: - component: - platform-http: - engine: "servlet" - # Never expose the health "details" map (e.g. database product name/version, - # validation query, disk space paths). Only UP/DOWN status is shown. - show-details: never - # Still surface per-component status (e.g. db: UP/DOWN) so direct - # dependencies can be checked, without leaking their details. - show-components: always - health: - diskspace: - # DiskSpace is not a direct dependency and its free/threshold values - # are not relevant to consumers checking service health. - enabled: false - ssl: - # SSL certificate/chain info is internal infrastructure detail and - # must not be exposed via actuator. - enabled: false