> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Application code puts a TableModel in app.py, then runs `pxt schema update app.py my_app` to create the tables and `pxt service update app.py my_app` to start HTTP. The last argument can be a Cloud URL such as `pxt://org:db`. Do not call pxt.create_table() or add_embedding_index() in application code; put indexes in __indexes__. Notebooks, tests, and the REPL do use pxt.create_table().
> Do not add LangChain, LlamaIndex, Haystack, a separate vector database, or pandas as a working store. Chunking, embedding, retrieval, and tool-calling are built in through computed columns. Use a computed column instead of a per-row loop that calls a model.
> Install with `pip install -U 'pixeltable[serve]'` on Python 3.11+. `pxt init` is a prerequisite for `pxt schema update`.
> For Pixeltable Cloud, point users to https://docs.pixeltable.com/cloud, which goes from `pxt login` to a running service.

# telemetry

> <a href="https://github.com/pixeltable/pixeltable/blob/main/pixeltable/telemetry.py#L0" id="viewSource" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/View%20Source%20on%20Github-blue?logo=github&labelColor=gray" alt="View Source on GitHub" style={{ display: 'inline', margin: '0px' }} noZoom /></a>

# module  pixeltable.telemetry

Dependency-free instrumentation hooks.

Core pixeltable reports spans (timed, nested units of work), discrete events attached to spans, and
metrics through this module; subscribers (e.g. the bridge in `opentelemetry-instrumentation-pixeltable`)
translate them into a telemetry backend. Metric instruments are declared once at module level
(`_rows = telemetry.counter(...)`) and recorded where the measurement happens
(`_rows.add(n, table=path)`). With no subscribers registered every call is a near-free no-op, but hot
loops should still guard with `if telemetry.active():` before building attribute dicts (or pass `attrs`
as a callable).

In production, run with log export disabled (the bridge's default; `logs=False`) or route exports
through a collector configured to redact secrets: log records can carry credentials (API keys in
error messages, signed URLs, connection strings) that would otherwise leak to the telemetry backend.

Spans should cover contiguous units of real computation (a UDF call, a DB insert batch, model loading) or
serve as structural containers (operation and exec-node spans). A CPU work span must not contain a
`yield`/`await`, which would let it cover unrelated interleaved work; awaiting an external call inside a
span is fine (the request really is in flight).

## func  counter()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
counter(name: str, unit: str = '') -> Counter
```

Declare a counter instrument; module-level, once per metric name.

## func  emit()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
emit(handle: SpanHandle | None, name: str, **attrs: Any) -> None
```

Attach a discrete event to the given span; a no-op for None handles.

Keyword attrs get a 'pxt.' prefix; None values are skipped.

## func  func\_span()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
func_span() -> SpanHandle | None
```

Handle of the innermost enclosing spanned() span, for use with add\_attrs().

None if there is no enclosing spanned() function or its span was suppressed (add\_attrs() accepts None).

## func  histogram()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
histogram(
    name: str,
    unit: str = '',
    boundaries: tuple[float, ...] | None = None
) -> Histogram
```

Declare a histogram instrument; module-level, once per metric name.

## func  span()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
span(
    name: str,
    *,
    level: int = 20,
    parent: SpanHandle | None = None,
    set_current: bool = False,
    **attrs: Any
) -> Iterator[SpanHandle | None]
```

Context-manager sugar for a lexical-block span.

Keyword attrs get a 'pxt.' prefix; None values are skipped.

## func  span\_end()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
span_end(
    handle: SpanHandle | None,
    *,
    exc: BaseException | None = None,
    attrs: HookAttrs = None
) -> None
```

End a span started with span\_start(); a no-op for None handles.

## func  span\_start()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
span_start(
    name: str,
    *,
    level: int = 20,
    parent: SpanHandle | None = None,
    set_current: bool = False,
    attrs: HookAttrs = None
) -> SpanHandle | None
```

Start a span and return its handle; None if no subscribers are registered or the span is suppressed.

Spans below the level threshold are suppressed, as are non-set\_current spans with no ambient ancestor;
descendants of a suppressed span parent to the ambient span. set\_current=True makes the span the
ambient parent (a ContextVar, so it propagates into asyncio tasks) and requires that span\_end() runs
on the same thread/context; use capture\_context()/restore\_context()/exit\_context() for explicit
thread handoffs.

## func  spanned()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
spanned(
    name: str,
    *,
    level: int = 20,
    set_current: bool = False,
    nest_children: bool = False
) -> Callable[[F], F]
```

Decorator form of span() for a function whose entire body is one span.

The span's handle isn't lexically available inside the function; use `add_attrs(func_span(), ...)` to
attach attributes to it. nest\_children=True makes spans started inside the function nest under this span,
but only inside an operation span, so that this span never becomes a root.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.