temporaltrace

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package temporaltrace defines the OpenTelemetry tracing contract for Temporal activity execution in loom-mcp powered runtimes.

Contract:

  • Temporal activities execute in a distinct trace domain from synchronous request handling (HTTP/gRPC). Each activity execution starts a new root span (new trace ID) to avoid long-lived traces that fragment in collectors and sampling pipelines.
  • If an activity is causally triggered by an upstream request trace, the upstream trace is preserved via an OTel link, not parenthood. This keeps trace trees semantically honest while retaining navigability across domains.
  • Control-plane and retry scheduling are not "children" in the request tree. Durable scheduling becomes a link between traces.

Index

Constants

View Source
const (
	// HeaderTraceParent is the Temporal header key that carries the upstream W3C
	// traceparent string for trace-linking.
	HeaderTraceParent = "ck.traceparent"
)

Variables

This section is empty.

Functions

func NewActivityInterceptor

func NewActivityInterceptor() interceptor.WorkerInterceptor

NewActivityInterceptor returns a worker interceptor that starts a new root span for each activity execution and links it to the origin trace (when present).

func NewLinkPropagator

func NewLinkPropagator() workflow.ContextPropagator

NewLinkPropagator returns a Temporal context propagator that carries the origin traceparent string across workflow/activity headers.

func OriginTraceParent

func OriginTraceParent(ctx context.Context) (string, bool)

OriginTraceParent returns the origin traceparent string stored by WithOriginTraceParent, if any.

func ParseTraceParent

func ParseTraceParent(traceparent string) (trace.SpanContext, error)

ParseTraceParent parses a W3C traceparent header into a remote span context.

This function enforces the core traceparent validity rules (shape, hex encoding, non-zero trace/span IDs). If traceparent is invalid, it returns an error to surface contract violations early.

func TraceParent

func TraceParent(ctx context.Context) string

TraceParent returns the W3C traceparent string for the active span in ctx. Returns an empty string if no active span exists.

func WithOriginTraceParent

func WithOriginTraceParent(ctx context.Context, traceparent string) context.Context

WithOriginTraceParent returns a derived context carrying the origin traceparent string. This value is used to link durable execution traces back to the initiating request trace.

Types

type ActivityInterceptor

type ActivityInterceptor struct {
	interceptor.WorkerInterceptorBase

	Tracer trace.Tracer
}

ActivityInterceptor starts a new root span for each activity execution and attaches an OTel link to the origin trace (when present).

type LinkPropagator

type LinkPropagator struct {
	Converter converter.DataConverter
}

LinkPropagator carries an origin traceparent string through Temporal workflow/activity headers under HeaderTraceParent.

The payload is encoded with Temporal's data converter so it can safely flow across SDK versions and language boundaries.

func (*LinkPropagator) Extract

func (*LinkPropagator) ExtractToWorkflow

func (p *LinkPropagator) ExtractToWorkflow(ctx workflow.Context, reader workflow.HeaderReader) (workflow.Context, error)

func (*LinkPropagator) Inject

func (p *LinkPropagator) Inject(ctx context.Context, writer workflow.HeaderWriter) error

func (*LinkPropagator) InjectFromWorkflow

func (p *LinkPropagator) InjectFromWorkflow(ctx workflow.Context, writer workflow.HeaderWriter) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL