@ratel-ai/telemetry
Raw API of @ratel-ai/telemetry — the OTel-free ratel.* semantic-convention vocabulary for TypeScript.
v0.1.2 · TypeScript · npm · source
Generated from the doc comments at
ratel-ai/ratel@3be0ecb— do not edit by hand. Regenerate withpnpm sync:apiinapps/docs.
@ratel-ai/telemetry — the ratel.* telemetry vocabulary.
See the wire contract in CONVENTIONS.md. Emitting the vocabulary is done
through the standard OpenTelemetry JS SDK; this package adds no transport and
no schema (ADR-0007). These constants are the ratel.* overlay Ratel owns,
plus the small subset of gen_ai.* keys the overlay emits directly on the
execute_tool span (borrowed verbatim from OpenTelemetry, never renamed).
This package is OTel-free (ADR-0007): the OTLP config resolver and the
content-capture gate are re-exported from ./config; the init() exporter,
which does pull the OpenTelemetry SDK, lives in @ratel-ai/telemetry-otlp.
Interfaces
InitOptions
init() (in @ratel-ai/telemetry-otlp) resolves endpoint + auth from
RATEL_URL / RATEL_API_KEY, with explicit { endpoint, apiKey } values
taking precedence over the environment. An explicit apiKey sets the Bearer
header; the RATEL_API_KEY fallback only applies when neither apiKey nor an
explicit Authorization header is given, so ambient env never overrides an
auth header the caller passed on purpose.
Properties
apiKey?
optionalapiKey?:string
Ratel API key; sent as Authorization: Bearer <apiKey>. Defaults to RATEL_API_KEY.
endpoint?
optionalendpoint?:string
Full OTLP traces URL (incl. /v1/traces). Defaults to RATEL_URL.
headers?
optionalheaders?:Record<string,string>
Extra headers merged onto the request. An explicit Authorization here is kept over the RATEL_API_KEY env fallback.
serviceName?
optionalserviceName?:string
service.name resource attribute. Defaults to DEFAULT_SERVICE_NAME.
ResolvedOtlpConfig
Resolved exporter configuration; the pure core of the OTLP exporter, exposed for testing.
Properties
headers
headers:
Record<string,string>
serviceName
serviceName:
string
url
url:
string
Type Aliases
AuthOutcome
AuthOutcome = typeof
AuthOutcome[keyof typeofAuthOutcome]
Outcome of an MCP auth flow. Carried by ratel.auth.outcome; NeedsAuth is
the 401-driven AuthNeeds case (ADR-0007 auth_needs).
ContentCapture
ContentCapture = typeof
ContentCapture[keyof typeofContentCapture]
Message/tool content capture modes for
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT (CONVENTIONS.md § Capture
gating). Default off.
Origin
Whether a ratel.* span was a direct library call or synthesized by the agent
inside its loop. Carried by ratel.origin; mirrors the local trace Origin
(ADR-0007).
SearchTarget
SearchTarget = typeof
SearchTarget[keyof typeofSearchTarget]
What a ratel.search span was searching. Carried by ratel.search.target;
folds capability-tool search and skill search into one span shape.
Variables
API_KEY_ENV
constAPI_KEY_ENV:"RATEL_API_KEY"="RATEL_API_KEY"
Env var whose value is the default Ratel API key.
AuthOutcome
constAuthOutcome:object
Outcome of an MCP auth flow. Carried by ratel.auth.outcome; NeedsAuth is
the 401-driven AuthNeeds case (ADR-0007 auth_needs).
Type Declaration
| Name | Type | Default value |
|---|---|---|
Failed | "failed" | "failed" |
NeedsAuth | "needs_auth" | "needs_auth" |
Ok | "ok" | "ok" |
Refreshed | "refreshed" | "refreshed" |
CAPTURE_CONTENT_ENV
constCAPTURE_CONTENT_ENV:"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"="OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"
The ecosystem instrumentation env var gating message/tool content capture.
Default off; honored by init() rather than a Ratel-invented flag
(CONVENTIONS.md § Capture gating). Values: legacy boolean, or the enum
NO_CONTENT (default) / SPAN_ONLY / EVENT_ONLY / SPAN_AND_EVENT.
ContentCapture
constContentCapture:object
Message/tool content capture modes for
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT (CONVENTIONS.md § Capture
gating). Default off.
Type Declaration
| Name | Type | Default value |
|---|---|---|
EventOnly | "EVENT_ONLY" | "EVENT_ONLY" |
NoContent | "NO_CONTENT" | "NO_CONTENT" |
SpanAndEvent | "SPAN_AND_EVENT" | "SPAN_AND_EVENT" |
SpanOnly | "SPAN_ONLY" | "SPAN_ONLY" |
DEFAULT_SERVICE_NAME
constDEFAULT_SERVICE_NAME:"ratel"="ratel"
service.name used when the caller does not pass one.
ENDPOINT_ENV
constENDPOINT_ENV:"RATEL_URL"="RATEL_URL"
Env var whose value is the default OTLP endpoint.
EXECUTE_TOOL
constEXECUTE_TOOL:"execute_tool"="execute_tool"
execute_tool — the gen_ai.operation.name value for a tool invocation.
Deliberately the standard OTel gen_ai operation, not a bespoke ratel.invoke
span, so a generic OTel backend already understands it (locked 2026-07-05). The
invoke is enriched with ratel.* attributes.
GEN_AI_INFERENCE_DETAILS
constGEN_AI_INFERENCE_DETAILS:"gen_ai.client.inference.operation.details"="gen_ai.client.inference.operation.details"
gen_ai.client.inference.operation.details — the event that carries message
text and tool-call content (never span attributes). Borrowed from gen_ai (Tier 1).
GEN_AI_OPERATION_NAME
constGEN_AI_OPERATION_NAME:"gen_ai.operation.name"="gen_ai.operation.name"
gen_ai.operation.name — set to EXECUTE_TOOL for a tool invocation.
GEN_AI_TOOL_CALL_ARGUMENTS
constGEN_AI_TOOL_CALL_ARGUMENTS:"gen_ai.tool.call.arguments"="gen_ai.tool.call.arguments"
gen_ai.tool.call.arguments — tool arguments (Opt-In content, gated).
GEN_AI_TOOL_CALL_ID
constGEN_AI_TOOL_CALL_ID:"gen_ai.tool.call.id"="gen_ai.tool.call.id"
gen_ai.tool.call.id — tool call id, when available.
GEN_AI_TOOL_CALL_RESULT
constGEN_AI_TOOL_CALL_RESULT:"gen_ai.tool.call.result"="gen_ai.tool.call.result"
gen_ai.tool.call.result — tool result (Opt-In content, gated).
GEN_AI_TOOL_NAME
constGEN_AI_TOOL_NAME:"gen_ai.tool.name"="gen_ai.tool.name"
gen_ai.tool.name — the capability tool id.
Origin
constOrigin:object
Whether a ratel.* span was a direct library call or synthesized by the agent
inside its loop. Carried by ratel.origin; mirrors the local trace Origin
(ADR-0007).
Type Declaration
RATEL_AUTH_FLOW
constRATEL_AUTH_FLOW:"ratel.auth.flow"="ratel.auth.flow"
ratel.auth.flow — MCP auth flow.
RATEL_AUTH_OUTCOME
constRATEL_AUTH_OUTCOME:"ratel.auth.outcome"="ratel.auth.outcome"
ratel.auth.outcome — ok / refreshed / needs_auth / failed (see AuthOutcome).
RATEL_ORIGIN
constRATEL_ORIGIN:"ratel.origin"="ratel.origin"
ratel.origin — direct library call vs agent-synthesized (shared attribute).
RATEL_SEARCH
constRATEL_SEARCH:"ratel.search"="ratel.search"
ratel.search — capability search (unifies tool-search and skill-search).
RATEL_SEARCH_HIT_COUNT
constRATEL_SEARCH_HIT_COUNT:"ratel.search.hit_count"="ratel.search.hit_count"
ratel.search.hit_count — results returned.
RATEL_SEARCH_QUERY
constRATEL_SEARCH_QUERY:"ratel.search.query"="ratel.search.query"
ratel.search.query — the search text (content, gated like message content).
RATEL_SEARCH_RESULTS
constRATEL_SEARCH_RESULTS:"ratel.search.results"="ratel.search.results"
ratel.search.results — Opt-In event carrying hit ids + scores + per-stage
BM25 timing; gated like content. The ratel.search span itself carries only counts.
RATEL_SEARCH_TARGET
constRATEL_SEARCH_TARGET:"ratel.search.target"="ratel.search.target"
ratel.search.target — tool or skill (see SearchTarget).
RATEL_SEARCH_TOP_K
constRATEL_SEARCH_TOP_K:"ratel.search.top_k"="ratel.search.top_k"
ratel.search.top_k — requested result count.
RATEL_SKILL_ID
constRATEL_SKILL_ID:"ratel.skill.id"="ratel.skill.id"
ratel.skill.id — skill loaded on the ratel.skill.load span.
RATEL_SKILL_LOAD
constRATEL_SKILL_LOAD:"ratel.skill.load"="ratel.skill.load"
ratel.skill.load — skill content load (get_skill_content).
RATEL_TOOL_ARGS_SIZE_BYTES
constRATEL_TOOL_ARGS_SIZE_BYTES:"ratel.tool.args_size_bytes"="ratel.tool.args_size_bytes"
ratel.tool.args_size_bytes — argument payload size on the execute_tool span.
RATEL_UPSTREAM_REGISTER
constRATEL_UPSTREAM_REGISTER:"ratel.upstream.register"="ratel.upstream.register"
ratel.upstream.register — upstream-MCP ingest.
RATEL_UPSTREAM_SERVER
constRATEL_UPSTREAM_SERVER:"ratel.upstream.server"="ratel.upstream.server"
ratel.upstream.server — upstream MCP server backing a tool / auth flow.
RATEL_UPSTREAM_TOOL_COUNT
constRATEL_UPSTREAM_TOOL_COUNT:"ratel.upstream.tool_count"="ratel.upstream.tool_count"
ratel.upstream.tool_count — tools ingested on register.
RATEL_UPSTREAM_TRANSPORT
constRATEL_UPSTREAM_TRANSPORT:"ratel.upstream.transport"="ratel.upstream.transport"
ratel.upstream.transport — stdio / http / sse / ...
SearchTarget
constSearchTarget:object
What a ratel.search span was searching. Carried by ratel.search.target;
folds capability-tool search and skill search into one span shape.
Type Declaration
SEMCONV_VERSION
constSEMCONV_VERSION:"1.42.0"="1.42.0"
The pinned OpenTelemetry semantic-conventions version this vocabulary tracks
(the gen_ai group). The pin is the contract; consumers read against this
exact version, never "latest" (CONVENTIONS.md § The pin).
Functions
clearContentCapture()
clearContentCapture(
generation):void
Clear the programmatic content-capture override, but only when generation —
the token returned by setContentCapture — still identifies the most
recent set. A stale token no-ops, so an old handle shutting down late cannot
clobber an override a newer caller installed (and silently re-enable, or
disable, capture via the env fallback). For an unconditional clear, use
setContentCapture(null).
Parameters
| Parameter | Type |
|---|---|
generation | number |
Returns
void
contentCaptureMode()
contentCaptureMode(
env?):ContentCapture
Parse the ecosystem content-capture gate. A mode set via
setContentCapture wins outright (env is the fallback, as in OTel);
otherwise default ContentCapture.NoContent when unset/empty/unrecognized.
The legacy boolean form maps true to full capture
(ContentCapture.SpanAndEvent) and false to none.
Parameters
| Parameter | Type | Default value |
|---|---|---|
env | Record<string, string | undefined> | process.env |
Returns
resolveOtlpConfig()
resolveOtlpConfig(
opts?,env?):ResolvedOtlpConfig
Resolve InitOptions into concrete exporter config. Pure and env-injectable so the endpoint/auth precedence is testable without a network.
Parameters
| Parameter | Type | Default value |
|---|---|---|
opts | InitOptions | {} |
env | Record<string, string | undefined> | process.env |
Returns
setContentCapture()
setContentCapture(
mode):number
Programmatically set the content-capture mode. While set,
contentCaptureMode returns this mode regardless of
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT — programmatic config wins
over the environment, matching how OpenTelemetry treats env vars as the
fallback for code-level configuration. Pass null/undefined to clear the
override unconditionally and return to env-driven parsing.
The mode is validated like the env var (case-insensitive, legacy true/false/
1/0 accepted) and throws a TypeError on anything unrecognized — failing
loud at config time instead of storing a value that would both disable capture
and mask the env var.
Returns a generation token identifying this call as the current owner of the override; pass it to clearContentCapture to clear only if no newer set has happened since (the safe form for shutdown/teardown hooks).
Parameters
| Parameter | Type |
|---|---|
mode | ContentCapture | null | undefined |
Returns
number