Tracing
Tracing protocol schemas
Tracing Protocol - Distributed Tracing & Observability
Comprehensive distributed tracing based on OpenTelemetry standards:
- Trace context propagation
- Span creation and management
- Sampling strategies
- Integration with tracing backends (Jaeger, Zipkin, etc.)
- W3C Trace Context standard compliance
Source: packages/spec/src/system/tracing.zod.ts
TypeScript Usage
import { OpenTelemetryCompatibilitySchema, OtelExporterType, SamplingDecision, SamplingStrategyType, SpanSchema, SpanAttributeValueSchema, SpanAttributesSchema, SpanEventSchema, SpanKind, SpanLinkSchema, SpanStatus, TraceContextSchema, TraceContextPropagationSchema, TraceFlagsSchema, TracePropagationFormat, TraceSamplingConfigSchema, TraceStateSchema, TracingConfigSchema } from '@objectstack/spec/system';
import type { OpenTelemetryCompatibility, OtelExporterType, SamplingDecision, SamplingStrategyType, Span, SpanAttributeValue, SpanAttributes, SpanEvent, SpanKind, SpanLink, SpanStatus, TraceContext, TraceContextPropagation, TraceFlags, TracePropagationFormat, TraceSamplingConfig, TraceState, TracingConfig } from '@objectstack/spec/system';
// Validate data
const result = OpenTelemetryCompatibilitySchema.parse(data);OpenTelemetryCompatibility
OpenTelemetry compatibility configuration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| sdkVersion | string | optional | OTel SDK version |
| exporter | { type: Enum<'otlp_http' | 'otlp_grpc' | 'jaeger' | 'zipkin' | 'console' | 'datadog' | …>; endpoint?: string; protocol?: string; headers?: Record<string, string>; … } | ✅ | Exporter configuration |
| resource | { serviceName: string; serviceVersion?: string; serviceInstanceId?: string; serviceNamespace?: string; … } | ✅ | Resource attributes |
| instrumentation | { autoInstrumentation: boolean; libraries?: string[]; disabledLibraries?: string[] } | optional | |
| semanticConventionsVersion | string | optional | Semantic conventions version |
Nested Shape: OpenTelemetryCompatibility.exporter
| Property | Type | Required | Description |
|---|---|---|---|
| type | Enum<'otlp_http' | 'otlp_grpc' | 'jaeger' | 'zipkin' | 'console' | 'datadog' | …> | ✅ | Exporter type |
| endpoint | string | optional | Exporter endpoint |
| protocol | string | optional | Protocol version |
| headers | Record<string, string> | optional | HTTP headers |
| timeout | integer | optional (default: 10000) | |
| compression | Enum<'none' | 'gzip'> | optional (default: "none") | |
| batch | { maxBatchSize: integer; maxQueueSize: integer; exportTimeout: integer; scheduledDelay: integer } | optional |
Nested Shape: OpenTelemetryCompatibility.resource
| Property | Type | Required | Description |
|---|---|---|---|
| serviceName | string | ✅ | Service name |
| serviceVersion | string | optional | Service version |
| serviceInstanceId | string | optional | Service instance ID |
| serviceNamespace | string | optional | Service namespace |
| deploymentEnvironment | string | optional | Deployment environment |
| attributes | Record<string, string | number | boolean | string[] | number[] | boolean[]> | optional | Additional resource attributes |
Nested Shape: OpenTelemetryCompatibility.instrumentation
| Property | Type | Required | Description |
|---|---|---|---|
| autoInstrumentation | boolean | optional (default: true) | |
| libraries | string[] | optional | Enabled libraries |
| disabledLibraries | string[] | optional | Disabled libraries |
OtelExporterType
OpenTelemetry exporter type
Allowed Values
otlp_httpotlp_grpcjaegerzipkinconsoledatadoghoneycomblightstepnewreliccustom
SamplingDecision
Sampling decision
Allowed Values
droprecord_onlyrecord_and_sample
SamplingStrategyType
Sampling strategy type
Allowed Values
always_onalways_offtrace_id_ratiorate_limitingparent_basedprobabilitycompositecustom
Span
OpenTelemetry span
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| context | { traceId: string; spanId: string; traceFlags: integer; traceState?: object; … } | ✅ | Trace context |
| name | string | ✅ | Span name |
| kind | Enum<'internal' | 'server' | 'client' | 'producer' | 'consumer'> | optional (default: "internal") | Span kind |
| startTime | string | ✅ | Span start time |
| endTime | string | optional | Span end time |
| duration | number | optional | Duration in milliseconds |
| status | { code: Enum<'unset' | 'ok' | 'error'>; message?: string } | optional | |
| attributes | Record<string, string | number | boolean | string[] | number[] | boolean[]> | optional (default: {}) | Span attributes |
| events | { name: string; timestamp: string; attributes?: Record<string, string | number | boolean | string[] | number[] | boolean[]> }[] | optional (default: []) | |
| links | { context: object; attributes?: Record<string, string | number | boolean | string[] | number[] | boolean[]> }[] | optional (default: []) | |
| resource | Record<string, string | number | boolean | string[] | number[] | boolean[]> | optional | Resource attributes |
| instrumentationLibrary | { name: string; version?: string } | optional |
Nested Shape: Span.context
| Property | Type | Required | Description |
|---|---|---|---|
| traceId | string | ✅ | Trace ID (32 hex chars) |
| spanId | string | ✅ | Span ID (16 hex chars) |
| traceFlags | integer | optional (default: 1) | Trace flags bitmap |
| traceState | { entries: Record<string, string> } | optional | Trace state |
| parentSpanId | string | optional | Parent span ID (16 hex chars) |
| sampled | boolean | optional (default: true) | |
| remote | boolean | optional (default: false) |
Nested Shape: Span.status
| Property | Type | Required | Description |
|---|---|---|---|
| code | Enum<'unset' | 'ok' | 'error'> | ✅ | Status code |
| message | string | optional | Status message |
Nested Shape: Span.events[number]
Span event
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Event name |
| timestamp | string | ✅ | Event timestamp |
| attributes | Record<string, string | number | boolean | string[] | number[] | boolean[]> | optional | Event attributes |
Nested Shape: Span.links[number]
Span link
| Property | Type | Required | Description |
|---|---|---|---|
| context | { traceId: string; spanId: string; traceFlags: integer; traceState?: object; … } | ✅ | Linked trace context |
| attributes | Record<string, string | number | boolean | string[] | number[] | boolean[]> | optional | Link attributes |
Nested Shape: Span.instrumentationLibrary
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Library name |
| version | string | optional | Library version |
SpanAttributeValue
Span attribute value
Union Options
This schema accepts one of the following structures:
Option 1
Type: string
Option 2
Type: number
Option 3
Type: boolean
Option 4
Type: string[]
Option 5
Type: number[]
Option 6
Type: boolean[]
SpanAttributes
Span attributes
Type: Record<string, string | number | boolean | string[] | number[] | boolean[]>
SpanEvent
Span event
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Event name |
| timestamp | string | ✅ | Event timestamp |
| attributes | Record<string, string | number | boolean | string[] | number[] | boolean[]> | optional | Event attributes |
SpanKind
Span kind
Allowed Values
internalserverclientproducerconsumer
SpanLink
Span link
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| context | { traceId: string; spanId: string; traceFlags: integer; traceState?: object; … } | ✅ | Linked trace context |
| attributes | Record<string, string | number | boolean | string[] | number[] | boolean[]> | optional | Link attributes |
Nested Shape: SpanLink.context
| Property | Type | Required | Description |
|---|---|---|---|
| traceId | string | ✅ | Trace ID (32 hex chars) |
| spanId | string | ✅ | Span ID (16 hex chars) |
| traceFlags | integer | optional (default: 1) | Trace flags bitmap |
| traceState | { entries: Record<string, string> } | optional | Trace state |
| parentSpanId | string | optional | Parent span ID (16 hex chars) |
| sampled | boolean | optional (default: true) | |
| remote | boolean | optional (default: false) |
SpanStatus
Span status
Allowed Values
unsetokerror
TraceContext
Trace context (W3C Trace Context)
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| traceId | string | ✅ | Trace ID (32 hex chars) |
| spanId | string | ✅ | Span ID (16 hex chars) |
| traceFlags | integer | optional (default: 1) | Trace flags bitmap |
| traceState | { entries: Record<string, string> } | optional | Trace state |
| parentSpanId | string | optional | Parent span ID (16 hex chars) |
| sampled | boolean | optional (default: true) | |
| remote | boolean | optional (default: false) |
Nested Shape: TraceContext.traceState
| Property | Type | Required | Description |
|---|---|---|---|
| entries | Record<string, string> | ✅ | Trace state entries |
TraceContextPropagation
Trace context propagation
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| formats | Enum<'w3c' | 'b3' | 'b3_multi' | 'jaeger' | 'xray' | 'ottrace' | 'custom'>[] | optional (default: ["w3c"]) | |
| extract | boolean | optional (default: true) | |
| inject | boolean | optional (default: true) | |
| headers | { traceId?: string; spanId?: string; traceFlags?: string; traceState?: string } | optional | |
| baggage | { enabled: boolean; maxSize: integer; allowedKeys?: string[] } | optional |
TraceFlags
Trace flags bitmap
Type: integer
TracePropagationFormat
Trace propagation format
Allowed Values
w3cb3b3_multijaegerxrayottracecustom
TraceSamplingConfig
Trace sampling configuration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| type | Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | 'probability' | 'composite' | 'custom'> | ✅ | Sampling strategy |
| ratio | number | optional | Sample ratio (0-1) |
| rateLimit | number | optional | Traces per second |
| parentBased | { whenParentSampled?: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; whenParentNotSampled?: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; root?: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; rootRatio?: number } | optional | |
| composite | { strategy: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; ratio?: number; condition?: Record<string, any> | string | object }[] | optional | |
| rules | { name: string; match?: object; decision: Enum<'drop' | 'record_only' | 'record_and_sample'>; rate?: number }[] | optional (default: []) | |
| customSamplerId | string | optional | Custom sampler identifier |
Nested Shape: TraceSamplingConfig.parentBased
| Property | Type | Required | Description |
|---|---|---|---|
| whenParentSampled | Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …> | optional (default: "always_on") | Sampling strategy type |
| whenParentNotSampled | Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …> | optional (default: "always_off") | Sampling strategy type |
| root | Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …> | optional (default: "trace_id_ratio") | Sampling strategy type |
| rootRatio | number | optional (default: 0.1) |
Nested Shape: TraceSamplingConfig.composite[number]
| Property | Type | Required | Description |
|---|---|---|---|
| strategy | Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …> | ✅ | Strategy type |
| ratio | number | optional | |
| condition | Record<string, any> | string | { dialect: Enum<'cel' | 'cron' | 'template'>; source?: string; ast?: any; meta?: object } | optional | Condition for this strategy — structured filter or CEL predicate |
Nested Shape: TraceSamplingConfig.rules[number]
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Rule name |
| match | { service?: string; spanName?: string; attributes?: Record<string, any> } | optional | |
| decision | Enum<'drop' | 'record_only' | 'record_and_sample'> | ✅ | Sampling decision |
| rate | number | optional |
TraceState
Trace state
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| entries | Record<string, string> | ✅ | Trace state entries |
TracingConfig
Tracing configuration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Configuration name (snake_case, max 64 chars) |
| label | string | ✅ | Display label |
| enabled | boolean | optional (default: true) | |
| sampling | { type: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; ratio?: number; rateLimit?: number; parentBased?: object; … } | optional | Trace sampling configuration |
| propagation | { formats?: Enum<'w3c' | 'b3' | 'b3_multi' | 'jaeger' | 'xray' | 'ottrace' | 'custom'>[]; extract?: boolean; inject?: boolean; headers?: object; … } | optional (default: {"formats":["w3c"],"extract":true,"inject":true}) | Trace context propagation |
| openTelemetry | { sdkVersion?: string; exporter: object; resource: object; instrumentation?: object; … } | optional | OpenTelemetry compatibility configuration |
| spanLimits | { maxAttributes?: integer; maxEvents?: integer; maxLinks?: integer; maxAttributeValueLength?: integer } | optional | |
| traceIdGenerator | Enum<'random' | 'uuid' | 'custom'> | optional (default: "random") | |
| customTraceIdGeneratorId | string | optional | Custom generator identifier |
| performance | { asyncExport?: boolean; exportInterval?: integer } | optional |
Nested Shape: TracingConfig.sampling
| Property | Type | Required | Description |
|---|---|---|---|
| type | Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …> | ✅ | Sampling strategy |
| ratio | number | optional | Sample ratio (0-1) |
| rateLimit | number | optional | Traces per second |
| parentBased | { whenParentSampled?: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; whenParentNotSampled?: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; root?: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; rootRatio?: number } | optional | |
| composite | { strategy: Enum<'always_on' | 'always_off' | 'trace_id_ratio' | 'rate_limiting' | 'parent_based' | …>; ratio?: number; condition?: Record<string, any> | string | object }[] | optional | |
| rules | { name: string; match?: object; decision: Enum<'drop' | 'record_only' | 'record_and_sample'>; rate?: number }[] | optional (default: []) | |
| customSamplerId | string | optional | Custom sampler identifier |
Nested Shape: TracingConfig.openTelemetry
| Property | Type | Required | Description |
|---|---|---|---|
| sdkVersion | string | optional | OTel SDK version |
| exporter | { type: Enum<'otlp_http' | 'otlp_grpc' | 'jaeger' | 'zipkin' | 'console' | 'datadog' | …>; endpoint?: string; protocol?: string; headers?: Record<string, string>; … } | ✅ | Exporter configuration |
| resource | { serviceName: string; serviceVersion?: string; serviceInstanceId?: string; serviceNamespace?: string; … } | ✅ | Resource attributes |
| instrumentation | { autoInstrumentation?: boolean; libraries?: string[]; disabledLibraries?: string[] } | optional | |
| semanticConventionsVersion | string | optional | Semantic conventions version |