diff --git a/common/src/main/java/org/keycloak/common/Profile.java b/common/src/main/java/org/keycloak/common/Profile.java index 7d3e61105b..fcd6ef90e2 100755 --- a/common/src/main/java/org/keycloak/common/Profile.java +++ b/common/src/main/java/org/keycloak/common/Profile.java @@ -114,6 +114,8 @@ public class Profile { OID4VC_VCI("Support for the OID4VCI protocol as part of OID4VC.", Type.EXPERIMENTAL), + OPENTELEMETRY("OpenTelemetry Tracing", Type.PREVIEW), + DECLARATIVE_UI("declarative ui spi", Type.EXPERIMENTAL), ORGANIZATION("Organization support within realms", Type.PREVIEW), diff --git a/docs/guides/server/tracing.adoc b/docs/guides/server/tracing.adoc index d60b36ce7c..6ec657c65e 100644 --- a/docs/guides/server/tracing.adoc +++ b/docs/guides/server/tracing.adoc @@ -17,9 +17,9 @@ It also provides valuable insights into performance bottlenecks and can help opt == Enable tracing -It is possible to enable exposing traces using the build time option `tracing-enabled` as follows: +It is possible to enable exposing traces using the build time option `tracing-enabled`, and enabling `opentelemetry` feature as follows: -<@kc.start parameters="--tracing-enabled=true"/> +<@kc.start parameters="--tracing-enabled=true --features=opentelemetry"/> By default, the trace exporters send out data in batches, using the `gRPC` protocol and endpoint `+http://localhost:4317+`. @@ -77,7 +77,7 @@ The format of the log records may start as follows: You can hide tracing information in specific log handlers by specifying their associated {project_name} option `log--include-trace`, where `` is the name of the log handler. For instance, to disable trace info in the `console` log, you can turn it off as follows: -<@kc.start parameters="--tracing-enabled=true --log=console --log-console-include-trace=false"/> +<@kc.start parameters="--tracing-enabled=true --features=opentelemetry --log=console --log-console-include-trace=false"/> NOTE: When you explicitly override the log format for the particular log handlers, the `*-include-trace` options do not have any effect, and no tracing is included. diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java index 33ca3b0bcb..c4175d131a 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java @@ -47,6 +47,7 @@ import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak; import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatusCondition; import org.keycloak.operator.crds.v2alpha1.deployment.ValueOrSecret; import org.keycloak.operator.crds.v2alpha1.deployment.spec.BootstrapAdminSpec; +import org.keycloak.operator.crds.v2alpha1.deployment.spec.FeatureSpec; import org.keycloak.operator.crds.v2alpha1.deployment.spec.HostnameSpecBuilder; import org.keycloak.operator.testsuite.unit.WatchedResourcesTest; import org.keycloak.operator.testsuite.utils.CRAssert; @@ -390,6 +391,9 @@ public class KeycloakDeploymentTest extends BaseOperatorTest { @Test public void testPodNamePropagation() { var kc = getTestKeycloakDeployment(true); + var featureSpec = new FeatureSpec(); + featureSpec.setEnabledFeatures(List.of("opentelemetry")); + kc.getSpec().setFeatureSpec(featureSpec); kc.getSpec().getAdditionalOptions().add(new ValueOrSecret("tracing-enabled", "true")); kc.getSpec().getAdditionalOptions().add(new ValueOrSecret("log-level", "io.opentelemetry:fine")); deployKeycloak(k8sclient, kc, true); diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/LoggingPropertyMappers.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/LoggingPropertyMappers.java index 9c59f15558..176eac59d0 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/LoggingPropertyMappers.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/LoggingPropertyMappers.java @@ -225,7 +225,7 @@ public final class LoggingPropertyMappers { * Add tracing info to the log if the format is not explicitly set, and tracing and {@code includeTraceOption} options are enabled */ private static Optional addTracingInfo(Optional value, Option includeTraceOption) { - var isTracingEnabled = Configuration.isTrue(TracingOptions.TRACING_ENABLED); + var isTracingEnabled = TracingPropertyMappers.isTracingEnabled(); var includeTrace = Configuration.isTrue(includeTraceOption); var isChangedLogFormat = !DEFAULT_LOG_FORMAT.equals(value.get()); diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/TracingPropertyMappers.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/TracingPropertyMappers.java index f50b59a95d..09ced24865 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/TracingPropertyMappers.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/TracingPropertyMappers.java @@ -18,6 +18,8 @@ package org.keycloak.quarkus.runtime.configuration.mappers; import io.smallrye.config.ConfigValue; +import org.keycloak.common.Profile; +import org.keycloak.quarkus.runtime.Environment; import org.keycloak.quarkus.runtime.cli.PropertyException; import org.keycloak.quarkus.runtime.configuration.Configuration; import org.keycloak.utils.StringUtil; @@ -38,7 +40,8 @@ import static org.keycloak.config.TracingOptions.TRACING_SERVICE_NAME; import static org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper.fromOption; public class TracingPropertyMappers { - private static final String TRACING_ENABLED_MSG = "Tracing is enabled"; + private static final String OTEL_FEATURE_ENABLED_MSG = "'opentelemetry' feature is enabled"; + private static final String TRACING_ENABLED_MSG = "'opentelemetry' feature and Tracing is enabled"; private TracingPropertyMappers() { } @@ -46,6 +49,7 @@ public class TracingPropertyMappers { public static PropertyMapper[] getMappers() { return new PropertyMapper[]{ fromOption(TRACING_ENABLED) + .isEnabled(TracingPropertyMappers::isFeatureEnabled, OTEL_FEATURE_ENABLED_MSG) .to("quarkus.otel.traces.enabled") .build(), fromOption(TRACING_ENDPOINT) @@ -118,6 +122,11 @@ public class TracingPropertyMappers { } } + private static boolean isFeatureEnabled() { + Environment.getCurrentOrCreateFeatureProfile(); + return Profile.isFeatureEnabled(Profile.Feature.OPENTELEMETRY); + } + public static boolean isTracingEnabled() { return Configuration.isTrue(TRACING_ENABLED); } diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/TracingDistTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/TracingDistTest.java index 0488197562..654521ef8b 100644 --- a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/TracingDistTest.java +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/TracingDistTest.java @@ -35,6 +35,7 @@ public class TracingDistTest { private void assertTracingEnabled(CLIResult result) { result.assertMessage("opentelemetry"); result.assertMessage("service.name=\"keycloak\""); + result.assertMessage("Preview features enabled: opentelemetry"); } private void assertTracingDisabled(CLIResult result) { @@ -42,6 +43,7 @@ public class TracingDistTest { result.assertNoMessage("service.name=\"keycloak\""); result.assertNoMessage("Failed to export spans."); result.assertNoMessage("Connection refused: localhost/127.0.0.1:4317"); + result.assertNoMessage("Preview features enabled: opentelemetry"); } @Test @@ -56,16 +58,34 @@ public class TracingDistTest { @Test @Order(2) - @Launch({"start-dev", "--tracing-enabled=true", "--log-level=io.opentelemetry:fine"}) - void enabledJdbc(LaunchResult result) { + @Launch({"start-dev", "--tracing-service-name=should-fail"}) + void disabledOption(LaunchResult result) { CLIResult cliResult = (CLIResult) result; - cliResult.assertStartedDevMode(); - assertTracingEnabled(cliResult); + cliResult.assertError("Disabled option: '--tracing-service-name'. Available only when 'opentelemetry' feature and Tracing is enabled"); } + @Test @Order(3) - @Launch({"build", "--tracing-enabled=true"}) + @Launch({"start-dev", "--tracing-enabled=true"}) + void disabledFeature(LaunchResult result) { + CLIResult cliResult = (CLIResult) result; + + cliResult.assertError("Disabled option: '--tracing-enabled'. Available only when 'opentelemetry' feature is enabled"); + } + + @Test + @Order(4) + @Launch({"start-dev", "--features=opentelemetry", "--tracing-enabled=false", "--tracing-endpoint=something"}) + void disabledTracing(LaunchResult result) { + CLIResult cliResult = (CLIResult) result; + + cliResult.assertError("Disabled option: '--tracing-endpoint'. Available only when 'opentelemetry' feature and Tracing is enabled"); + } + + @Test + @Order(5) + @Launch({"build", "--tracing-enabled=true", "--features=opentelemetry"}) void buildTracingEnabled(LaunchResult result) { CLIResult cliResult = (CLIResult) result; diff --git a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testExportHelpAll.approved.txt b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testExportHelpAll.approved.txt index e13bcd1da4..a5b6fbef48 100644 --- a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testExportHelpAll.approved.txt +++ b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testExportHelpAll.approved.txt @@ -176,37 +176,38 @@ Tracing (Preview): --tracing-compression Preview: OpenTelemetry compression method used to compress payloads. If unset, compression is disabled. Possible values are: gzip, none. Default: none. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-enabled - Preview: Enables the OpenTelemetry tracing. Default: false. + Preview: Enables the OpenTelemetry tracing. Default: false. Available only + when 'opentelemetry' feature is enabled. --tracing-endpoint Preview: OpenTelemetry endpoint to connect to. Default: http://localhost:4317. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-jdbc-enabled Preview: Enables the OpenTelemetry JDBC tracing. Default: true. Available only - when Tracing is enabled. + when 'opentelemetry' feature and Tracing is enabled. --tracing-protocol Preview: OpenTelemetry protocol used for the telemetry data. Possible values - are: grpc, http/protobuf. Default: grpc. Available only when Tracing is - enabled. + are: grpc, http/protobuf. Default: grpc. Available only when 'opentelemetry' + feature and Tracing is enabled. --tracing-resource-attributes Preview: OpenTelemetry resource attributes present in the exported trace to characterize the telemetry producer. Values in format 'key1=val1,key2=val2'. - For more information, check the Tracing guide. Available only when Tracing - is enabled. + For more information, check the Tracing guide. Available only when + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-ratio Preview: OpenTelemetry sampler ratio. Probability that a span will be sampled. Expected double value in interval <0,1). Default: 1.0. Available only when - Tracing is enabled. + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-type Preview: OpenTelemetry sampler to use for tracing. Possible values are: always_on, always_off, traceidratio, parentbased_always_on, parentbased_always_off, parentbased_traceidratio. Default: traceidratio. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-service-name Preview: OpenTelemetry service name. Takes precedence over 'service.name' defined in the 'tracing-resource-attributes' property. Default: keycloak. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. Truststore: diff --git a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testImportHelpAll.approved.txt b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testImportHelpAll.approved.txt index 2ef0c9fc3a..f4ffcab687 100644 --- a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testImportHelpAll.approved.txt +++ b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testImportHelpAll.approved.txt @@ -176,37 +176,38 @@ Tracing (Preview): --tracing-compression Preview: OpenTelemetry compression method used to compress payloads. If unset, compression is disabled. Possible values are: gzip, none. Default: none. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-enabled - Preview: Enables the OpenTelemetry tracing. Default: false. + Preview: Enables the OpenTelemetry tracing. Default: false. Available only + when 'opentelemetry' feature is enabled. --tracing-endpoint Preview: OpenTelemetry endpoint to connect to. Default: http://localhost:4317. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-jdbc-enabled Preview: Enables the OpenTelemetry JDBC tracing. Default: true. Available only - when Tracing is enabled. + when 'opentelemetry' feature and Tracing is enabled. --tracing-protocol Preview: OpenTelemetry protocol used for the telemetry data. Possible values - are: grpc, http/protobuf. Default: grpc. Available only when Tracing is - enabled. + are: grpc, http/protobuf. Default: grpc. Available only when 'opentelemetry' + feature and Tracing is enabled. --tracing-resource-attributes Preview: OpenTelemetry resource attributes present in the exported trace to characterize the telemetry producer. Values in format 'key1=val1,key2=val2'. - For more information, check the Tracing guide. Available only when Tracing - is enabled. + For more information, check the Tracing guide. Available only when + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-ratio Preview: OpenTelemetry sampler ratio. Probability that a span will be sampled. Expected double value in interval <0,1). Default: 1.0. Available only when - Tracing is enabled. + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-type Preview: OpenTelemetry sampler to use for tracing. Possible values are: always_on, always_off, traceidratio, parentbased_always_on, parentbased_always_off, parentbased_traceidratio. Default: traceidratio. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-service-name Preview: OpenTelemetry service name. Takes precedence over 'service.name' defined in the 'tracing-resource-attributes' property. Default: keycloak. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. Truststore: diff --git a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartDevHelpAll.approved.txt b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartDevHelpAll.approved.txt index e67a16b87e..4a8c258e9b 100644 --- a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartDevHelpAll.approved.txt +++ b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartDevHelpAll.approved.txt @@ -352,37 +352,38 @@ Tracing (Preview): --tracing-compression Preview: OpenTelemetry compression method used to compress payloads. If unset, compression is disabled. Possible values are: gzip, none. Default: none. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-enabled - Preview: Enables the OpenTelemetry tracing. Default: false. + Preview: Enables the OpenTelemetry tracing. Default: false. Available only + when 'opentelemetry' feature is enabled. --tracing-endpoint Preview: OpenTelemetry endpoint to connect to. Default: http://localhost:4317. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-jdbc-enabled Preview: Enables the OpenTelemetry JDBC tracing. Default: true. Available only - when Tracing is enabled. + when 'opentelemetry' feature and Tracing is enabled. --tracing-protocol Preview: OpenTelemetry protocol used for the telemetry data. Possible values - are: grpc, http/protobuf. Default: grpc. Available only when Tracing is - enabled. + are: grpc, http/protobuf. Default: grpc. Available only when 'opentelemetry' + feature and Tracing is enabled. --tracing-resource-attributes Preview: OpenTelemetry resource attributes present in the exported trace to characterize the telemetry producer. Values in format 'key1=val1,key2=val2'. - For more information, check the Tracing guide. Available only when Tracing - is enabled. + For more information, check the Tracing guide. Available only when + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-ratio Preview: OpenTelemetry sampler ratio. Probability that a span will be sampled. Expected double value in interval <0,1). Default: 1.0. Available only when - Tracing is enabled. + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-type Preview: OpenTelemetry sampler to use for tracing. Possible values are: always_on, always_off, traceidratio, parentbased_always_on, parentbased_always_off, parentbased_traceidratio. Default: traceidratio. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-service-name Preview: OpenTelemetry service name. Takes precedence over 'service.name' defined in the 'tracing-resource-attributes' property. Default: keycloak. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. Truststore: diff --git a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartHelpAll.approved.txt b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartHelpAll.approved.txt index ce36ad4b88..37aa6d3b85 100644 --- a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartHelpAll.approved.txt +++ b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartHelpAll.approved.txt @@ -353,37 +353,38 @@ Tracing (Preview): --tracing-compression Preview: OpenTelemetry compression method used to compress payloads. If unset, compression is disabled. Possible values are: gzip, none. Default: none. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-enabled - Preview: Enables the OpenTelemetry tracing. Default: false. + Preview: Enables the OpenTelemetry tracing. Default: false. Available only + when 'opentelemetry' feature is enabled. --tracing-endpoint Preview: OpenTelemetry endpoint to connect to. Default: http://localhost:4317. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-jdbc-enabled Preview: Enables the OpenTelemetry JDBC tracing. Default: true. Available only - when Tracing is enabled. + when 'opentelemetry' feature and Tracing is enabled. --tracing-protocol Preview: OpenTelemetry protocol used for the telemetry data. Possible values - are: grpc, http/protobuf. Default: grpc. Available only when Tracing is - enabled. + are: grpc, http/protobuf. Default: grpc. Available only when 'opentelemetry' + feature and Tracing is enabled. --tracing-resource-attributes Preview: OpenTelemetry resource attributes present in the exported trace to characterize the telemetry producer. Values in format 'key1=val1,key2=val2'. - For more information, check the Tracing guide. Available only when Tracing - is enabled. + For more information, check the Tracing guide. Available only when + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-ratio Preview: OpenTelemetry sampler ratio. Probability that a span will be sampled. Expected double value in interval <0,1). Default: 1.0. Available only when - Tracing is enabled. + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-type Preview: OpenTelemetry sampler to use for tracing. Possible values are: always_on, always_off, traceidratio, parentbased_always_on, parentbased_always_off, parentbased_traceidratio. Default: traceidratio. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-service-name Preview: OpenTelemetry service name. Takes precedence over 'service.name' defined in the 'tracing-resource-attributes' property. Default: keycloak. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. Truststore: diff --git a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartOptimizedHelpAll.approved.txt b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartOptimizedHelpAll.approved.txt index 08a66f4029..220af25640 100644 --- a/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartOptimizedHelpAll.approved.txt +++ b/quarkus/tests/integration/src/test/resources/org/keycloak/it/cli/dist/approvals/cli/help/HelpCommandDistTest.testStartOptimizedHelpAll.approved.txt @@ -304,27 +304,27 @@ Tracing (Preview): --tracing-compression Preview: OpenTelemetry compression method used to compress payloads. If unset, compression is disabled. Possible values are: gzip, none. Default: none. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-endpoint Preview: OpenTelemetry endpoint to connect to. Default: http://localhost:4317. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. --tracing-protocol Preview: OpenTelemetry protocol used for the telemetry data. Possible values - are: grpc, http/protobuf. Default: grpc. Available only when Tracing is - enabled. + are: grpc, http/protobuf. Default: grpc. Available only when 'opentelemetry' + feature and Tracing is enabled. --tracing-resource-attributes Preview: OpenTelemetry resource attributes present in the exported trace to characterize the telemetry producer. Values in format 'key1=val1,key2=val2'. - For more information, check the Tracing guide. Available only when Tracing - is enabled. + For more information, check the Tracing guide. Available only when + 'opentelemetry' feature and Tracing is enabled. --tracing-sampler-ratio Preview: OpenTelemetry sampler ratio. Probability that a span will be sampled. Expected double value in interval <0,1). Default: 1.0. Available only when - Tracing is enabled. + 'opentelemetry' feature and Tracing is enabled. --tracing-service-name Preview: OpenTelemetry service name. Takes precedence over 'service.name' defined in the 'tracing-resource-attributes' property. Default: keycloak. - Available only when Tracing is enabled. + Available only when 'opentelemetry' feature and Tracing is enabled. Truststore: