xa.telemetry

Named telemetry profiles: where a session’s OTLP trace export goes, and where its credentials live.

A profile is a [telemetry.<name>] table of ~/.config/xa/config.toml; xa spawn --telemetry <name> (and resume) turns it into an xa.claude_env.OtlpTraces.

[telemetry.lab]
endpoint = "https://otel.example.com/v1/traces"
headers_file = "~/.config/xa/lab.keys"       # KEY=VALUE lines, mode 600, yours
export_interval_ms = 5000
content = false                              # prompts and tool output stay out
[telemetry.lab.resource]
team = "fleet"
[telemetry.lab.headers]                      # header name = template over the file's keys
Authorization = "Bearer ${LAB_TOKEN}"

Credentials never leave their file. The config holds key names only; the values are read from headers_file at the moment a pane starts, by the pane’s own shell (_xa_h="$(xa telemetry-headers lab)" && export OTEL_EXPORTER_OTLP_HEADERS="$_xa_h"). So the tmux command line, ps, the archive and the logs carry the expression, never the value, and xa writes no file of its own. A missing key is an error that names the key.

Functions

get_telemetry_profile(name[, path])

The profile called name; an unknown name lists the known ones.

load_telemetry_profiles([path])

Every [telemetry.*] profile of the config file (empty when there is none).

profile_from_table(name, raw)

Build a profile from its [telemetry.<name>] table; unknown keys are an error (typos).

read_keys_file(path)

The KEY=VALUE lines of a keys file (export prefix, quotes and whole-line # comments tolerated).

Classes

TelemetryProfile(name, endpoint[, protocol, ...])

One named export target: its non-secret settings plus where its headers come from.

class xa.telemetry.TelemetryProfile(name, endpoint, protocol='http/protobuf', content=False, resource=dict(), export_interval_ms=None, headers_file=None, headers=dict())[source]

Bases: object

One named export target: its non-secret settings plus where its headers come from.

headers_env_value()[source]

The value of OTEL_EXPORTER_OTLP_HEADERS (empty when the profile has no headers).

Return type:

str

resolve_headers()[source]

{header: value} with each ${KEY} read from headers_file.

The keys file is the only source: a pane’s environment is the tmux server’s, not the caller’s, so an environment fallback would pass here and fail there. Raises ValueError naming the missing key (never a value).

Return type:

dict

shell_export(*, xa_command=None)[source]

The shell fragment that exports the headers in the pane, or '' without headers.

It holds a command substitution, never the value.

>>> p = TelemetryProfile('lab', 'http://h/v1/traces', headers={'A': '${K}'})
>>> export = p.shell_export(xa_command=['xa'])
>>> export.startswith('_xa_h="$(XA_CONFIG='), 'telemetry-headers lab' in export
(True, True)
Return type:

str

traces()[source]

The OtlpTraces for the command line: no headers, so no secret.

Return type:

OtlpTraces

xa.telemetry.get_telemetry_profile(name, path=None)[source]

The profile called name; an unknown name lists the known ones. Headers are checked now.

Resolving them here means a missing key fails the xa spawn that asked, in the caller’s terminal, rather than silently in a pane that exits on start.

Return type:

TelemetryProfile

xa.telemetry.load_telemetry_profiles(path=None)[source]

Every [telemetry.*] profile of the config file (empty when there is none).

Return type:

dict[str, TelemetryProfile]

xa.telemetry.profile_from_table(name, raw)[source]

Build a profile from its [telemetry.<name>] table; unknown keys are an error (typos).

Return type:

TelemetryProfile

xa.telemetry.read_keys_file(path)[source]

The KEY=VALUE lines of a keys file (export prefix, quotes and whole-line # comments tolerated).

>>> import tempfile
>>> p = Path(tempfile.mkdtemp()) / 'k'
>>> _ = p.write_text('# c\nexport A="1"\nB=two\n')
>>> read_keys_file(p)
{'A': '1', 'B': 'two'}
Return type:

dict[str, str]