Skip to content

Commit 9d7d3c9

Browse files
committed
support use custom trace path
1 parent 6d2c7fb commit 9d7d3c9

File tree

15 files changed

+56
-15
lines changed

15 files changed

+56
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.3] - 2026-02-24
9+
### Added
10+
- **Trace**: Support use custom trace path
811

912
## [0.1.2] - 2026-02-04
1013
### Changed

cozeloop-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>com.coze</groupId>
1010
<artifactId>cozeloop-java</artifactId>
11-
<version>0.1.2</version>
11+
<version>0.1.3</version>
1212
<relativePath>../pom.xml</relativePath>
1313
</parent>
1414

cozeloop-core/src/main/java/com/coze/loop/auth/JWTOAuthAuth.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public String getToken() {
125125

126126
@Override
127127
public String getType() {
128-
return AUTH_TYPE;
128+
return AUTH_TYPE + " ";
129129
}
130130

131131
/** Check if token should be refreshed. */
@@ -162,7 +162,7 @@ private void refreshToken() {
162162
body.put("grant_type", GRANT_TYPE_JWT);
163163

164164
Map<String, String> headers = new HashMap<>();
165-
headers.put("Authorization", "Bearer " + jwt);
165+
headers.put("Authorization", this.getType() + jwt);
166166

167167
String responseJson = httpClient.post(baseUrl + TOKEN_PATH, body, headers);
168168
TokenResponse resp = JsonUtils.fromJson(responseJson, TokenResponse.class);

cozeloop-core/src/main/java/com/coze/loop/auth/TokenAuth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public String getToken() {
3030

3131
@Override
3232
public String getType() {
33-
return AUTH_TYPE;
33+
return AUTH_TYPE + " ";
3434
}
3535
}

cozeloop-core/src/main/java/com/coze/loop/client/CozeLoopClientBuilder.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ private void loadByEnv() {
3434
if (serviceName != null) {
3535
this.config.setServiceName(serviceName);
3636
}
37+
// Load trace path
38+
String tracePath = System.getenv("COZELOOP_TRACE_PATH");
39+
if (tracePath != null) {
40+
this.config.setTracePath(tracePath);
41+
}
3742
// Load auth token
3843
String token = System.getenv("COZELOOP_API_TOKEN");
3944
if (token != null) {
@@ -61,6 +66,12 @@ private void loadByProperties() {
6166
this.config.setServiceName(serviceName);
6267
}
6368

69+
// Load trace path
70+
String tracePath = ConfigUtils.get("cozeloop.trace-path");
71+
if (tracePath != null) {
72+
this.config.setTracePath(tracePath);
73+
}
74+
6475
// Load auth token
6576
String token = ConfigUtils.get("cozeloop.auth.token");
6677
if (token != null) {
@@ -108,6 +119,17 @@ public CozeLoopClientBuilder baseUrl(String baseUrl) {
108119
return this;
109120
}
110121

122+
/**
123+
* Set trace path (optional, default: "/v1/loop/opentelemetry/v1/traces").
124+
*
125+
* @param tracePath the trace path
126+
* @return this builder
127+
*/
128+
public CozeLoopClientBuilder tracePath(String tracePath) {
129+
config.setTracePath(tracePath);
130+
return this;
131+
}
132+
111133
/**
112134
* Set configuration (optional).
113135
*

cozeloop-core/src/main/java/com/coze/loop/config/CozeLoopConfig.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
/** Main configuration for CozeLoop Client. */
88
public class CozeLoopConfig {
9+
private static final String DEFAULT_TRACE_PATH = "/v1/loop/opentelemetry/v1/traces";
10+
911
private String workspaceId = System.getenv("COZELOOP_WORKSPACE_ID");
1012
private String serviceName = "cozeloop-java-app";
1113
private String baseUrl = "https://api.coze.cn";
14+
private String tracePath = DEFAULT_TRACE_PATH;
1215

1316
private HttpConfig httpConfig;
1417
private CozeLoopTracerProvider.TraceConfig traceConfig;
@@ -45,6 +48,14 @@ public void setBaseUrl(String baseUrl) {
4548
this.baseUrl = baseUrl;
4649
}
4750

51+
public String getTracePath() {
52+
return tracePath;
53+
}
54+
55+
public void setTracePath(String tracePath) {
56+
this.tracePath = tracePath;
57+
}
58+
4859
public HttpConfig getHttpConfig() {
4960
return httpConfig;
5061
}
@@ -71,7 +82,7 @@ public void setPromptCacheConfig(PromptCache.PromptCacheConfig promptCacheConfig
7182

7283
/** Get span endpoint URL. */
7384
public String getSpanEndpoint() {
74-
return baseUrl + "/v1/loop/opentelemetry/v1/traces";
85+
return baseUrl + tracePath;
7586
}
7687

7788
/** Get prompt endpoint URL for fetching prompts (mget). */
@@ -111,6 +122,11 @@ public Builder baseUrl(String baseUrl) {
111122
return this;
112123
}
113124

125+
public Builder tracePath(String tracePath) {
126+
config.tracePath = tracePath;
127+
return this;
128+
}
129+
114130
public Builder httpConfig(HttpConfig httpConfig) {
115131
config.httpConfig = httpConfig;
116132
return this;

cozeloop-core/src/main/java/com/coze/loop/http/AuthInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Response intercept(Chain chain) throws IOException {
3737
Request.Builder builder =
3838
original
3939
.newBuilder()
40-
.header("Authorization", authType + " " + token)
40+
.header("Authorization", authType + token)
4141
.header("User-Agent", UserAgentUtils.getUserAgent())
4242
.header("X-Coze-Client-User-Agent", UserAgentUtils.getClientUserAgent());
4343

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.coze.loop.internal;
22

33
public class Constants {
4-
public static final String Version = "0.1.2";
4+
public static final String Version = "0.1.3";
55
public static final String TraceContextHeaderParent = "X-Cozeloop-Traceparent";
66
public static final String TraceContextHeaderBaggage = "X-Cozeloop-Tracestate";
77
}

cozeloop-core/src/main/java/com/coze/loop/trace/CozeLoopTracerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private CozeLoopTracerProvider(
104104
() -> {
105105
Map<String, String> headers = new HashMap<>();
106106
headers.put("cozeloop-workspace-id", workspaceId);
107-
headers.put("Authorization", "Bearer " + auth.getToken());
107+
headers.put("Authorization", auth.getType() + auth.getToken());
108108
headers.put("User-Agent", UserAgentUtils.getUserAgent());
109109
headers.put("X-Coze-Client-User-Agent", UserAgentUtils.getClientUserAgent());
110110

cozeloop-core/src/test/java/com/coze/loop/auth/TokenAuthTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void testConstructorWithValidToken() {
1515
TokenAuth auth = new TokenAuth("test-token");
1616

1717
assertThat(auth.getToken()).isEqualTo("test-token");
18-
assertThat(auth.getType()).isEqualTo("Bearer");
18+
assertThat(auth.getType()).isEqualTo("Bearer ");
1919
}
2020

2121
@Test
@@ -63,6 +63,6 @@ void testGetToken() {
6363
@Test
6464
void testGetType() {
6565
TokenAuth auth = new TokenAuth("token");
66-
assertThat(auth.getType()).isEqualTo("Bearer");
66+
assertThat(auth.getType()).isEqualTo("Bearer ");
6767
}
6868
}

0 commit comments

Comments
 (0)