Loading...
Loading...
Compare original and translation side by side
<objective>Routing note: For ambiguous user intents, use the shared clarification templates in references/intent-clarification.md.
<objective>路由提示:如果遇到歧义的用户意图,请使用 references/intent-clarification.md 中的通用澄清模板。
statusTFY_BASE_URLTFY_API_KEYTFY_API_SHscripts/tfy-api.shreferences/tfy-api-setup.mdstatusTFY_BASE_URLTFY_API_KEYTFY_API_SHscripts/tfy-api.shreferences/tfy-api-setup.mdtfy_tracing_list_projects()tfy_tracing_list_projects()TFY_API_SH=~/.claude/skills/truefoundry-tracing/scripts/tfy-api.shTFY_API_SH=~/.claude/skills/truefoundry-tracing/scripts/tfy-api.shundefinedundefinedtfy_tracing_create_project(name="my-tracing-project")tfy_tracing_create_project(name="my-tracing-project")undefinedundefined
Save the returned project `id` for the next step.
保存返回的项目`id`供下一步使用。tfy_tracing_create_application(project_id="PROJECT_ID", name="my-app")tfy_tracing_create_application(project_id="PROJECT_ID", name="my-app")undefinedundefined
> **Fallback**: If any of these API endpoints return 404, the tracing API may have changed. Direct the user to create the tracing project via the TrueFoundry UI at `$TFY_BASE_URL` → Tracing section, then return here with the project FQN.
> **降级方案**:如果上述任意API接口返回404,说明追踪API可能已变更。引导用户通过`$TFY_BASE_URL`→追踪模块的TrueFoundry UI创建追踪项目,拿到项目FQN后再回到当前流程。requirements.txtpyproject.tomlsetup.pyPipfileopenaianthropiclangchainllama-indexlitellmcoherebedrockvertexaitransformerspackage.jsonopenai@anthropic-ai/sdklangchain@langchain/corerequirements.txtpyproject.tomlsetup.pyPipfileopenaianthropiclangchainllama-indexlitellmcoherebedrockvertexaitransformerspackage.jsonopenai@anthropic-ai/sdklangchain@langchain/corepip install traceloop-sdktraceloop-sdkrequirements.txtpip install traceloop-sdktraceloop-sdkrequirements.txtnpm install @traceloop/node-server-sdkpackage.jsonnpm install @traceloop/node-server-sdkpackage.jsonTraceloop.init()Traceloop.init()main.pyapp.pyundefinedmain.pyapp.pyundefined
Replace placeholders:
- `<APP_NAME>` — the application name (e.g., "my-chatbot")
- `<TFY_BASE_URL>` — from environment or `.env`
- `<TFY_API_KEY>` — from environment or `.env`
- `<TRACING_PROJECT_FQN>` — the tracing project FQN from Step 2
**Best practice**: Read `TFY_BASE_URL` and `TFY_API_KEY` from environment variables:
```python
import os
from traceloop.sdk import Traceloop
Traceloop.init(
app_name="<APP_NAME>",
api_endpoint=f"{os.environ['TFY_BASE_URL']}/api/otel",
headers={
"Authorization": f"Bearer {os.environ['TFY_API_KEY']}",
"X-TFY-TRACING-PROJECT-FQN": "<TRACING_PROJECT_FQN>",
},
disable_batch=False,
)
替换占位符:
- `<APP_NAME>` — 应用名称(例如"my-chatbot")
- `<TFY_BASE_URL>` — 来自环境变量或`.env`文件
- `<TFY_API_KEY>` — 来自环境变量或`.env`文件
- `<TRACING_PROJECT_FQN>` — 步骤2中获取的追踪项目FQN
**最佳实践**:从环境变量读取`TFY_BASE_URL`和`TFY_API_KEY`:
```python
import os
from traceloop.sdk import Traceloop
Traceloop.init(
app_name="<APP_NAME>",
api_endpoint=f"{os.environ['TFY_BASE_URL']}/api/otel",
headers={
"Authorization": f"Bearer {os.environ['TFY_API_KEY']}",
"X-TFY-TRACING-PROJECT-FQN": "<TRACING_PROJECT_FQN>",
},
disable_batch=False,
)index.tsapp.ts// --- Traceloop init MUST be before any LLM imports ---
import * as traceloop from "@traceloop/node-server-sdk";
traceloop.initialize({
appName: "<APP_NAME>",
apiEndpoint: `${process.env.TFY_BASE_URL}/api/otel`,
headers: {
Authorization: `Bearer ${process.env.TFY_API_KEY}`,
"X-TFY-TRACING-PROJECT-FQN": "<TRACING_PROJECT_FQN>",
},
disableBatch: false,
});
// --- Now import LLM libraries ---
// import OpenAI from "openai";
// etc.index.tsapp.ts// --- Traceloop init 必须放在所有LLM导入之前 ---
import * as traceloop from "@traceloop/node-server-sdk";
traceloop.initialize({
appName: "<APP_NAME>",
apiEndpoint: `${process.env.TFY_BASE_URL}/api/otel`,
headers: {
Authorization: `Bearer ${process.env.TFY_API_KEY}`,
"X-TFY-TRACING-PROJECT-FQN": "<TRACING_PROJECT_FQN>",
},
disableBatch: false,
});
// --- 现在导入LLM库 ---
// import OpenAI from "openai";
// 其他库from traceloop.sdk.decorators import workflow, task, agent, tool
@workflow(name="rag_pipeline")
def run_pipeline(query: str):
context = retrieve(query)
return generate(query, context)
@task(name="retrieve_context")
def retrieve(query: str):
# retrieval logic
...
@task(name="generate_response")
def generate(query: str, context: str):
# LLM call
...
@agent(name="research_agent")
def research_agent(topic: str):
# agent logic
...
@tool(name="web_search")
def web_search(query: str):
# tool logic
...from traceloop.sdk.decorators import workflow, task, agent, tool
@workflow(name="rag_pipeline")
def run_pipeline(query: str):
context = retrieve(query)
return generate(query, context)
@task(name="retrieve_context")
def retrieve(query: str):
# 检索逻辑
...
@task(name="generate_response")
def generate(query: str, context: str):
# LLM调用
...
@agent(name="research_agent")
def research_agent(topic: str):
# Agent逻辑
...
@tool(name="web_search")
def web_search(query: str):
# 工具逻辑
...import { withWorkflow, withTask, withAgent, withTool } from "@traceloop/node-server-sdk";
const runPipeline = withWorkflow({ name: "rag_pipeline" }, async (query: string) => {
const context = await retrieve(query);
return generate(query, context);
});
const retrieve = withTask({ name: "retrieve_context" }, async (query: string) => {
// retrieval logic
});
const generate = withTask({ name: "generate_response" }, async (query: string, context: string) => {
// LLM call
});import { withWorkflow, withTask, withAgent, withTool } from "@traceloop/node-server-sdk";
const runPipeline = withWorkflow({ name: "rag_pipeline" }, async (query: string) => {
const context = await retrieve(query);
return generate(query, context);
});
const retrieve = withTask({ name: "retrieve_context" }, async (query: string) => {
// 检索逻辑
});
const generate = withTask({ name: "generate_response" }, async (query: string, context: string) => {
// LLM调用
});from opentelemetry.sdk.trace.sampling import ParentBased, TraceIdRatioBased
Traceloop.init(
app_name="<APP_NAME>",
api_endpoint=f"{os.environ['TFY_BASE_URL']}/api/otel",
headers={
"Authorization": f"Bearer {os.environ['TFY_API_KEY']}",
"X-TFY-TRACING-PROJECT-FQN": "<TRACING_PROJECT_FQN>",
},
disable_batch=False,
sampler=ParentBased(root=TraceIdRatioBased(0.1)), # 10% sampling
)from opentelemetry.sdk.trace.sampling import ParentBased, TraceIdRatioBased
Traceloop.init(
app_name="<APP_NAME>",
api_endpoint=f"{os.environ['TFY_BASE_URL']}/api/otel",
headers={
"Authorization": f"Bearer {os.environ['TFY_API_KEY']}",
"X-TFY-TRACING-PROJECT-FQN": "<TRACING_PROJECT_FQN>",
},
disable_batch=False,
sampler=ParentBased(root=TraceIdRatioBased(0.1)), # 10%采样率
)import { ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-base";
traceloop.initialize({
appName: "<APP_NAME>",
apiEndpoint: `${process.env.TFY_BASE_URL}/api/otel`,
headers: {
Authorization: `Bearer ${process.env.TFY_API_KEY}`,
"X-TFY-TRACING-PROJECT-FQN": "<TRACING_PROJECT_FQN>",
},
disableBatch: false,
sampler: new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(0.1) }), // 10%
});import { ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-base";
traceloop.initialize({
appName: "<APP_NAME>",
apiEndpoint: `${process.env.TFY_BASE_URL}/api/otel`,
headers: {
Authorization: `Bearer ${process.env.TFY_API_KEY}`,
"X-TFY-TRACING-PROJECT-FQN": "<TRACING_PROJECT_FQN>",
},
disableBatch: false,
sampler: new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(0.1) }), // 10%采样率
});traceloop-sdk@traceloop/node-server-sdkTraceloop.init()AuthorizationX-TFY-TRACING-PROJECT-FQNtraceloop-sdk@traceloop/node-server-sdkTraceloop.init()AuthorizationX-TFY-TRACING-PROJECT-FQNstatussecretsdeploylogsstatussecretsdeploylogsreferences/api-endpoints.mdreferences/api-endpoints.mdCheck that TFY_API_KEY is valid and not expired.
Regenerate at $TFY_BASE_URL → Settings → API Keys.检查TFY_API_KEY是否有效且未过期。
可在$TFY_BASE_URL → 设置 → API Keys页面重新生成。1. Verify Traceloop.init() is called BEFORE LLM library imports — this is the #1 cause.
2. Check that api_endpoint ends with /api/otel (not /api/otel/).
3. Verify X-TFY-TRACING-PROJECT-FQN header matches the project FQN exactly.
4. Set disable_batch=True temporarily to force immediate export and check for errors.
5. Check application logs for OTLP export errors.1. 确认Traceloop.init()调用早于LLM库导入 — 这是最常见的原因。
2. 检查api_endpoint以/api/otel结尾(不要带末尾的/)。
3. 验证X-TFY-TRACING-PROJECT-FQN头与项目FQN完全匹配。
4. 临时将disable_batch设为True强制立即导出,检查是否有报错。
5. 查看应用日志排查OTLP导出错误。Run: pip install traceloop-sdk
Ensure you're installing in the correct virtual environment.执行:pip install traceloop-sdk
确保你在正确的虚拟环境中执行安装。Traceloop.init() must be called BEFORE importing the LLM library.
Move the init call to the very top of your entry point file.Traceloop.init()必须在导入LLM库之前调用。
将init调用移动到入口文件的最顶部。Add sampling — see Step 7 for ParentBased(TraceIdRatioBased) configuration.
Start with 10% sampling (0.1) and adjust based on needs.添加采样配置 — 参考步骤7的ParentBased(TraceIdRatioBased)配置。
初始可设置10%采样率(0.1),再根据需求调整。The tracing API endpoints may differ on your TrueFoundry version.
Create the tracing project via the TrueFoundry UI instead:
$TFY_BASE_URL → Tracing → New Project
Then use the project FQN in your Traceloop.init() configuration.你使用的TrueFoundry版本的追踪API接口可能有差异。
改为通过TrueFoundry UI创建追踪项目:
$TFY_BASE_URL → 追踪 → 新建项目
然后将项目FQN填入Traceloop.init()配置中即可。