Skip to main content
SIL (Struct Instrumentation Language) is the JSON document format used to define Observations for running Python services — both permanent baseline captures and short-lived, auto-expiring triage overlays (target: {"kind": "overlay", "id": "..."}, completion: {"expiresAfterSeconds": 1800}).
Validate any SIL document before drafting with struct observations validate --file obs.sil.json --json. If your installed CLI includes struct observations guide or struct docs, use struct observations guide [topic] or struct docs sil to read the guide and examples offline.

Document structure

What can be targeted

  • Function boundaries. enter runs when the function starts executing, return on normal completion, and unwind when an exception escapes it. Ordinary functions and methods support point captures and paired spans. SDK builds with native suspension support extend these hooks to async def functions, generators, async generators and verified contextlib context managers. Awaits and item yields leave the call open.
  • Public Python packages. With struct-sdk 0.5.25 and struct-sdk-native 0.1.15, use the source-anchored hooks below inside async def functions. Async boundaries and spans across suspension require a newer SDK build with native suspension support. Check which build the process runs.
  • Source-anchored hooks. Use these as standalone points in ordinary functions or coroutines. They require an exact match to the running source. Start a fresh call after installation to verify an interior point.
    • {"event": "before", "operation": {"kind": "await_assignment", "call": "client.fetch", "assign_to": "response"}} runs before response = await client.fetch(...). Change before to after to capture after a successful assignment. A failed or cancelled await skips after.
    • {"event": "except", "handler": {"source": "TimeoutError"}} runs on entry to a unique except TimeoutError handler. A function containing except* fails handler source proof.
    • location runs before a verified simple statement. Set at.event to location and at.location to the statement’s line (one-based), column (zero-based UTF-8 byte offset) and source_digest (sha256: followed by the SHA-256 hex digest of the exact Python file bytes).
  • Binding and Temporal. Unverified decorators, generator-based types.coroutine functions and unsupported source points can produce struct.observations.health reports. Ordinary methods on supported Pydantic models and abstract base classes can bind. The runtime suppresses capture while Temporal reports an active workflow. Activities follow normal Python rules, including async activities. The suppression starts when the workflow is active, after sandbox imports and initial payload conversion.

Reads

A read is a safe path, never an arbitrary expression (no function calls, operators, or whitespace outside quoted keys). At most 4 path steps after the root (under args, locals and start, the first key names the binding and does not count).Events and spans omit unreadable values and record the reason in struct.capture.field_states. A metric skips its sample when the value or any attribute is unreadable. The SDK avoids executing properties and ORM descriptors during capture. For example, locals['row'].status can yield blocked_read for a SQLAlchemy row even when the application reads row.status successfully. If the application already assigned the value to a scalar local (status) or passed it to another function, capture that local or argument at the corresponding point.

Outputs and conditions

  • Event (emit.event): arrives as a log record with log.event_name = <name>. Optional severity: trace, debug, info (default), warn, error, fatal.
  • Metrics (emit.metrics): array of {type, name, unit, value, attributes?, when?}. type is counter, up_down_counter, histogram or gauge. unit is required. value is a number or {"field": "<capture>"}. One metric name must keep one type and unit across the whole scope.
  • Span (emit.span): requires start and end instead of at (see Span with duration). At most one Observation can create a span on a given target function.
  • Span update (emit.span_update): a point definition can update an existing span with "target": "current". Use "target": "observation" only when this definition creates a span.
  • Conditions (when): eq, ne, gt, ge, lt, le, and, or, not, e.g. {"eq": [{"field": "status"}, "failed"]}.
  • Naming: use lowercase names with dots and underscores (refunds.provider). Names cannot start with struct. or otel.. Metric names must start with a lowercase letter, contain only lowercase letters, digits, _, ., / or -, and be at most 255 characters. Keep event and span names short. Use standard OpenTelemetry names (http.route, error.type) only with their standard meaning. One trigger emits at most eight outputs.

Limits and rules

  • Strict JSON: no duplicate keys, no NaN/Infinity, integers must fit signed 64-bit, 1 (int) and 1.0 (float) keep distinct types.
  • Per-definition bounds: at most 8 distinct code reads, 32 condition operations at one execution point, expression nesting 16 deep, 32 rules, 8 outputs per trigger, and 4 span links.
  • Events before metrics: a monitor over an event or span can be created before any data exists (count() reads 0). A monitor over a metric is refused until the metric has reported at least one sample. For < floor / heartbeat monitors, wait for at least one full window of data before creating the monitor.

Reading captured data back

  • By Observation ID (traces or logs): filter struct.observation.id = '<id>' AND service.name = '<service>' AND resource.deployment.environment.name = '<env>'. (struct.observation.id supports filter operators only; it cannot be grouped, selected or aggregated.)
  • By event name (logs): log.event_name = '<name>' AND service.name = '<service>' AND resource.deployment.environment.name = '<env>'.
  • By span name (traces): span.name = '<name>' with the same service and environment.
  • By metric name (metrics): lowercase metric name with the same service and environment.
  • Live verification: follow the verification procedure to check artifact readiness, SDK health and actual captured rows. Add a resource filter to confirm delivery from the intended worker in a shared scope.

Worked examples

Event on return (event_on_return)

Record an outcome with low-cardinality dimensions for grouping and monitoring:

Failure event (failure_event)

Record exceptions raised by a function while ignoring cancellations:

Span with duration (span_with_duration)

Wrap a function in a span, record its duration histogram on return, and mark errors on unwind. SDK builds with native suspension support can use the same definition for async def:

Conditional metric (conditional_metric)

Emit an event on every return and increment a counter only when a condition matches:

Inside an async def (async_after_await)

Capture a boolean local after the successful assignment in dispatched = await repository.dispatch_if_current(...):