From 1b52715e1cc12a3d907a9c419f0a9e8cfd9239e1 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 21 May 2026 12:10:22 +0200 Subject: [PATCH] chore: Enable simple tracer standby in dev profile The backlog tracer already had standby auto-enabled in dev mode, but the simple log tracer (controlled by --trace) did not. This meant users had to restart with --trace to get log-based tracing, even during development. Now both tracers are in standby mode in the dev profile, so tracing can be toggled on at runtime via Tracer.setEnabled(true) or JMX without restarting. Co-Authored-By: Claude Opus 4.6 --- .../apache/camel/main/ProfileConfigurer.java | 3 + .../MainDevProfileTracingStandbyTest.java | 85 +++++++++++++++++++ .../modules/ROOT/pages/tracer.adoc | 3 + 3 files changed, 91 insertions(+) create mode 100644 core/camel-main/src/test/java/org/apache/camel/main/MainDevProfileTracingStandbyTest.java diff --git a/core/camel-main/src/main/java/org/apache/camel/main/ProfileConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/ProfileConfigurer.java index 983e4dc1e530e..dd6b6b5643f59 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/ProfileConfigurer.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/ProfileConfigurer.java @@ -49,6 +49,9 @@ public static void configureMain(CamelContext camelContext, String profile, Main if (!enabled) { config.tracerConfig().withStandby(true); } + if (!config.isTracing()) { + config.setTracingStandby(true); + } } if ("dev".equals(profile)) { diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainDevProfileTracingStandbyTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainDevProfileTracingStandbyTest.java new file mode 100644 index 0000000000000..12efd09d0674c --- /dev/null +++ b/core/camel-main/src/test/java/org/apache/camel/main/MainDevProfileTracingStandbyTest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.main; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spi.Tracer; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MainDevProfileTracingStandbyTest { + + @Test + public void testDevProfileEnablesTracingStandby() { + Main main = new Main(); + main.configure().withProfile("dev"); + + main.start(); + try { + CamelContext context = main.getCamelContext(); + assertTrue(context.isTracingStandby(), + "dev profile should enable tracing standby"); + } finally { + main.stop(); + } + } + + @Test + public void testDevProfileTracingCanBeEnabledAtRuntime() throws Exception { + Main main = new Main(); + main.configure().withProfile("dev"); + main.configure().addRoutesBuilder(new RouteBuilder() { + @Override + public void configure() { + from("direct:start").to("mock:result"); + } + }); + + main.start(); + try { + CamelContext context = main.getCamelContext(); + Tracer tracer = context.getTracer(); + assertFalse(tracer.isEnabled(), + "tracer should be in standby (not enabled) by default in dev mode"); + + tracer.setEnabled(true); + assertTrue(tracer.isEnabled(), + "tracer should be enableable at runtime in dev mode"); + } finally { + main.stop(); + } + } + + @Test + public void testProdProfileDoesNotEnableTracingStandby() { + Main main = new Main(); + main.configure().withProfile("prod"); + + main.start(); + try { + CamelContext context = main.getCamelContext(); + assertFalse(context.isTracingStandby(), + "prod profile should not enable tracing standby"); + } finally { + main.stop(); + } + } + +} diff --git a/docs/user-manual/modules/ROOT/pages/tracer.adoc b/docs/user-manual/modules/ROOT/pages/tracer.adoc index 5b42ae28f3fdc..dbcbddb6f5cf9 100644 --- a/docs/user-manual/modules/ROOT/pages/tracer.adoc +++ b/docs/user-manual/modules/ROOT/pages/tracer.adoc @@ -45,6 +45,9 @@ camel.main.tracing = true By default, Camel optimizes and opt-out tracing. Therefore, you would either have to enable tracing from the startup, or turn on standby mode, to allow tracing to be enabled later during runtime. +NOTE: When using Camel Main or Camel JBang with the `dev` profile (the default), tracing standby is automatically enabled. +This means you can toggle tracing on and off at runtime without needing to restart. + To set tracing in standby mode you can do: [tabs]