描述你要收集的事件以及想要回答的问题。你的编码智能体可以为 Worker 或应用添加埋点,将事件发送到 Basin Pipelines,在 Basin Catalog 中写入 Iceberg 表,并用 Basin SQL 查询。
Source → Basin Pipelines → Basin Catalog → Basin SQL
复制此提示,从 Hello World Worker 构建请求分析工作流:
Start with the JavaScript Hello World Worker. Use basin pipelines setup to create a stream with one required string field named path, a simple-ingestion pipeline, and a Basin Catalog table named default.request_events. Add one Worker binding call that sends new URL(request.url).pathname on each request while keeping the Hello World response. Deploy it, visit / and /example, then count requests by path with Basin SQL. Keep the resources so I can inspect them.完整可运行步骤请遵循 Basin CLI 指南。
将 Cloudflare 文档 Model Context Protocol (MCP) 服务器 ↗ 连接到编辑器或智能体。它可以检索当前命令、绑定字段、权限和限制。此连接不会授予账户访问权限,也不能替代对 Basin Pipelines 投递和 Basin SQL 结果的检查。
在智能体创建资源之前,请指向 Basin Pipelines、Basin Catalog 和 Basin SQL 文档。
在让智能体编写代码之前,先选择摄取路径:
| 数据源 | 推荐路径 |
|---|---|
| 由 Worker 处理的请求或应用事件 | 通过 Basin Pipelines stream 绑定 发送小型 JSON 记录。绑定会处理摄取身份验证。 |
| 涉及 D1、Queues、R2、Workers AI 或其他 Cloudflare 服务的活动 | 在使用该服务的 Worker 或应用中添加埋点。记录结果以及分析所需的字段。 |
| 来自外部应用的事件 | 使用具有 Basin Pipelines Send 权限令牌的已认证 stream HTTP 端点。 |
不要假定某项服务会直接暴露 Basin Pipelines 数据源。如果没有,请在应用使用该服务的位置收集事件。
如果组合多个来源,除非架构匹配,否则应使用不同的表。在用 Basin SQL 连接记录之前,请先验证字段和共享标识符。否则,请比较某个时间窗口内的聚合结果。
Pipelines SQL 使用 INSERT INTO sink SELECT ... FROM stream 来转换和路由传入记录。在数据到达 Iceberg 表之后,再用 Basin SQL 进行 GROUP BY、连接和报表。普通的 R2 JSON 或 Parquet sink 不是 Basin SQL 表。
Instrument my existing Worker to record the route, response status, and request duration in a Basin Pipelines stream. Preserve the response and avoid request bodies, tokens, and client IP addresses. Write the events to a Basin Catalog Iceberg table, then use Basin SQL to count requests and errors by route. Show how to verify that events reach the table.In the Worker that uses D1, record a short operation label, success or failure, and elapsed time for each database operation. Send these records through a Basin Pipelines stream binding to a Basin Catalog Iceberg table. Do not include SQL parameters or result data. Use Basin SQL to compare operation counts and error rates. Keep the existing database behavior intact.Instrument my Queue consumer Worker to record the message type, processing outcome, and duration through a Basin Pipelines stream binding. Do not store message bodies or secrets. Write the events to a Basin Catalog Iceberg table and use Basin SQL to count successful and failed processing attempts. Preserve the consumer's existing retry behavior.Take my existing Basin Pipelines stream of JSON application events and write purchases and signups to separate Basin Catalog tables. Inspect the real stream schema, then use supported Pipelines INSERT INTO ... SELECT statements to route records. Provide Basin SQL queries that count each event type. Preserve the existing stream and explain which sinks and tables you create.My external service sends JSON events over HTTP. Create an authenticated Basin Pipelines stream endpoint and an Iceberg sink in Basin Catalog. Show a minimal request, the required Basin Pipelines Send token permission, one Basin SQL validation query, and how to detect dropped events. Keep tokens out of source files and URLs.In the Worker that reads and writes R2 objects, record the operation type, outcome, and duration through a Basin Pipelines stream binding. Do not record object contents, credentials, or full object keys. Write the events to a Basin Catalog Iceberg table and use Basin SQL to count operations and failures by type. Preserve existing R2 behavior.将 <user_prompt> 内的文本替换为你的数据源、所需字段以及要回答的问题。这些标签用于组织给智能体的指令,不是 Cloudflare 配置的一部分。
<system_context>
You are building a Cloudflare Basin workflow. Check current Cloudflare documentation for Basin Pipelines, Basin Catalog, Basin SQL, Workers, and any source service before choosing commands or APIs.
</system_context>
<source_selection>
Choose the path that fits the request:
- Worker events: use a Basin Pipelines stream binding and await env.STREAM.send([record]). Configure the binding with a stream ID using the "stream" field in wrangler.jsonc.
- Activity involving D1, Queues, R2, Workers AI, or another Cloudflare service: instrument the Worker or application that performs the operation. Inspect its code and choose a small event schema.
- External application events: use an authenticated HTTP stream endpoint.
Do not invent a direct service connector. Keep separate sources in separate tables unless their schemas match.
</source_selection>
<basin_rules>
- When the goal includes Basin SQL, write Apache Iceberg tables through a Basin Catalog sink. A plain R2 JSON or Parquet sink is different.
- Use the current Wrangler commands: basin pipelines setup, basin catalog get <BUCKET_NAME>, and basin sql query <WAREHOUSE_NAME> <SQL>. Set WRANGLER_BASIN_SQL_AUTH_TOKEN for SQL queries. Keep the "stream" binding field; do not use the deprecated "pipeline" field.
- Use Pipelines SQL for supported ingestion transforms and routing. Use Basin SQL for aggregations, joins, and analysis after data lands.
- Inspect the actual application events and stream schema before naming columns. Verify a shared key before joining sources.
- Do not place tokens in Worker code, wrangler.jsonc, URLs, or generated documentation. Worker bindings handle ingestion authentication. Scope tokens for HTTP ingestion, catalog writes, and SQL queries.
- Keep event records minimal and avoid sensitive request fields unless required.
</basin_rules>
<verification>
Show the resources and files needed for the chosen path. Provide one small sample event and a query against the actual warehouse and namespace.table. Verify source ingestion, the Iceberg table, and the Basin SQL result. Check Basin Pipelines metrics and user errors if rows are missing. Allow a few minutes for the first Iceberg file. State what you tested and what still needs account access.
</verification>
<user_prompt>
Describe the data source, event fields, and question to answer.
</user_prompt>- 确认 Worker 或应用已向 stream 发送事件。Worker 上成功的
send()只确认摄取,并不表示表中已有一行。 - 确认 Basin Pipelines 写入的是 Basin Catalog Iceberg sink。在 Pipelines 指标 中检查已写入的记录和文件。
- 使用 Basin SQL 运行小型
SELECT ... LIMIT 10查询。如果表缺失或为空,请等待第一次文件滚动后再重试。 - 如果行仍然缺失,请查看 Pipelines 用户错误指标,排查缺失字段、类型不匹配、解析失败和空值。