Skip to content

Commit a69d8dc

Browse files
committed
Support record event when finish and export and change log prefix
1 parent 9d7d3c9 commit a69d8dc

28 files changed

Lines changed: 876 additions & 41 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ 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.4] - 2026-02-26
9+
### Changed
10+
- **Trace**: Support record event when finish and export
11+
- **Log**: Change log prefix
12+
813
## [0.1.3] - 2026-02-24
914
### Added
1015
- **Trace**: Support use custom trace path

cozeloop-core/pom.xml

Lines changed: 6 additions & 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.3</version>
11+
<version>0.1.4</version>
1212
<relativePath>../pom.xml</relativePath>
1313
</parent>
1414

@@ -74,6 +74,11 @@
7474
<artifactId>opentelemetry-exporter-otlp</artifactId>
7575
<version>1.47.0</version>
7676
</dependency>
77+
<dependency>
78+
<groupId>io.opentelemetry</groupId>
79+
<artifactId>opentelemetry-exporter-otlp-common</artifactId>
80+
<version>1.47.0</version>
81+
</dependency>
7782

7883
<!-- HTTP Client -->
7984
<dependency>

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
@@ -11,11 +11,11 @@
1111
import java.util.concurrent.locks.ReentrantReadWriteLock;
1212

1313
import org.slf4j.Logger;
14-
import org.slf4j.LoggerFactory;
1514

1615
import com.coze.loop.exception.AuthException;
1716
import com.coze.loop.exception.ErrorCode;
1817
import com.coze.loop.http.HttpClient;
18+
import com.coze.loop.internal.CozeLoopLogger;
1919
import com.coze.loop.internal.JsonUtils;
2020
import com.coze.loop.internal.ValidationUtils;
2121
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -28,7 +28,7 @@
2828
* automatically refreshes tokens.
2929
*/
3030
public class JWTOAuthAuth implements Auth {
31-
private static final Logger logger = LoggerFactory.getLogger(JWTOAuthAuth.class);
31+
private static final Logger logger = CozeLoopLogger.getLogger(JWTOAuthAuth.class);
3232
private static final String AUTH_TYPE = "Bearer";
3333
private static final String GRANT_TYPE_JWT = "urn:ietf:params:oauth:grant-type:jwt-bearer";
3434
private static final String TOKEN_PATH = "/api/permission/oauth2/token";

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.coze.loop.internal.ValidationUtils;
1212
import com.coze.loop.prompt.PromptProvider;
1313
import com.coze.loop.trace.CozeLoopTracerProvider;
14+
import com.coze.loop.trace.FinishEventProcessor;
1415

1516
/** Builder for creating CozeLoopClient instances. */
1617
public class CozeLoopClientBuilder {
@@ -176,6 +177,17 @@ public CozeLoopClientBuilder auth(Auth auth) {
176177
return this;
177178
}
178179

180+
/**
181+
* Set finish event processor for span finish events.
182+
*
183+
* @param processor the finish event processor
184+
* @return this builder
185+
*/
186+
public CozeLoopClientBuilder finishEventProcessor(FinishEventProcessor processor) {
187+
config.getTraceConfig().setFinishEventProcessor(processor);
188+
return this;
189+
}
190+
179191
/**
180192
* Build the CozeLoopClient instance.
181193
*

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.concurrent.atomic.AtomicBoolean;
66

77
import org.slf4j.Logger;
8-
import org.slf4j.LoggerFactory;
98

109
import com.coze.loop.entity.ExecuteParam;
1110
import com.coze.loop.entity.ExecuteResult;
@@ -15,6 +14,7 @@
1514
import com.coze.loop.exception.ErrorCode;
1615
import com.coze.loop.http.HttpClient;
1716
import com.coze.loop.internal.Constants;
17+
import com.coze.loop.internal.CozeLoopLogger;
1818
import com.coze.loop.prompt.GetPromptParam;
1919
import com.coze.loop.prompt.PromptProvider;
2020
import com.coze.loop.spec.tracespec.SpanKeys;
@@ -34,7 +34,7 @@
3434

3535
/** Implementation of CozeLoopClient. */
3636
public class CozeLoopClientImpl implements CozeLoopClient {
37-
private static final Logger logger = LoggerFactory.getLogger(CozeLoopClientImpl.class);
37+
private static final Logger logger = CozeLoopLogger.getLogger(CozeLoopClientImpl.class);
3838
private static final String INSTRUMENTATION_NAME = "cozeloop-java-sdk";
3939
private static final String INSTRUMENTATION_VERSION = Constants.Version;
4040

@@ -137,7 +137,12 @@ public CozeLoopSpan startSpan(
137137
Scope scope = finalContext.makeCurrent();
138138

139139
return new CozeLoopSpan(
140-
span, scope, tracerProvider.getPropagators(), new CozeLoopContext(finalContext), scene);
140+
span,
141+
scope,
142+
tracerProvider.getPropagators(),
143+
new CozeLoopContext(finalContext),
144+
scene,
145+
tracerProvider.getFinishEventProcessor());
141146
}
142147

143148
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
import java.util.concurrent.TimeUnit;
55

66
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
87

98
import com.coze.loop.auth.Auth;
109
import com.coze.loop.exception.CozeLoopException;
1110
import com.coze.loop.exception.ErrorCode;
11+
import com.coze.loop.internal.CozeLoopLogger;
1212
import com.coze.loop.internal.JsonUtils;
1313

1414
import io.opentelemetry.context.propagation.ContextPropagators;
1515
import okhttp3.*;
1616

1717
/** HTTP client based on OkHttp. */
1818
public class HttpClient {
19-
private static final Logger logger = LoggerFactory.getLogger(HttpClient.class);
19+
private static final Logger logger = CozeLoopLogger.getLogger(HttpClient.class);
2020
private static final MediaType JSON_MEDIA_TYPE =
2121
MediaType.parse("application/json; charset=utf-8");
2222

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import java.io.IOException;
44

55
import org.slf4j.Logger;
6-
import org.slf4j.LoggerFactory;
6+
7+
import com.coze.loop.internal.CozeLoopLogger;
78

89
import okhttp3.Interceptor;
910
import okhttp3.Request;
@@ -12,7 +13,7 @@
1213

1314
/** Interceptor to log HTTP requests and responses. */
1415
public class LoggingInterceptor implements Interceptor {
15-
private static final Logger logger = LoggerFactory.getLogger(LoggingInterceptor.class);
16+
private static final Logger logger = CozeLoopLogger.getLogger(LoggingInterceptor.class);
1617

1718
@Override
1819
public Response intercept(Chain chain) throws IOException {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import java.util.concurrent.TimeUnit;
55

66
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
7+
8+
import com.coze.loop.internal.CozeLoopLogger;
89

910
import okhttp3.Interceptor;
1011
import okhttp3.Request;
1112
import okhttp3.Response;
1213

1314
/** Interceptor to retry failed requests with exponential backoff. */
1415
public class RetryInterceptor implements Interceptor {
15-
private static final Logger logger = LoggerFactory.getLogger(RetryInterceptor.class);
16+
private static final Logger logger = CozeLoopLogger.getLogger(RetryInterceptor.class);
1617
private static final int INITIAL_BACKOFF_MS = 100;
1718
private static final int MAX_BACKOFF_MS = 10000;
1819

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.3";
4+
public static final String Version = "0.1.4";
55
public static final String TraceContextHeaderParent = "X-Cozeloop-Traceparent";
66
public static final String TraceContextHeaderBaggage = "X-Cozeloop-Tracestate";
77
}

0 commit comments

Comments
 (0)