diff --git a/agentscope-core/pom.xml b/agentscope-core/pom.xml index 54bf500a7..b5bb9a12b 100644 --- a/agentscope-core/pom.xml +++ b/agentscope-core/pom.xml @@ -140,5 +140,11 @@ com.networknt json-schema-validator + + + io.opentelemetry + opentelemetry-api + test + diff --git a/agentscope-core/src/main/java/io/agentscope/core/hook/recorder/JsonlTraceExporter.java b/agentscope-core/src/main/java/io/agentscope/core/hook/recorder/JsonlTraceExporter.java index 9054e5d50..9d60df268 100644 --- a/agentscope-core/src/main/java/io/agentscope/core/hook/recorder/JsonlTraceExporter.java +++ b/agentscope-core/src/main/java/io/agentscope/core/hook/recorder/JsonlTraceExporter.java @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.OpenOption; @@ -47,12 +48,21 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; +import java.util.WeakHashMap; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; /** * A built-in, out-of-the-box JSONL trace exporter based on the Hook event system. @@ -65,13 +75,15 @@ *
AgentScope core does not depend on OpenTelemetry directly. JsonlTraceExporter uses reflection - * to attach trace_id/span_id when OpenTelemetry is present at runtime. These stubs let us cover - * that branch in unit tests without adding a core dependency. - */ -public final class Span { - - private static volatile Span current = new Span(new SpanContext(false, "", "")); - - private final SpanContext context; - - public Span(SpanContext context) { - this.context = context; - } - - public static Span current() { - return current; - } - - public static void setCurrent(Span span) { - current = span; - } - - public SpanContext getSpanContext() { - return context; - } -} diff --git a/agentscope-core/src/test/java/io/opentelemetry/api/trace/SpanContext.java b/agentscope-core/src/test/java/io/opentelemetry/api/trace/SpanContext.java deleted file mode 100644 index de1ee35ba..000000000 --- a/agentscope-core/src/test/java/io/opentelemetry/api/trace/SpanContext.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2024-2026 the original author or authors. - * - * Licensed 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 io.opentelemetry.api.trace; - -/** Minimal OpenTelemetry stub for tests. */ -public final class SpanContext { - private final boolean valid; - private final String traceId; - private final String spanId; - - public SpanContext(boolean valid, String traceId, String spanId) { - this.valid = valid; - this.traceId = traceId; - this.spanId = spanId; - } - - public boolean isValid() { - return valid; - } - - public String getTraceId() { - return traceId; - } - - public String getSpanId() { - return spanId; - } -} diff --git a/docs/en/task/hook.md b/docs/en/task/hook.md index ac533c972..7066b737a 100644 --- a/docs/en/task/hook.md +++ b/docs/en/task/hook.md @@ -134,6 +134,10 @@ Hooks are immutable after agent construction. For local debugging and offline troubleshooting, AgentScope Java provides a built-in JSONL exporter: +> Warning: the JSONL trace exporter writes full prompts, messages, tool inputs, and error stack +> traces to local files. These records may contain sensitive user data, credentials, or other +> secrets, so only enable it in trusted environments and handle the output file as sensitive data. + ```java import io.agentscope.core.ReActAgent; import io.agentscope.core.hook.recorder.JsonlTraceExporter; diff --git a/docs/zh/task/hook.md b/docs/zh/task/hook.md index f57be00c2..e394d5d57 100644 --- a/docs/zh/task/hook.md +++ b/docs/zh/task/hook.md @@ -207,9 +207,9 @@ cd agentscope-examples/quickstart mvn exec:java -Dexec.mainClass="io.agentscope.examples.quickstart.HookExample" ``` -## Built-in JSONL Trace Exporter +## 内置 JSONL 跟踪导出器 -AgentScope Java provides a built-in JSONL exporter for local debugging: +AgentScope Java 内置了一个 JSONL 导出器,可用于本地调试和离线排障: ```java import io.agentscope.core.hook.recorder.JsonlTraceExporter; @@ -220,6 +220,6 @@ try (JsonlTraceExporter exporter = .includeReasoningChunks(true) // optional .includeActingChunks(true) // optional .build()) { - // Add exporter into hooks list when building agent + // 在构建智能体时,将 exporter 加入 hooks 列表 } ```