Documentation
¶
Overview ¶
Package dttrace implements replay-aware Durable Task OpenTelemetry spans.
Index ¶
- Constants
- Variables
- func EndClientSpan(span trace.Span, err error)
- func EntityOperationSpanContext(ctx context.Context, index int, requestID string) trace.SpanContext
- func RandomSpanID() trace.SpanID
- func RandomTraceID() trace.TraceID
- func SpanName(kind, name, version string) string
- func StartActivitySpan(ctx context.Context) context.Context
- func WithActivity(ctx context.Context, activity *Activity) context.Context
- func WithEntityBatch(ctx context.Context, batch *EntityBatch) context.Context
- func WithOrchestration(ctx context.Context, orchestration *Orchestration) context.Context
- type Activity
- type ClientTracer
- type EntityBatch
- type IDGenerator
- type Orchestration
- func (o *Orchestration) ConfirmEntitySignal(eventID int32, replaying bool)
- func (o *Orchestration) ConfirmSendEvent(eventID int32, replaying bool)
- func (o *Orchestration) Emit(response *protos.OrchestratorResponse)
- func (o *Orchestration) Enabled() bool
- func (o *Orchestration) Observe(event *protos.HistoryEvent, replaying bool)
- func (o *Orchestration) PrepareResponse(response *protos.OrchestratorResponse)
- func (o *Orchestration) RecordEntitySignal(action *protos.OrchestratorAction, id api.EntityID, replaying bool)
- func (o *Orchestration) RecordSendEvent(action *protos.OrchestratorAction, replaying bool)
- func (o *Orchestration) SpanContext() trace.SpanContext
- type Sampler
- type Tracer
- func (t *Tracer) NewActivity(name, version, instanceID string, taskID int32, parent *protos.TraceContext) *Activity
- func (t *Tracer) NewEntityBatch(id api.EntityID, request *protos.EntityBatchRequest) *EntityBatch
- func (t *Tracer) StartOrchestration(instanceID string, persisted *protos.OrchestrationTraceContext, ...) *Orchestration
Constants ¶
const ( AttrType = attribute.Key("durabletask.type") AttrName = attribute.Key("durabletask.task.name") AttrVersion = attribute.Key("durabletask.task.version") AttrInstanceID = attribute.Key("durabletask.task.instance_id") AttrExecutionID = attribute.Key("durabletask.task.execution_id") AttrStatus = attribute.Key("durabletask.task.status") AttrTaskID = attribute.Key("durabletask.task.task_id") AttrFireAt = attribute.Key("durabletask.fire_at") )
Attribute keys shared with the other Durable Task SDKs.
const ( // AttrOperation is DurableTask.Core's entity request kind: "call_entity" // or "signal_entity". AttrOperation = attribute.Key("durabletask.task.operation") // AttrEntityOperation is the entity operation name, as reported by the // Python and JavaScript SDKs. AttrEntityOperation = attribute.Key("durabletask.entity.operation") // AttrScheduledTime is the RFC 3339 delivery time of a scheduled entity // request. AttrScheduledTime = attribute.Key("durabletask.task.scheduled_time") // AttrEntityError is the failure message of a failed entity operation. AttrEntityError = attribute.Key("durabletask.entity.error_message") )
Entity attribute keys shared with the other Durable Task SDKs.
const AttrEventTargetInstanceID = attribute.Key("durabletask.event.target_instance_id")
AttrEventTargetInstanceID identifies the orchestration that receives an event.
const ScopeName = "Microsoft.DurableTask"
ScopeName is the instrumentation scope name, matching the Durable Task .NET, JavaScript, and Java SDKs.
Variables ¶
var ErrUnsupportedTracerProvider = errors.New(
"durabletask tracing requires an OpenTelemetry SDK tracer provider configured with " +
"tracing.WithIDGenerator and tracing.WithSampler")
ErrUnsupportedTracerProvider reports a provider that cannot reconstruct spans with persisted IDs and sampling decisions, which would otherwise export a disconnected span tree.
Functions ¶
func EndClientSpan ¶
EndClientSpan records err, if any, and ends span.
func EntityOperationSpanContext ¶
EntityOperationSpanContext returns the reserved, non-recording span context of the operation at index in the batch attached to ctx. It returns an invalid span context when tracing is disabled or requestID does not match.
func RandomSpanID ¶
RandomSpanID returns a non-zero random span ID.
func RandomTraceID ¶
RandomTraceID returns a non-zero random trace ID.
func StartActivitySpan ¶
StartActivitySpan starts the span of the activity trace attached to ctx and returns ctx with that span active, so application spans nest under it.
func WithActivity ¶
WithActivity attaches an activity trace to an executor call.
func WithEntityBatch ¶
func WithEntityBatch(ctx context.Context, batch *EntityBatch) context.Context
WithEntityBatch attaches an entity batch trace to an executor call.
func WithOrchestration ¶
func WithOrchestration(ctx context.Context, orchestration *Orchestration) context.Context
WithOrchestration attaches an orchestration trace to an executor call.
Types ¶
type Activity ¶
type Activity struct {
// contains filtered or unexported fields
}
Activity holds the trace state of one activity work item. Its SERVER span starts only when the executor is about to produce a result, so work the executor rejects back to the backend exports nothing.
func (*Activity) End ¶
func (a *Activity) End(result *protos.HistoryEvent, err error)
End ends the activity span with the executor's outcome. Delivering that outcome to the backend is transport work and does not change the span. Durable failures are reported as errors even though the executor returns them as failure events without a Go error.
type ClientTracer ¶
type ClientTracer struct {
// contains filtered or unexported fields
}
ClientTracer emits live client PRODUCER spans. Unlike Tracer it never reconstructs spans, so any provider is accepted.
func NewClientTracer ¶
func NewClientTracer(provider trace.TracerProvider) *ClientTracer
NewClientTracer returns nil for a nil provider, which disables client spans.
func (*ClientTracer) StartCreateOrchestration ¶
func (t *ClientTracer) StartCreateOrchestration( ctx context.Context, name, version, instanceID, executionID string, ) (context.Context, trace.Span)
StartCreateOrchestration starts the PRODUCER span for scheduling an orchestration as a child of the span in ctx. The returned context carries the new span so it becomes the orchestration's parent trace context. An empty executionID, the usual case, omits the execution ID attribute.
func (*ClientTracer) StartRaiseEvent ¶
func (t *ClientTracer) StartRaiseEvent(ctx context.Context, eventName, instanceID string) (context.Context, trace.Span)
StartRaiseEvent starts the PRODUCER span for raising an event to an orchestration as a child of the span in ctx.
type EntityBatch ¶
type EntityBatch struct {
// contains filtered or unexported fields
}
EntityBatch holds the span identities reserved for one V2 entity batch. V2 entity messages carry no trace context, so every operation span is an independent root. Its identity and sampling decision are reserved before execution so handlers can see it, and the span is reconstructed only after the backend accepts the batch result.
func (*EntityBatch) Emit ¶
func (b *EntityBatch) Emit(result *protos.EntityBatchResult, start, end time.Time)
Emit exports the reserved operation spans. Call it only after the backend accepts result, so rejected or abandoned batches export nothing. start and end bound operations whose result has no timestamps. Dropped operations record nothing.
type IDGenerator ¶
type IDGenerator struct {
Base sdktrace.IDGenerator
}
IDGenerator wraps an application ID generator so the SDK can reconstruct spans with persisted IDs. Ordinary spans always use the base generator.
type Orchestration ¶
type Orchestration struct {
// contains filtered or unexported fields
}
Orchestration holds one dispatch's replay-aware trace state. The logical orchestration span is never live: its persisted identity is restored on each dispatch and the span is reconstructed only when the execution completes.
func OrchestrationFromContext ¶
func OrchestrationFromContext(ctx context.Context) *Orchestration
OrchestrationFromContext returns the orchestration trace for an executor call.
func (*Orchestration) ConfirmEntitySignal ¶
func (o *Orchestration) ConfirmEntitySignal(eventID int32, replaying bool)
ConfirmEntitySignal queues a signal consumed in the same dispatch only after the replay engine validates its action/history match.
func (*Orchestration) ConfirmSendEvent ¶
func (o *Orchestration) ConfirmSendEvent(eventID int32, replaying bool)
ConfirmSendEvent queues a send only after the replay engine validates its history match. An acknowledgement of a send from an earlier dispatch emits nothing: that send was already exported with its accepted response.
func (*Orchestration) Emit ¶
func (o *Orchestration) Emit(response *protos.OrchestratorResponse)
Emit exports spans for a response the backend accepted. Call it only after the completion succeeds so abandoned work never exports telemetry. Only the first call exports; later calls do nothing.
func (*Orchestration) Enabled ¶
func (o *Orchestration) Enabled() bool
Enabled reports whether this dispatch belongs to a traceable execution.
func (*Orchestration) Observe ¶
func (o *Orchestration) Observe(event *protos.HistoryEvent, replaying bool)
Observe records one consumed history event. Completions consumed as new queue a reconstructed span; replayed completions only drop correlation.
func (*Orchestration) PrepareResponse ¶
func (o *Orchestration) PrepareResponse(response *protos.OrchestratorResponse)
PrepareResponse persists the orchestration span identity on response and assigns scheduling span IDs to new activity and sub-orchestration actions. Continue-as-new and rewind responses carry a fresh identity so the next execution never reuses this execution's span.
func (*Orchestration) RecordEntitySignal ¶
func (o *Orchestration) RecordEntitySignal(action *protos.OrchestratorAction, id api.EntityID, replaying bool)
RecordEntitySignal records a signal action. Each signal exports one PRODUCER span with the accepted response that first carries or consumes it, following the same rules as event sends (see eventSpan):
- A new signal still in the response exports with that response.
- A new signal whose acknowledgement is consumed in the same dispatch is queued by ConfirmEntitySignal and exports with the response. DTS normally delivers the acknowledgement as a past event of a later dispatch, so this is defensive and best effort: the acknowledgement proves an earlier response carrying the signal was accepted, and the span exports twice if the worker that sent it also exported it.
- A signal issued while replaying exports only if it is still in the response and no acknowledgement with its ID and request ID appears in the request. A buffered event can create a new action while the replay engine still reports replaying, and a turn budget can defer an acknowledgement, so the request rather than the replay flag decides.
func (*Orchestration) RecordSendEvent ¶
func (o *Orchestration) RecordSendEvent(action *protos.OrchestratorAction, replaying bool)
RecordSendEvent creates the span for a send made outside replay, timestamped when the orchestrator sends the event. The span is exported only if the dispatch's response is accepted.
func (*Orchestration) SpanContext ¶
func (o *Orchestration) SpanContext() trace.SpanContext
SpanContext returns the non-recording logical orchestration span context. An execution scheduled with trace context joins that trace. Otherwise the orchestration is the root of its own trace, whose ID is derived from the persisted span identity so every dispatch and worker agrees on it.
type Sampler ¶
Sampler wraps an application sampler so the SDK can learn a reconstructed root span's sampling decision without starting a recording span, and can reconstruct that span later with the same decision.
func (Sampler) Description ¶
Description implements sdktrace.Sampler.
func (Sampler) ShouldSample ¶
func (s Sampler) ShouldSample(parameters sdktrace.SamplingParameters) sdktrace.SamplingResult
ShouldSample implements sdktrace.Sampler. Sampling queries record the base decision without recording a span; reconstruction can reuse that decision.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer emits Durable Task spans through a validated tracer provider.
func NewTracer ¶
func NewTracer(provider trace.TracerProvider) (*Tracer, error)
NewTracer validates that provider honors persisted span IDs and answers sampling queries.
func (*Tracer) NewActivity ¶
func (t *Tracer) NewActivity( name, version, instanceID string, taskID int32, parent *protos.TraceContext, ) *Activity
NewActivity prepares the SERVER span for one activity work item, parented by the persisted scheduling span. It returns nil when parent is unusable.
func (*Tracer) NewEntityBatch ¶
func (t *Tracer) NewEntityBatch(id api.EntityID, request *protos.EntityBatchRequest) *EntityBatch
NewEntityBatch reserves a root span context for each operation in request.
func (*Tracer) StartOrchestration ¶
func (t *Tracer) StartOrchestration( instanceID string, persisted *protos.OrchestrationTraceContext, eventLists ...[]*protos.HistoryEvent, ) *Orchestration
StartOrchestration restores the persisted orchestration span identity, or reserves one on the first dispatch of an execution. A rewind that carries a new parent trace context reparents the orchestration, as in the .NET SDK.