@cetra-ai/cli 0.0.0-stage → 0.1.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +48 -0
  2. package/README.md +14 -2
  3. package/dist/cli.js +2816 -0
  4. package/dist/skills/cetra/SKILL.md +95 -0
  5. package/dist/skills/cetra/references/anthropic.md +82 -0
  6. package/dist/skills/cetra/references/attributes.md +178 -0
  7. package/dist/skills/cetra/references/bedrock.md +46 -0
  8. package/dist/skills/cetra/references/crewai.md +38 -0
  9. package/dist/skills/cetra/references/dspy.md +38 -0
  10. package/dist/skills/cetra/references/from-laminar.md +49 -0
  11. package/dist/skills/cetra/references/from-langfuse.md +59 -0
  12. package/dist/skills/cetra/references/google-adk.md +60 -0
  13. package/dist/skills/cetra/references/google-genai.md +50 -0
  14. package/dist/skills/cetra/references/integrations.md +71 -0
  15. package/dist/skills/cetra/references/langchain.md +76 -0
  16. package/dist/skills/cetra/references/litellm.md +45 -0
  17. package/dist/skills/cetra/references/llama-index.md +38 -0
  18. package/dist/skills/cetra/references/metadata-and-tags.md +117 -0
  19. package/dist/skills/cetra/references/openai-agents.md +55 -0
  20. package/dist/skills/cetra/references/openai.md +82 -0
  21. package/dist/skills/cetra/references/openinference.md +51 -0
  22. package/dist/skills/cetra/references/openllmetry.md +42 -0
  23. package/dist/skills/cetra/references/opentelemetry-genai.md +49 -0
  24. package/dist/skills/cetra/references/opentelemetry.md +134 -0
  25. package/dist/skills/cetra/references/otlp.md +73 -0
  26. package/dist/skills/cetra/references/privacy-controls.md +120 -0
  27. package/dist/skills/cetra/references/python-context.md +63 -0
  28. package/dist/skills/cetra/references/python-opentelemetry.md +136 -0
  29. package/dist/skills/cetra/references/python-tracing.md +77 -0
  30. package/dist/skills/cetra/references/python.md +79 -0
  31. package/dist/skills/cetra/references/sessions.md +84 -0
  32. package/dist/skills/cetra/references/sql-schema.md +210 -0
  33. package/dist/skills/cetra/references/troubleshooting.md +90 -0
  34. package/dist/skills/cetra/references/typescript-context.md +22 -0
  35. package/dist/skills/cetra/references/typescript-opentelemetry.md +68 -0
  36. package/dist/skills/cetra/references/typescript-runtimes.md +54 -0
  37. package/dist/skills/cetra/references/typescript-tracing.md +40 -0
  38. package/dist/skills/cetra/references/typescript.md +56 -0
  39. package/dist/skills/cetra/references/users.md +87 -0
  40. package/dist/skills/cetra/references/vercel-ai-sdk.md +82 -0
  41. package/package.json +38 -3
@@ -0,0 +1,79 @@
1
+ <!-- Generated from website/src/content/docs/docs/reference/python/index.mdx by website/scripts/skill-references.mjs. Do not edit: run `just docs-gen`. -->
2
+
3
+ # Python SDK
4
+
5
+ Install the cetra Python SDK, configure it and find your way around its reference pages.
6
+
7
+ Use the Python SDK to send traces and scores from your Python code to cetra. `cetra` is a thin layer over OpenTelemetry: spans go out as OTLP/HTTP protobuf to `<base_url>/v1/traces`, and scores go to `<base_url>/api/v1/scores`. It needs Python 3.11 or later and is MIT licensed.
8
+
9
+ The server stores traces only. If another OpenTelemetry GenAI instrumentation sends prompts and completions as log events, they reach `/v1/logs` and are dropped; the project shows a hint in the UI. Set that instrumentation to capture message content on spans.
10
+
11
+ The pages of this reference:
12
+
13
+ - [Tracing](https://cetra.sh/docs/reference/python/tracing/): `observe`, manual spans and `llm_span`.
14
+ - [Context](https://cetra.sh/docs/reference/python/context/): sessions, users, tags and metadata, baggage and threads.
15
+ - [Scores, datasets and experiments](https://cetra.sh/docs/reference/python/scores-datasets-experiments/): `score`, the `Client` and `evaluate`.
16
+ - [OpenTelemetry](https://cetra.sh/docs/reference/python/opentelemetry/): instrumentors, existing OpenTelemetry setups, masking, serverless and known limits.
17
+ - [API](https://cetra.sh/docs/reference/python/api/): every public name.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pip install cetra-sdk
23
+ ```
24
+
25
+ Auto-instrumentation is optional, one extra per library:
26
+
27
+ | `instrument` name | Extra |
28
+ |---|---|
29
+ | `openai` | `cetra-sdk[openai]` |
30
+ | `anthropic` | `cetra-sdk[anthropic]` |
31
+ | `langchain` | `cetra-sdk[langchain]` |
32
+ | `llama-index` | `cetra-sdk[llama-index]` |
33
+ | `litellm` | `cetra-sdk[litellm]` |
34
+ | `google-genai` | `cetra-sdk[google-genai]` |
35
+ | `bedrock` | `cetra-sdk[bedrock]` |
36
+ | `openai-agents` | `cetra-sdk[openai-agents]` |
37
+ | `crewai` | `cetra-sdk[crewai]` |
38
+ | `dspy` | `cetra-sdk[dspy]` |
39
+
40
+ `cetra-sdk[all]` installs every instrumentor. The core package pulls in only `opentelemetry-api`, `opentelemetry-sdk`, `opentelemetry-exporter-otlp-proto-http` and `requests`.
41
+
42
+ ## Initialize
43
+
44
+ For a first trace, follow the [quick start](https://cetra.sh/docs/get-started/quickstart/).
45
+
46
+ `init()` is called once per process; it also registers an `atexit` hook that calls `shutdown()` (flush, then stop). `flush()` is the manual lever when you need the data out now: see [Serverless](https://cetra.sh/docs/reference/python/opentelemetry/#serverless).
47
+
48
+ Without an API key (argument and `CETRA_API_KEY` both unset), `init()` logs one warning (`cetra: no API key; set CETRA_API_KEY, or CETRA_ENABLED=false to silence this; tracing is disabled`) and the SDK runs as a no-op: nothing raises, nothing is sent. Set `CETRA_ENABLED=false` to silence the warning.
49
+
50
+ ## Configuration
51
+
52
+ An explicit argument wins over the environment variable, which wins over the default. An argument set to `None` counts as not given; env values are trimmed and an empty value counts as unset.
53
+
54
+ | Option | Env | Default |
55
+ |---|---|---|
56
+ | `api_key` | `CETRA_API_KEY` | unset: one warning, SDK disabled |
57
+ | `base_url` | `CETRA_BASE_URL` | `http://localhost:8080` |
58
+ | `environment` | `CETRA_ENVIRONMENT` | unset |
59
+ | `release` | `CETRA_RELEASE` | unset (falls back to `GIT_COMMIT`, then `SOURCE_VERSION`) |
60
+ | `capture_content` | `CETRA_CAPTURE_CONTENT` | `true` |
61
+ | `sample_rate` | `CETRA_SAMPLE_RATE` | `1.0` |
62
+ | `instrument` | — | `[]` |
63
+ | `mask` | — | `None` |
64
+ | `export_filter` | — | `None` |
65
+ | `use_global_provider` | — | `False` |
66
+ | `enabled` | `CETRA_ENABLED` | `true` (no-op mode when false) |
67
+
68
+ - `enabled` is resolved first; when it is false, no other option is read or validated.
69
+ - Booleans from the environment accept `true`/`false`, `1`/`0`, `yes`/`no`, `on`/`off`, case-insensitive.
70
+ - `api_key` must start with `sk-cetra-`. A key with the wrong prefix raises; a missing key does not (see above).
71
+ - `base_url` must be an absolute `http`/`https` URL without query or fragment. A path is allowed (reverse-proxy prefix); trailing slashes are removed.
72
+ - `environment` must not be a reserved environment: `cetra-eval` (evaluation) or `cetra-playground` (playground runs).
73
+ - `sample_rate` must be a finite number in `[0, 1]` (a `ParentBased(TraceIdRatioBased)` sampler on our own provider). From the environment it must be a plain decimal (`1`, `0.25`, `.5`).
74
+ - Any other invalid value raises `ConfigError` (a `ValueError` subclass) naming the option or env var, never its value. Resolution stops at the first problem.
75
+ - `init()` is once per process: any later call, whatever the first one did, logs `cetra: init() was already called; this call is ignored` and changes nothing.
76
+
77
+ ## What is never logged
78
+
79
+ The SDK's own logs and errors never contain payload content (prompts, completions, attribute values), secrets, API keys or email addresses. Log lines carry ids, sizes, counts and exception type names only; configuration errors name the option, never its value; the API key is excluded from `repr` and serialization of the config. Messages go to the `cetra` logger, which has no handlers by default: configure the standard `logging` module to see them. The missing-key and second-`init()` warnings appear once per process; a full score buffer warns at most once per minute, and rejected or failed score batches are logged as they happen.
@@ -0,0 +1,84 @@
1
+ <!-- Generated from website/src/content/docs/docs/tracing/sessions.mdx by website/scripts/skill-references.mjs. Do not edit: run `just docs-gen`. -->
2
+
3
+ # Sessions
4
+
5
+ Group the traces of one conversation or workflow into a session, and read it as a transcript in the UI.
6
+
7
+ Set a session ID on your traces to see them together, in order, with their total cost and errors.
8
+
9
+ A session is the set of traces that share a session ID: for example the turns of one chat. You do not create a session. cetra builds it from the ID. See the [data model](https://cetra.sh/docs/concepts/data-model/).
10
+
11
+ ## Set a session ID
12
+
13
+ Wrap the code that handles one turn in a context block. Every span started inside the block carries the session ID, so each trace of the session carries it too.
14
+
15
+ **Python**
16
+
17
+ ```python
18
+ import cetra
19
+
20
+ cetra.init()
21
+
22
+ @cetra.observe(name="turn")
23
+ def turn() -> None: ...
24
+
25
+ with cetra.context(session_id="chat-42", user_id="u-17"):
26
+ turn()
27
+
28
+ cetra.flush()
29
+ ```
30
+
31
+ **TypeScript**
32
+
33
+ ```ts
34
+ import { observe, withContext } from "@cetra-ai/sdk";
35
+ ```
36
+
37
+ ```ts
38
+ const turn = observe(({ question }: { question: string }) => `answered: ${question}`, {
39
+ name: "turn",
40
+ });
41
+ withContext({ sessionId: "chat-42", userId: "u-17", tags: ["beta"] }, () =>
42
+ turn({ question: "why?" }),
43
+ );
44
+ ```
45
+
46
+ **Attributes**
47
+
48
+ Set the attribute `cetra.session.id` on a span. cetra also reads `session.id` and `gen_ai.conversation.id`, and the session attributes of the other [conventions](https://cetra.sh/docs/concepts/conventions/).
49
+
50
+ ```python
51
+ with tracer.start_as_current_span("turn") as span:
52
+ span.set_attribute("cetra.session.id", "chat-42")
53
+ ```
54
+
55
+ Use the same ID for every trace of the session. A new ID starts a new session.
56
+
57
+ ## In the UI
58
+
59
+ Select **Sessions** in the sidebar, or press `g` then `s`. A chart above the list counts the sessions that started in each part of the time range. A summary strip shows the totals for the loaded sessions: **Sessions**, **Avg turns**, **Avg duration**, **Error rate**, **Cost** and **Tokens**. If more sessions exist than are loaded, it says "of N loaded".
60
+
61
+ The columns are:
62
+
63
+ - **Session**, the session ID.
64
+ - **First message** and **Last answer**, a preview of the first input and the last output.
65
+ - **Start** and **Last activity**.
66
+ - **Traces**, **Duration**, **Tokens** and **Cost**.
67
+ - **User** and **Tags**.
68
+ - **Errors** and **Error rate**.
69
+ - One column per score name found in the sessions.
70
+
71
+ Select **Columns** to show, hide or reorder them. The list has the same facets, preset chips (**Errors**, **Slow**, **Expensive**) and saved views as the traces list ([Filters and search](https://cetra.sh/docs/tracing/filters-and-search/)).
72
+
73
+ Open a session to read it as a transcript. cetra rebuilds the conversation from the input and output of each trace's root span, in order. Select a turn to open its trace. Session scores sit at the top, and **Annotate** adds your own.
74
+
75
+ A session takes its user from the first trace that has one, and its tags are the tags of all its traces together.
76
+
77
+ ## Filter sessions
78
+
79
+ Use the filter bar with the `sessions` view: for example `trace_count > 10 AND cost_total > 1`. To list the traces of one session, filter the traces list with `session_id = 'chat-42'`. See [Filters and search](https://cetra.sh/docs/tracing/filters-and-search/).
80
+
81
+ ## Limits
82
+
83
+ - A trace belongs to one session. If its spans carry different session IDs, cetra prefers the root span's.
84
+ - Session cost and tokens add up the traces cetra has received so far.
@@ -0,0 +1,210 @@
1
+ <!-- Generated from website/src/content/docs/docs/reference/sql-schema.md by website/scripts/skill-references.mjs. Do not edit: run `just docs-gen`. -->
2
+
3
+ # SQL schema
4
+
5
+ The tables and columns you can query in the SQL console and the filter language.
6
+
7
+ <!-- Generated by `just docs-gen` from the server's schema catalog. Do not edit. -->
8
+
9
+ Each table below is a view of your project's data. The SQL console and the filter language read the same views. Timestamps are integers in nanoseconds since the Unix epoch (UTC), and trace and span IDs are lowercase hex strings.
10
+
11
+ ## `traces`
12
+
13
+ One row per trace. Merge bookkeeping columns are not exposed.
14
+
15
+ | Column | Type | Nullable | Description |
16
+ |---|---|---|---|
17
+ | `trace_id` | `string` | no | Trace id, 16 bytes as lowercase hex. |
18
+ | `start_time` | `timestamp` | no | Earliest span start. |
19
+ | `end_time` | `timestamp` | no | Latest span end. |
20
+ | `duration_ns` | `integer` | no | end_time minus start_time, in nanoseconds. |
21
+ | `duration_ms` | `float` | no | duration_ns / 1e6, for convenience. |
22
+ | `name` | `string` | no | Name of the root span, else the earliest span. |
23
+ | `root_span_id` | `string` | yes | Span id of the root. Null when the trace has no root. |
24
+ | `has_root` | `boolean` | no | Whether a root span is present. |
25
+ | `status` | `string` | no | error if any span errored, else the root status, else unset. |
26
+ | `session_id` | `string` | yes | Session id, preferring the root. |
27
+ | `user_id` | `string` | yes | End-user id, preferring the root. |
28
+ | `environment` | `string` | yes | Deployment environment. |
29
+ | `release` | `string` | yes | Git SHA or version string. |
30
+ | `tags` | `string_list` | no | Distinct union of span tags. |
31
+ | `metadata` | `string_map` | no | Root metadata, with keys from other spans added when absent. |
32
+ | `input_preview` | `string` | yes | Root input preview, else the first llm span's. |
33
+ | `output_preview` | `string` | yes | Root output preview, else the first llm span's. |
34
+ | `span_count` | `integer` | no | Number of spans. |
35
+ | `error_count` | `integer` | no | Number of spans with status error. |
36
+ | `llm_count` | `integer` | no | Number of llm spans. |
37
+ | `input_tokens` | `integer` | yes | Sum of input tokens. Null when every span omitted the field. |
38
+ | `output_tokens` | `integer` | yes | Sum of output tokens. Null when every span omitted the field. |
39
+ | `cache_read_tokens` | `integer` | yes | Sum of cache-read tokens. Null when every span omitted the field. |
40
+ | `cache_write_tokens` | `integer` | yes | Sum of cache-write tokens. Null when every span omitted the field. |
41
+ | `reasoning_tokens` | `integer` | yes | Sum of reasoning tokens. Null when every span omitted the field. |
42
+ | `total_tokens` | `integer` | yes | Sum of total tokens. Null when every span omitted the field. |
43
+ | `cost_total` | `float` | yes | Sum of span costs, USD. Null when every span omitted the field. |
44
+ | `models` | `string_list` | no | Distinct model names. |
45
+ | `prompts` | `string_list` | no | Registry prompts the trace used, as name@version (D-V-15). |
46
+
47
+ ## `spans`
48
+
49
+ One row per span, including payload columns.
50
+
51
+ | Column | Type | Nullable | Description |
52
+ |---|---|---|---|
53
+ | `trace_id` | `string` | no | Trace id, 16 bytes as lowercase hex. |
54
+ | `span_id` | `string` | no | Span id, 8 bytes as lowercase hex. |
55
+ | `parent_span_id` | `string` | yes | Parent span id. Null when the span was received as a root. |
56
+ | `name` | `string` | no | Span name. |
57
+ | `span_kind` | `string` | no | Kind of work: llm, embedding, tool, agent, chain, retriever, reranker, guardrail, evaluator, or span. |
58
+ | `start_time` | `timestamp` | no | Start time. |
59
+ | `end_time` | `timestamp` | no | End time. |
60
+ | `duration_ns` | `integer` | no | end_time minus start_time, in nanoseconds. |
61
+ | `duration_ms` | `float` | no | duration_ns / 1e6, for convenience. |
62
+ | `status` | `string` | no | unset, ok, or error. |
63
+ | `status_message` | `string` | yes | Status description. |
64
+ | `service_name` | `string` | yes | Resource service.name. |
65
+ | `session_id` | `string` | yes | Session id. |
66
+ | `user_id` | `string` | yes | End-user id. |
67
+ | `environment` | `string` | yes | Deployment environment. cetra-eval is reserved for evaluator runs, cetra-playground for playground runs and cetra-assistant for assistant turns. |
68
+ | `release` | `string` | yes | Git SHA or version string. |
69
+ | `tags` | `string_list` | no | Tags. |
70
+ | `metadata` | `string_map` | no | User metadata. Values are JSON-encoded scalars or strings. |
71
+ | `provider` | `string` | yes | Normalized provider name, for example openai or anthropic. |
72
+ | `request_model` | `string` | yes | Model named in the request. |
73
+ | `response_model` | `string` | yes | Model named in the response. |
74
+ | `model` | `string` | yes | coalesce(response_model, request_model). |
75
+ | `prompt_name` | `string` | yes | Registry prompt the span used (D-V-15). |
76
+ | `prompt_version` | `integer` | yes | Version of that prompt. |
77
+ | `operation` | `string` | yes | GenAI operation name. |
78
+ | `input_tokens` | `integer` | yes | Input tokens, including cached tokens. |
79
+ | `output_tokens` | `integer` | yes | Output tokens, including reasoning tokens. |
80
+ | `cache_read_tokens` | `integer` | yes | Cache-read tokens. |
81
+ | `cache_write_tokens` | `integer` | yes | Cache-write tokens. |
82
+ | `reasoning_tokens` | `integer` | yes | Reasoning tokens. |
83
+ | `total_tokens` | `integer` | yes | Total tokens. |
84
+ | `cost_input` | `float` | yes | Input cost, USD. |
85
+ | `cost_output` | `float` | yes | Output cost, USD. |
86
+ | `cost_total` | `float` | yes | Total cost, USD, including cache and reasoning. |
87
+ | `cost_source` | `string` | yes | computed, reported, or none. |
88
+ | `ttft_ns` | `integer` | yes | Time to first token, nanoseconds. |
89
+ | `request_params` | `json` | yes | Request parameters such as temperature and max_tokens. |
90
+ | `input` | `string` | yes | Stored payload text. |
91
+ | `input_format` | `string` | yes | messages, json, or text. |
92
+ | `output` | `string` | yes | Stored payload text. |
93
+ | `output_format` | `string` | yes | messages, json, or text. |
94
+ | `input_preview` | `string` | yes | First 512 characters of the plain-text rendering. |
95
+ | `output_preview` | `string` | yes | First 512 characters of the plain-text rendering. |
96
+ | `system_instructions` | `json` | yes | System instructions as JSON text. |
97
+ | `tool_definitions` | `json` | yes | Tool definitions as JSON text. |
98
+ | `attributes` | `string_map` | no | Span attributes not consumed by normalization. Values are JSON-encoded. |
99
+ | `resource_attributes` | `string_map` | no | Resource attributes except service.name. Values are JSON-encoded. |
100
+ | `scope_name` | `string` | yes | Instrumentation scope name. |
101
+ | `scope_version` | `string` | yes | Instrumentation scope version. |
102
+ | `events` | `json` | no | Span events. Each item has time, name, and attributes. |
103
+ | `links` | `json` | no | Span links. Each item has trace_id, span_id, and attributes. |
104
+ | `media_refs` | `string_list` | no | SHA-256 hex of extracted media blobs. |
105
+ | `truncated` | `string_list` | no | Names of attributes truncated at ingest. |
106
+ | `conventions` | `string_list` | no | Detected conventions, for example genai or openinference. |
107
+ | `ingest_time` | `timestamp` | no | Server receive time. |
108
+ | `schema_version` | `integer` | no | Row-level normalization version. |
109
+
110
+ ## `sessions`
111
+
112
+ One row per session.
113
+
114
+ | Column | Type | Nullable | Description |
115
+ |---|---|---|---|
116
+ | `session_id` | `string` | no | Session id. |
117
+ | `start_time` | `timestamp` | no | Earliest trace start. |
118
+ | `end_time` | `timestamp` | no | Latest trace end. |
119
+ | `duration_ns` | `integer` | no | end_time minus start_time, in nanoseconds. |
120
+ | `duration_ms` | `float` | no | duration_ns / 1e6, for convenience. |
121
+ | `trace_count` | `integer` | no | Number of traces in the session. |
122
+ | `error_count` | `integer` | no | Sum of trace error counts. |
123
+ | `total_tokens` | `integer` | yes | Sum of trace total tokens. |
124
+ | `cost_total` | `float` | yes | Sum of trace costs, USD. |
125
+ | `user_id` | `string` | yes | End-user id of the session. |
126
+ | `tags` | `string_list` | no | Distinct union of trace tags. |
127
+
128
+ ## `scores`
129
+
130
+ One row per live score.
131
+
132
+ | Column | Type | Nullable | Description |
133
+ |---|---|---|---|
134
+ | `score_id` | `string` | no | Score id. |
135
+ | `target` | `string` | no | span, trace, or session. |
136
+ | `trace_id` | `string` | yes | Trace id for a span or trace target. |
137
+ | `span_id` | `string` | yes | Span id for a span target. |
138
+ | `session_id` | `string` | yes | Session id for a session target, and copied for a trace target when known. |
139
+ | `user_id` | `string` | yes | End-user id, when the writer knew it. |
140
+ | `name` | `string` | no | Score name. |
141
+ | `data_type` | `string` | no | numeric, boolean, categorical, or text. |
142
+ | `value_num` | `float` | yes | Numeric value. Booleans are 0 or 1. |
143
+ | `value_str` | `string` | yes | Categorical label or text. |
144
+ | `reason` | `string` | yes | Explanation. |
145
+ | `source` | `string` | no | api, sdk, human, end_user, llm_judge, check, webhook or issue. |
146
+ | `evaluator_id` | `string` | yes | Evaluator that produced the score. |
147
+ | `rule_id` | `string` | yes | Online rule that produced the score. |
148
+ | `experiment_id` | `string` | yes | Experiment the score belongs to. |
149
+ | `dataset_item_id` | `string` | yes | Dataset item the score belongs to. |
150
+ | `queue_id` | `string` | yes | Annotation queue the score was written from. |
151
+ | `author_user_id` | `string` | yes | Person who annotated, for human scores. |
152
+ | `metadata` | `string_map` | no | Evaluator metadata. Values are strings. |
153
+ | `created_at` | `timestamp` | no | Creation time. |
154
+ | `updated_at` | `timestamp` | no | Last-writer-wins version. |
155
+ | `deleted` | `boolean` | no | Tombstone. |
156
+ | `ingest_time` | `timestamp` | no | Server receive time. |
157
+
158
+ ## `experiment_items`
159
+
160
+ One row per experiment result (item × repetition) of the project's visible experiments.
161
+
162
+ | Column | Type | Nullable | Description |
163
+ |---|---|---|---|
164
+ | `experiment_id` | `string` | no | Experiment id. |
165
+ | `experiment_name` | `string` | no | Experiment name. |
166
+ | `dataset_id` | `string` | yes | Dataset the experiment ran on; null once the dataset is deleted. |
167
+ | `dataset_version` | `integer` | no | Dataset version the experiment pinned. |
168
+ | `dataset_item_id` | `string` | no | Dataset item id, stable across versions. |
169
+ | `repetition` | `integer` | no | Repetition number, from 0. |
170
+ | `trace_id` | `string` | yes | Trace of the task run, lowercase hex; null when none was reported. |
171
+ | `input` | `json` | no | Item input at the pinned version, JSON text. |
172
+ | `expected_output` | `json` | yes | Expected output at the pinned version, JSON text; null when absent. |
173
+ | `output` | `json` | yes | Task output, JSON text; null when the run failed. |
174
+ | `error` | `string` | yes | Error text of the failed run; null when the run did not fail. |
175
+ | `latency_ns` | `integer` | yes | Task run time in nanoseconds, as the SDK measured it. |
176
+ | `created_at` | `timestamp` | no | Time the result was stored. |
177
+
178
+ ## `dataset_items`
179
+
180
+ Live items of each dataset at its current version.
181
+
182
+ | Column | Type | Nullable | Description |
183
+ |---|---|---|---|
184
+ | `dataset_id` | `string` | no | Dataset id. |
185
+ | `dataset_name` | `string` | no | Dataset name. |
186
+ | `dataset_version` | `integer` | no | Current version of the dataset, the version these rows belong to. |
187
+ | `item_id` | `string` | no | Dataset item id, stable across versions. |
188
+ | `input` | `json` | no | Item input, JSON text. |
189
+ | `expected_output` | `json` | yes | Expected output, JSON text; null when absent. |
190
+ | `metadata` | `json` | no | Item metadata, JSON text. |
191
+ | `source_trace_id` | `string` | yes | Trace the item was created from, lowercase hex; null when none. |
192
+ | `source_span_id` | `string` | yes | Span the item was created from, lowercase hex; null when none. |
193
+ | `created_at` | `timestamp` | no | Time the item revision was stored. |
194
+
195
+ ## Functions
196
+
197
+ | Function | Description |
198
+ |---|---|
199
+ | `now() -> timestamp` | Current time. |
200
+ | `lower(value: string) -> string` | Lowercase a string. |
201
+ | `upper(value: string) -> string` | Uppercase a string. |
202
+ | `length(value: string) -> integer` | Number of characters. |
203
+ | `coalesce(value: any, fallback: any) -> any` | First non-null argument. |
204
+ | `array_has(array: string_list, value: string) -> boolean` | Whether the list contains the value. |
205
+ | `array_length(array: string_list) -> integer` | Number of elements. |
206
+ | `date_trunc(unit: string, time: timestamp) -> timestamp` | Truncate a timestamp to a unit such as day or hour. |
207
+ | `abs(value: float) -> float` | Absolute value. |
208
+ | `score(name: string) -> float` | Latest numeric score of that name on the row's target. |
209
+ | `score_label(name: string) -> string` | Latest categorical or text score of that name. |
210
+ | `has_score(name: string) -> boolean` | Whether the row's target has a score of that name. |
@@ -0,0 +1,90 @@
1
+ <!-- Generated from website/src/content/docs/docs/help/troubleshooting.mdx by website/scripts/skill-references.mjs. Do not edit: run `just docs-gen`. -->
2
+
3
+ # Troubleshooting
4
+
5
+ Find the cause of the common problems, from missing traces to rejected requests, by symptom, with a check and a fix for each.
6
+
7
+ This page lists problems by what you see. Each one has a check and a fix.
8
+
9
+ ## No traces at all
10
+
11
+ **Check:** Look at the dot in the top bar of the UI. Its tooltip says "Receiving spans" with the time of the last batch, "No spans in the last 5 minutes", or "No spans received since the server started". If spans arrive but the list is empty, open the **Include** menu in the list toolbar: the list hides evaluation traces and experiment traces until you tick them, and a time range or filter can hide the rest. If no spans arrive: is the API key right, and is it for the project you are looking at? Does the SDK reach the server? Look at the cetra log (`cetra serve` output or `docker logs cetra`): it names the reason when it refuses a request.
12
+
13
+ **Fix:** Use a key that starts with `sk-cetra-`, set `CETRA_BASE_URL` to the server's address (the SDKs default to `http://localhost:8080`), and make sure `CETRA_ENABLED` is not `false`. See the [quick start](https://cetra.sh/docs/get-started/quickstart/#nothing-showing-up).
14
+
15
+ ## The SDK warns "no API key"
16
+
17
+ **Check:** The warning reads `cetra: no API key; set CETRA_API_KEY, or CETRA_ENABLED=false to silence this; tracing is disabled`.
18
+
19
+ **Fix:** Set `CETRA_API_KEY` or pass `api_key` to `init()`. To run without tracing on purpose, set `CETRA_ENABLED=false`. See [Python SDK](https://cetra.sh/docs/reference/python/#initialize).
20
+
21
+ ## A short script loses its last spans
22
+
23
+ **Check:** Does the process exit right after the last call? Spans are exported in the background, and a process that ends first never sends them.
24
+
25
+ **Fix:** Call `flush()` (Python) or `await flush()` (TypeScript) before the process ends. See [Serverless](https://cetra.sh/docs/reference/python/opentelemetry/#serverless).
26
+
27
+ ## Spans are lost on serverless or an edge runtime
28
+
29
+ **Check:** Does the platform freeze or stop the process when the handler returns?
30
+
31
+ **Fix:** Call `await flush()` or `shutdown()` at the end of every invocation. The TypeScript SDK installs no signal handlers. See [Runtimes](https://cetra.sh/docs/reference/typescript/runtimes/).
32
+
33
+ ## Traces appear without input or output
34
+
35
+ **Check:** Is `capture_content` turned off, or is a mask removing the values? Does your instrumentation send prompts and completions as log events? If it does, the UI shows a banner once per project: "GenAI content was sent as log events." It gives the number of dropped records, and you can dismiss it.
36
+
37
+ **Fix:** Turn `capture_content` back on, or review your `mask`. cetra stores spans only, and drops logs and metrics, so set your instrumentation to put content on spans. See [Masking, sampling and truncation](https://cetra.sh/docs/tracing/privacy-controls/) and [OTLP endpoint](https://cetra.sh/docs/reference/otlp/#logs-and-metrics).
38
+
39
+ ## The tree is flat or spans are in the wrong place
40
+
41
+ **Check:** Does each span carry the right parent span ID? A span whose parent never arrived shows as a root of its own.
42
+
43
+ **Fix:** Make sure the work runs inside the parent's context, and that you flush so every span arrives. See [Traces](https://cetra.sh/docs/tracing/traces/) and [Context](https://cetra.sh/docs/reference/python/context/).
44
+
45
+ ## A span has no cost
46
+
47
+ **Check:** Does the span have token counts and a model name? Cost is reported by your code, or computed from a price that matches the model and provider.
48
+
49
+ **Fix:** Send token counts, or set a price for your model in the project. See [Cost and tokens](https://cetra.sh/docs/tracing/cost-and-tokens/).
50
+
51
+ ## Spans are rejected, or the time looks wrong
52
+
53
+ **Check:** cetra rejects a span that starts before 2000-01-01, before the project's retention, or more than one day in the future. A host with a wrong clock sends such spans. The response is `200` with a `partial_success` message.
54
+
55
+ **Fix:** Correct the clock of the machine that runs your application. See [Partial success](https://cetra.sh/docs/reference/otlp/#partial-success).
56
+
57
+ ## Ingest answers 401, 402, 403, 413, 429 or 503
58
+
59
+ | Status | Check | Fix |
60
+ |---|---|---|
61
+ | `401` | The key is missing or invalid. | Send `Authorization: Bearer sk-cetra-…`. |
62
+ | `402` | The organization reached its monthly units cap. | Do not retry. Wait for the reset time in `Retry-After`, or raise the cap. See [Plans and licence](https://cetra.sh/docs/platform/plans-and-licence/). |
63
+ | `403` | The credential is not a key with the `ingest` scope. | Create an API key with that scope. See [API keys and tokens](https://cetra.sh/docs/platform/api-keys/). |
64
+ | `413` | The request is over a limit: its size or its span count. | Send smaller batches, or raise the limit in [`ingest`](https://cetra.sh/docs/self-hosting/configuration-reference/#ingest). |
65
+ | `429` | The organization's ingest rate limit. | Wait for `Retry-After`. |
66
+ | `503` | The server is overloaded, out of disk space or shutting down. | Retry after `Retry-After`. Check free disk and the [resources](https://cetra.sh/docs/self-hosting/resources/). |
67
+
68
+ See the full list in [OTLP endpoint](https://cetra.sh/docs/reference/otlp/#answers).
69
+
70
+ ## OTLP/gRPC does not work through a proxy
71
+
72
+ **Check:** Does the proxy speak HTTP/2 to cetra? Is port 4317 published?
73
+
74
+ **Fix:** Configure the proxy to use HTTP/2 to port 4317, or send OTLP/HTTP to port 8080 or 4318 instead. See [TLS](https://cetra.sh/docs/self-hosting/configuration/#tls).
75
+
76
+ ## The setup link is lost
77
+
78
+ **Check:** cetra logs `setup required: open http://localhost:8080/setup?token=…` on its first start with an empty database.
79
+
80
+ **Fix:** Find it in the log: `docker logs cetra 2>&1 | grep 'setup required'`. To skip the page, set the `CETRA_INIT_*` variables. See [Install](https://cetra.sh/docs/self-hosting/install/#binary).
81
+
82
+ ## The UI is missing
83
+
84
+ **Check:** Run `cetra version`. A build without the web UI prints `ui: not built`.
85
+
86
+ **Fix:** Use a release binary or the Docker image, which include the UI. See [Install](https://cetra.sh/docs/self-hosting/install/).
87
+
88
+ ## Still stuck
89
+
90
+ See [Support and security](https://cetra.sh/docs/help/support/).
@@ -0,0 +1,22 @@
1
+ <!-- Generated from website/src/content/docs/docs/reference/typescript/context.mdx by website/scripts/skill-references.mjs. Do not edit: run `just docs-gen`. -->
2
+
3
+ # Context (TypeScript)
4
+
5
+ Attach sessions, users, tags and metadata to every span and send them downstream as baggage.
6
+
7
+ Use `withContext` to group traces by session and user.
8
+
9
+ ## Context and baggage
10
+
11
+ ```ts
12
+ const turn = observe(({ question }: { question: string }) => `answered: ${question}`, {
13
+ name: "turn",
14
+ });
15
+ withContext({ sessionId: "chat-42", userId: "u-17", tags: ["beta"] }, () =>
16
+ turn({ question: "why?" }),
17
+ );
18
+ ```
19
+
20
+ The values live in the OpenTelemetry context, so they follow `AsyncLocalStorage` into promises and concurrent flows; nested blocks merge (inner session and user win, tags union, metadata merges by key). They are stamped on every span of the SDK's provider: session and user ids, tags, metadata, `environment` and `release`. Metadata is recorded to be read back by the server: keep personal data out of it, or mask it (see [Masking](https://cetra.sh/docs/reference/typescript/opentelemetry/#masking-and-capturecontent)). `propagate: true` also sets the session and user ids as W3C baggage entries for downstream services.
21
+
22
+ `prompt` links the spans to a prompt from `getPrompt()`: `withContext({ prompt }, fn)` stamps `cetra.prompt.name` and `cetra.prompt.version` on every span inside the block, and an inner prompt replaces an outer one. A fallback prompt has no version, so only its name is stamped. Any value that is not a `Prompt` is ignored. The [Prompts](https://cetra.sh/docs/evaluation/prompts/) page shows the whole flow.
@@ -0,0 +1,68 @@
1
+ <!-- Generated from website/src/content/docs/docs/reference/typescript/opentelemetry.mdx by website/scripts/skill-references.mjs. Do not edit: run `just docs-gen`. -->
2
+
3
+ # OpenTelemetry (TypeScript)
4
+
5
+ Enable instrumentation for OpenAI, Anthropic and LangChain, use the Vercel AI SDK, work next to an existing OpenTelemetry setup and mask payloads.
6
+
7
+ Use these helpers to capture spans from LLM libraries, to share a process with other OpenTelemetry code and to keep content out of your traces.
8
+
9
+ ## Instrumentation (OpenAI, Anthropic, LangChain)
10
+
11
+ `init({ instrument: [...] })` takes instrumentation objects (anything with `setTracerProvider`, `enable` and `disable`). The subpath helpers build the OpenInference instrumentation and patch the module by hand, so ESM works without loader flags:
12
+
13
+ ```ts
14
+ import { init } from "@cetra-ai/sdk";
15
+ import { openai } from "@cetra-ai/sdk/openai";
16
+ import OpenAI from "openai";
17
+
18
+ init({ apiKey: process.env.CETRA_API_KEY, instrument: [openai(OpenAI)] });
19
+ ```
20
+
21
+ The same shape exists as `@cetra-ai/sdk/anthropic` (takes the `Anthropic` class from `@anthropic-ai/sdk`) and `@cetra-ai/sdk/langchain` (takes the LangChain global from `@langchain/core`). The OpenInference packages are optional peers. Pass the helpers' `captureContent` the same value as `init`'s.
22
+
23
+ ## Vercel AI SDK
24
+
25
+ The AI SDK sends spans to the tracer it is given; `aiTelemetry()` hands out one from the cetra provider (scope `ai`) plus your context values as telemetry metadata.
26
+
27
+ ```ts
28
+ // Pass `telemetry` as `experimental_telemetry` to the Vercel AI SDK; the
29
+ // tracer it hands out is the cetra one, so AI spans land in cetra.
30
+ const telemetry = aiTelemetry({ sessionId: "chat-42", functionId: "chat" });
31
+ telemetry.tracer?.startSpan("ai.chat").end();
32
+ ```
33
+
34
+ Full usage with the AI SDK itself:
35
+
36
+ ```ts
37
+ import { aiTelemetry } from "@cetra-ai/sdk";
38
+ import { generateText } from "ai";
39
+
40
+ const result = await generateText({
41
+ model: myModel,
42
+ experimental_telemetry: aiTelemetry({ sessionId: "chat-42", functionId: "chat" }),
43
+ });
44
+ ```
45
+
46
+ ## Existing OpenTelemetry setups
47
+
48
+ By default the SDK keeps its own `TracerProvider` and never registers it globally, so it cannot hijack an app's OpenTelemetry setup. The OpenTelemetry _context_ is always the global one, so instrumentor spans nest under ours.
49
+
50
+ - `useGlobalProvider: true` registers our provider as the global one when none is set; OpenTelemetry JS 2.x providers cannot take processors after construction, so with an app provider already registered the SDK logs one warning and stays private.
51
+ - `spanProcessor()` returns our span processor, for apps that build their own OpenTelemetry pipeline and add it to their provider.
52
+ - `exportFilter(span)` replaces the default export rule (which, in global mode, keeps spans whose scope is `cetra` or `ai` or that carry known LLM attribute prefixes).
53
+ - `tracerProvider()` returns the provider in use.
54
+
55
+ ## Masking and `captureContent`
56
+
57
+ `mask(value)` runs on every value the SDK records (inputs, outputs, metadata, LLM messages) before serialization, and at export time on payload keys of other spans (instrumentor spans included). It gets the decoded value and must return a new one; a string stays a string, anything else is serialized back. If it throws, the value becomes `"[cetra: mask failed]"` (fail closed).
58
+
59
+ `captureContent: false` records no payload attributes on our spans and deletes the payload keys from other spans; token counts, models and costs still flow.
60
+
61
+ ```ts
62
+ import { init } from "@cetra-ai/sdk";
63
+
64
+ init({
65
+ apiKey: process.env.CETRA_API_KEY,
66
+ mask: (value) => (typeof value === "string" ? value.replaceAll("sk-live-", "[key]") : value),
67
+ });
68
+ ```
@@ -0,0 +1,54 @@
1
+ <!-- Generated from website/src/content/docs/docs/reference/typescript/runtimes.mdx by website/scripts/skill-references.mjs. Do not edit: run `just docs-gen`. -->
2
+
3
+ # Runtimes (TypeScript)
4
+
5
+ Run the TypeScript SDK on edge runtimes and serverless platforms, send feedback from a browser and know its known limits.
6
+
7
+ Use this page to run the SDK outside a long-lived Node process.
8
+
9
+ ## Edge runtimes and serverless
10
+
11
+ One transport everywhere: OTLP protobuf over `fetch`, gzipped through `CompressionStream` when the runtime has it. On Cloudflare Workers, enable Node compatibility (the SDK uses `AsyncLocalStorage` for context):
12
+
13
+ ```toml
14
+ compatibility_flags = ["nodejs_compat"]
15
+ ```
16
+
17
+ In serverless (Workers, Lambda, edge functions), flush explicitly. The `beforeExit` hook only fires when the event loop empties, never on a frozen or reused invocation:
18
+
19
+ ```ts
20
+ import { flush } from "@cetra-ai/sdk";
21
+
22
+ export default {
23
+ async fetch(request, env, ctx) {
24
+ const response = handle(request);
25
+ ctx.waitUntil(flush());
26
+ return response;
27
+ },
28
+ };
29
+ ```
30
+
31
+ ## Browser feedback
32
+
33
+ The `@cetra-ai/sdk/browser` subpath imports nothing from OpenTelemetry; it posts an end-user feedback score with a public key (`pk-cetra-…`) and never throws:
34
+
35
+ ```ts
36
+ import { feedback } from "@cetra-ai/sdk/browser";
37
+
38
+ const { ok } = await feedback({
39
+ baseUrl: "https://cetra.example.org",
40
+ publicKey: "pk-cetra-…",
41
+ traceId, // 32 hex chars, from traceparent or your app
42
+ value: 1,
43
+ });
44
+ ```
45
+
46
+ ## Known limits
47
+
48
+ - **Zero-argument functions and `undefined`**: no arguments record no input (Python records `{}`); an `undefined` return records no output (Python records `null`). Return `null` to record a JSON `null`.
49
+ - **Integral floats**: JavaScript has one number type, and OpenTelemetry JS encodes an integral number as an int attribute; Python writes a double for `1.0`. The server reads both. `bigint` becomes a decimal string in payloads.
50
+ - **Resource attributes**: only `OTEL_SERVICE_NAME` is read (from the config's env source); `OTEL_RESOURCE_ATTRIBUTES` is not (Python reads it).
51
+ - **Usage counts**: `setUsage` records only safe integers (`Number.isSafeInteger`); a larger value, a non-integer or a negative one is skipped with a debug line. Python's `set_usage` records any non-negative `int`, including values beyond 2^53.
52
+ - **Abandoned generators**: a half-consumed generator is left unexported (TypeScript has no finalizer); Python's garbage collector ends it with status ok.
53
+ - **Cloudflare Workers** need `nodejs_compat` (above); flush through `ctx.waitUntil(flush())` before the invocation is frozen.
54
+ - **Serverless**: call `await flush()` (or `shutdown()`) at the end of each invocation; the SDK installs no signal handlers and `beforeExit` does not fire on `process.exit()`.
@@ -0,0 +1,40 @@
1
+ <!-- Generated from website/src/content/docs/docs/reference/typescript/tracing.mdx by website/scripts/skill-references.mjs. Do not edit: run `just docs-gen`. -->
2
+
3
+ # Tracing (TypeScript)
4
+
5
+ Trace functions with observe, write spans by hand with withSpan and record LLM calls with withLlmSpan.
6
+
7
+ Use `observe`, `withSpan` and `withLlmSpan` to turn your TypeScript code into spans.
8
+
9
+ ## Wrapper rules
10
+
11
+ `observe(fn, options?)` wraps a function so that each call is one span.
12
+
13
+ - **Input**: no arguments record none; one argument records that value; more record the JSON array of them. Destructuring defaults are invisible to `observe`: pass the fields you want recorded explicitly.
14
+ - **Output**: the return value, or the resolved value of a returned promise. `undefined` records no output; return `null` to record a JSON `null`.
15
+ - **Generators**: a generator or async generator function (detected at wrap time) is traced as a generator: the span starts at the first `next()`, the output is the yielded items, their concatenation when every item is a string, else the JSON array. An early `return()` ends the span with status ok, not an error.
16
+ - **Errors**: a throw records one `exception` event and sets the status to error, then re-throws unchanged. Any other function shape, including one _returning_ a generator, is traced as a call, and a returned generator object is passed through untouched, never consumed.
17
+ - `captureInput` / `captureOutput` (default `true`) turn each side off.
18
+ - An invalid `kind` throws a `TypeError` at wrap time, before the function runs.
19
+
20
+ ## Manual spans and `withLlmSpan`
21
+
22
+ `withSpan(name, options?, fn)` runs `fn` inside a span; the body's return value is never recorded. Only `span.setInput`, `span.setOutput` and `span.setMetadata` write attributes.
23
+
24
+ ```ts
25
+ withLlmSpan(
26
+ "chat",
27
+ {
28
+ provider: "openai",
29
+ model: "gpt-4o-mini",
30
+ inputMessages: [{ role: "user", content: "hi" }],
31
+ params: { temperature: 0.2 },
32
+ },
33
+ (span) => {
34
+ span.setOutputMessages([{ role: "assistant", content: "hello" }]);
35
+ span.setUsage({ inputTokens: 12, outputTokens: 3 });
36
+ },
37
+ );
38
+ ```
39
+
40
+ `withLlmSpan` writes the GenAI attributes (`gen_ai.*`), `cetra.span.kind = "llm"` and, through the handle, the response model, usage, cost (`setCost(totalUsd)`) and time-to-first-token (`recordFirstToken()`). Messages may be the canonical `{ role, parts }` format or the short `{ role, content: "<text>" }` form, which becomes one text part.