Documentation Index
Fetch the complete documentation index at: https://docs.hipocap.com/llms.txt
Use this file to discover all available pages before exploring further.
Laminar.serializeLaminarSpanContext(span?)
Serialize span context for cross-service propagation.await observe({ name: 'service_a' }, async () => {
const context = Laminar.serializeLaminarSpanContext();
await fetch('/api/service-b', {
headers: { 'X-Laminar-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.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.import { Laminar } from '@lmnr-ai/lmnr';
const span = Laminar.startSpan({
name: 'service_b_handler',
parentSpanContext: contextString,
});
Example: Validate untrusted inputconst raw = req.headers['x-laminar-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: LaminarSpanContextLaminar.serialize_span_context(span?)
Serialize span context for cross-service propagation.@observe()
def service_a():
context = Laminar.serialize_span_context()
requests.post("http://service-b/api",
headers={"X-Laminar-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.# In service B
context_str = request.headers.get("X-Laminar-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: LaminarSpanContextExample: Safe deserializationfrom lmnr import Laminar
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.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.@dataclass
class LaminarSpanContext:
trace_id: UUID
span_id: UUID
is_remote: bool = False
span_path: list[str]
span_ids_path: list[str]