Skip to content

Commit 2b0ada2

Browse files
committed
Instrument client for tracing
1 parent 11e8612 commit 2b0ada2

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

client/client.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,22 @@ func (c *client) CreateWorkflowInstance(ctx context.Context, options WorkflowIns
102102
}
103103

104104
func (c *client) CancelWorkflowInstance(ctx context.Context, instance *workflow.Instance) error {
105+
ctx, span := c.backend.Tracer().Start(ctx, "CancelWorkflowInstance", trace.WithAttributes(
106+
attribute.String(log.InstanceIDKey, instance.InstanceID),
107+
))
108+
defer span.End()
109+
105110
cancellationEvent := history.NewWorkflowCancellationEvent(time.Now())
106111
return c.backend.CancelWorkflowInstance(ctx, instance, cancellationEvent)
107112
}
108113

109114
func (c *client) SignalWorkflow(ctx context.Context, instanceID string, name string, arg interface{}) error {
115+
ctx, span := c.backend.Tracer().Start(ctx, "SignalWorkflow", trace.WithAttributes(
116+
attribute.String(log.InstanceIDKey, instanceID),
117+
attribute.String(log.SignalNameKey, name),
118+
))
119+
defer span.End()
120+
110121
input, err := c.backend.Converter().To(arg)
111122
if err != nil {
112123
return fmt.Errorf("converting arguments: %w", err)
@@ -136,6 +147,11 @@ func (c *client) WaitForWorkflowInstance(ctx context.Context, instance *workflow
136147
timeout = time.Second * 20
137148
}
138149

150+
ctx, span := c.backend.Tracer().Start(ctx, "WaitForWorkflowInstance", trace.WithAttributes(
151+
attribute.String(log.InstanceIDKey, instance.InstanceID),
152+
))
153+
defer span.End()
154+
139155
b := backoff.ExponentialBackOff{
140156
InitialInterval: time.Millisecond * 1,
141157
MaxInterval: time.Second * 1,
@@ -167,13 +183,18 @@ func (c *client) WaitForWorkflowInstance(ctx context.Context, instance *workflow
167183
// GetWorkflowResult gets the workflow result for the given workflow result. It first waits for the workflow to finish or until
168184
// the given timeout has expired.
169185
func GetWorkflowResult[T any](ctx context.Context, c Client, instance *workflow.Instance, timeout time.Duration) (T, error) {
186+
ic := c.(*client)
187+
b := ic.backend
188+
189+
ctx, span := b.Tracer().Start(ctx, "GetWorkflowResult", trace.WithAttributes(
190+
attribute.String(log.InstanceIDKey, instance.InstanceID),
191+
))
192+
defer span.End()
193+
170194
if err := c.WaitForWorkflowInstance(ctx, instance, timeout); err != nil {
171195
return *new(T), fmt.Errorf("workflow did not finish in time: %w", err)
172196
}
173197

174-
ic := c.(*client)
175-
b := ic.backend
176-
177198
h, err := b.GetWorkflowInstanceHistory(ctx, instance, nil)
178199
if err != nil {
179200
return *new(T), fmt.Errorf("getting workflow history: %w", err)
@@ -208,5 +229,10 @@ func GetWorkflowResult[T any](ctx context.Context, c Client, instance *workflow.
208229
}
209230

210231
func (c *client) RemoveWorkflowInstance(ctx context.Context, instance *core.WorkflowInstance) error {
232+
ctx, span := c.backend.Tracer().Start(ctx, "RemoveWorkflowInstance", trace.WithAttributes(
233+
attribute.String(log.InstanceIDKey, instance.InstanceID),
234+
))
235+
defer span.End()
236+
211237
return c.backend.RemoveWorkflowInstance(ctx, instance)
212238
}

0 commit comments

Comments
 (0)