From eb710739f2edee5aa074264871d6f1d154a43a90 Mon Sep 17 00:00:00 2001 From: Zecheng Zhang Date: Mon, 20 Oct 2025 15:13:49 -0700 Subject: [PATCH] feat: support customize tencent cloud apm endpoint --- .../java/com/example/StandaloneExample.java | 4 ++- .../traceroot/sdk/tracer/TraceRootTracer.java | 32 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/examples/tencent-logback-example/src/main/java/com/example/StandaloneExample.java b/examples/tencent-logback-example/src/main/java/com/example/StandaloneExample.java index 5bb7f37..056ceaf 100644 --- a/examples/tencent-logback-example/src/main/java/com/example/StandaloneExample.java +++ b/examples/tencent-logback-example/src/main/java/com/example/StandaloneExample.java @@ -76,11 +76,13 @@ private static void initializeTraceRoot() { System.getenv("TENCENT_SECRET_ID")); // Required: Get from environment tencentCredentials.setSecretKey( System.getenv("TENCENT_SECRET_KEY")); // Required: Get from environment - tencentCredentials.setRegion("ap-hongkong"); // Optional: defaults to ap-hongkong + tencentCredentials.setRegion("na-siliconvalley"); // Optional: defaults to ap-hongkong tencentCredentials.setLogset( System.getenv("TENCENT_LOGSET")); // Optional: CLS logset name (like AWS log group) tencentCredentials.setTraceToken( System.getenv("TRACE_TOKEN")); // Required: Tencent APM trace token for authentication + tencentCredentials.setOtlpEndpoint( + System.getenv("TENCENT_APM_ENDPOINT")); // Optional: Custom APM endpoint (overrides default pattern) // Set credentials on config config.setTencentCredentials(tencentCredentials); diff --git a/src/main/java/ai/traceroot/sdk/tracer/TraceRootTracer.java b/src/main/java/ai/traceroot/sdk/tracer/TraceRootTracer.java index e2685fe..323dba8 100644 --- a/src/main/java/ai/traceroot/sdk/tracer/TraceRootTracer.java +++ b/src/main/java/ai/traceroot/sdk/tracer/TraceRootTracer.java @@ -288,21 +288,31 @@ private void prepareAwsConfig() { private void prepareTencentConfig() { // For Tencent, we use the configured credentials and construct the OTLP endpoint if (config.getTencentCredentials() != null) { - String region = config.getTencentCredentials().getRegion(); - if (region == null) { - region = TraceRootConstants.TENCENT_DEFAULT_REGION; // Default region - } + String tencentOtlpEndpoint = config.getTencentCredentials().getOtlpEndpoint(); - // Construct the endpoint based on the region - String tencentOtlpEndpoint = - String.format(TraceRootConstants.TENCENT_APM_ENDPOINT_PATTERN, region); + // Only construct endpoint from pattern if not already specified + if (tencentOtlpEndpoint == null || tencentOtlpEndpoint.isEmpty()) { + String region = config.getTencentCredentials().getRegion(); + if (region == null) { + region = TraceRootConstants.TENCENT_DEFAULT_REGION; // Default region + } - config.getTencentCredentials().setOtlpEndpoint(tencentOtlpEndpoint); - config.setOtlpEndpoint(tencentOtlpEndpoint); + // Construct the endpoint based on the region + tencentOtlpEndpoint = + String.format(TraceRootConstants.TENCENT_APM_ENDPOINT_PATTERN, region); - if (config.isTracerVerbose()) { - logger.debug("[TraceRoot] Tencent Cloud APM endpoint configured: {}", tencentOtlpEndpoint); + config.getTencentCredentials().setOtlpEndpoint(tencentOtlpEndpoint); + + if (config.isTracerVerbose()) { + logger.debug("[TraceRoot] Tencent Cloud APM endpoint auto-configured: {}", tencentOtlpEndpoint); + } + } else { + if (config.isTracerVerbose()) { + logger.debug("[TraceRoot] Using user-specified Tencent Cloud APM endpoint: {}", tencentOtlpEndpoint); + } } + + config.setOtlpEndpoint(tencentOtlpEndpoint); } else { logger.error("[TraceRoot] Tencent provider selected but no Tencent credentials configured"); }