Skip to content

Commit 21508ed

Browse files
authored
Merge pull request #42 from traceroot-ai/feat/add_tencent_apm_endpoint
feat: support customize tencent cloud apm endpoint
2 parents 887effd + eb71073 commit 21508ed

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

examples/tencent-logback-example/src/main/java/com/example/StandaloneExample.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ private static void initializeTraceRoot() {
7676
System.getenv("TENCENT_SECRET_ID")); // Required: Get from environment
7777
tencentCredentials.setSecretKey(
7878
System.getenv("TENCENT_SECRET_KEY")); // Required: Get from environment
79-
tencentCredentials.setRegion("ap-hongkong"); // Optional: defaults to ap-hongkong
79+
tencentCredentials.setRegion("na-siliconvalley"); // Optional: defaults to ap-hongkong
8080
tencentCredentials.setLogset(
8181
System.getenv("TENCENT_LOGSET")); // Optional: CLS logset name (like AWS log group)
8282
tencentCredentials.setTraceToken(
8383
System.getenv("TRACE_TOKEN")); // Required: Tencent APM trace token for authentication
84+
tencentCredentials.setOtlpEndpoint(
85+
System.getenv("TENCENT_APM_ENDPOINT")); // Optional: Custom APM endpoint (overrides default pattern)
8486

8587
// Set credentials on config
8688
config.setTencentCredentials(tencentCredentials);

src/main/java/ai/traceroot/sdk/tracer/TraceRootTracer.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,31 @@ private void prepareAwsConfig() {
288288
private void prepareTencentConfig() {
289289
// For Tencent, we use the configured credentials and construct the OTLP endpoint
290290
if (config.getTencentCredentials() != null) {
291-
String region = config.getTencentCredentials().getRegion();
292-
if (region == null) {
293-
region = TraceRootConstants.TENCENT_DEFAULT_REGION; // Default region
294-
}
291+
String tencentOtlpEndpoint = config.getTencentCredentials().getOtlpEndpoint();
295292

296-
// Construct the endpoint based on the region
297-
String tencentOtlpEndpoint =
298-
String.format(TraceRootConstants.TENCENT_APM_ENDPOINT_PATTERN, region);
293+
// Only construct endpoint from pattern if not already specified
294+
if (tencentOtlpEndpoint == null || tencentOtlpEndpoint.isEmpty()) {
295+
String region = config.getTencentCredentials().getRegion();
296+
if (region == null) {
297+
region = TraceRootConstants.TENCENT_DEFAULT_REGION; // Default region
298+
}
299299

300-
config.getTencentCredentials().setOtlpEndpoint(tencentOtlpEndpoint);
301-
config.setOtlpEndpoint(tencentOtlpEndpoint);
300+
// Construct the endpoint based on the region
301+
tencentOtlpEndpoint =
302+
String.format(TraceRootConstants.TENCENT_APM_ENDPOINT_PATTERN, region);
302303

303-
if (config.isTracerVerbose()) {
304-
logger.debug("[TraceRoot] Tencent Cloud APM endpoint configured: {}", tencentOtlpEndpoint);
304+
config.getTencentCredentials().setOtlpEndpoint(tencentOtlpEndpoint);
305+
306+
if (config.isTracerVerbose()) {
307+
logger.debug("[TraceRoot] Tencent Cloud APM endpoint auto-configured: {}", tencentOtlpEndpoint);
308+
}
309+
} else {
310+
if (config.isTracerVerbose()) {
311+
logger.debug("[TraceRoot] Using user-specified Tencent Cloud APM endpoint: {}", tencentOtlpEndpoint);
312+
}
305313
}
314+
315+
config.setOtlpEndpoint(tencentOtlpEndpoint);
306316
} else {
307317
logger.error("[TraceRoot] Tencent provider selected but no Tencent credentials configured");
308318
}

0 commit comments

Comments
 (0)