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

# Context Utilities

> [tab] TypeScript
>
> Laminar.serializeLaminarSpanContext(span?)
>
> Serialize span context for cross-service propagation.
>
> ```typescript theme={null}
> await observe({ name: 'service_a' }, async () => {
>   const context = Laminar.serializeLaminarSpanContext();
>
>   await fetch('/api/service-b', {
>     headers: { 'X-Tracevell-Span-Context': context },
>   });
> });
> ```
>
> **Parameters:**
>
> | Name | Type | Default | Description |
> | - | - | - | - |
> | `span` | `Span` | Active span | Optional span |
>
> **Returns:** `string | null` — JSON string containing `traceId`, `spanId`, `isRemote`, `spanPath`, `spanIdsPath`
>
> ***
>
> Laminar.getLaminarSpanContext(span?)
>
> Get span context as an object.
>
> ```typescript theme={null}
> const context = Laminar.getLaminarSpanContext();
> // { traceId, spanId, isRemote, spanPath, spanIdsPath }
> ```
>
> **Parameters:**
>
> | Name | Type | Default | Description |
> | - | - | - | - |
> | `span` | `Span` | Active span | Optional span |
>
> **Returns:** `LaminarSpanContext | null`
>
> ***
>
> deserializeLaminarSpanContext(data) (internal)
>
> Not exported from `@lmnr-ai/lmnr`. You typically do not need to deserialize manually—pass the serialized context directly as `parentSpanContext` when starting a span.
>
> ```typescript theme={null}
> import { Tracevell } from '@lmnr-ai/lmnr';
>
> const span = Laminar.startSpan({
>   name: 'service_b_handler',
>   parentSpanContext: contextString,
> });
> ```
>
> **Example: Validate untrusted input**
>
> ```typescript theme={null}
> const raw = req.headers['x-tracevell-span-context'];
> const parentSpanContext = typeof raw === 'string' && raw.length > 0 ? raw : undefined;
>
> const span = Laminar.startSpan({ name: 'service_b_handler', parentSpanContext });
> span.end();
> ```
>
> **Parameters:**
>
> | Name | Type | Description |
> | - | - | - |
> | `data` | `string` \| `Record<string, unknown>` | Serialized context (accepts camelCase or snake\_case) |
>
> **Returns:** `LaminarSpanContext`

> [tab] Python
>
> Laminar.serialize\_span\_context(span?)
>
> Serialize span context for cross-service propagation.
>
> ```python theme={null}
> @observe()
>     def service_a():
>         context = Laminar.serialize_span_context()
>
>         requests.post("http://service-b/api", 
>             headers={"X-Tracevell-Span-Context": context}
>         )
> ```
>
> **Parameters:**
>
> | Name | Type | Default | Description |
> | - | - | - | - |
> | `span` | `Span` | Active span | Optional span |
>
> **Returns:** `str | None` — JSON string
>
> ***
>
> Laminar.deserialize\_span\_context(span\_context)
>
> Deserialize span context from string or dict.
>
> ```python theme={null}
> # In service B
> context_str = request.headers.get("X-Tracevell-Context")
> parent = Laminar.deserialize_span_context(context_str)
>
> with Laminar.start_as_current_span(
>     name="service_b_handler",
>     parent_span_context=parent
> ):
>     handle_request()
> ```
>
> **Parameters:**
>
> | Name | Type | Description |
> | - | - | - |
> | `span_context` | `dict` \| `str` | Serialized context |
>
> **Returns:** `LaminarSpanContext`
>
> **Example: Safe deserialization**
>
> ```python theme={null}
> from lmnr import Tracevell
>
> def safe_deserialize(context_str):
>     try:
>         return Laminar.deserialize_span_context(context_str) if context_str else None
>     except Exception:
>         return None
> ```
>
> ***
>
> Laminar.get\_laminar\_span\_context(span?)
>
> Get span context as an object.
>
> ```python theme={null}
> context = Laminar.get_laminar_span_context()
> # LaminarSpanContext(trace_id, span_id, is_remote, span_path, span_ids_path)
> ```
>
> **Parameters:**
>
> | Name | Type | Default | Description |
> | - | - | - | - |
> | `span` | `trace.Span` \| `None` | Active span | Optional span |
>
> **Returns:** `LaminarSpanContext | None`
>
> ***
>
> Laminar.get\_laminar\_span\_context\_dict(span?)
>
> Get span context as a dictionary.
>
> **Parameters:**
>
> | Name | Type | Default | Description |
> | - | - | - | - |
> | `span` | `trace.Span` \| `None` | Active span | Optional span |
>
> **Returns:** `dict | None`
>
> ***
>
> LaminarSpanContext
>
> Span context for distributed tracing.
>
> ```python theme={null}
> @dataclass
> class LaminarSpanContext:
>     trace_id: UUID
>     span_id: UUID
>     is_remote: bool = False
>     span_path: list[str]
>     span_ids_path: list[str]
> ```


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