Skip to content

Commit

Permalink
Support trace logger in workflows & activities (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlegrone authored Feb 7, 2022
1 parent 5773685 commit b5ba1d3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion interceptor/tracing_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"fmt"

commonpb "go.temporal.io/api/common/v1"

"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/converter"
Expand Down Expand Up @@ -290,11 +291,29 @@ func (t *tracingClientOutboundInterceptor) QueryWorkflow(
return val, err
}

type tracingActivityOutboundInterceptor struct {
ActivityOutboundInterceptorBase
root *tracingInterceptor
}

func (t *tracingActivityOutboundInterceptor) GetLogger(ctx context.Context) log.Logger {
if span := t.root.tracer.SpanFromContext(ctx); span != nil {
return t.root.tracer.GetLogger(t.Next.GetLogger(ctx), span)
}
return t.Next.GetLogger(ctx)
}

type tracingActivityInboundInterceptor struct {
ActivityInboundInterceptorBase
root *tracingInterceptor
}

func (t *tracingActivityInboundInterceptor) Init(outbound ActivityOutboundInterceptor) error {
i := &tracingActivityOutboundInterceptor{root: t.root}
i.Next = outbound
return t.Next.Init(i)
}

func (t *tracingActivityInboundInterceptor) ExecuteActivity(
ctx context.Context,
in *ExecuteActivityInput,
Expand Down Expand Up @@ -453,7 +472,7 @@ func (t *tracingWorkflowOutboundInterceptor) ExecuteLocalActivity(

func (t *tracingWorkflowOutboundInterceptor) GetLogger(ctx workflow.Context) log.Logger {
if span, _ := ctx.Value(t.root.options.SpanContextKey).(TracerSpan); span != nil {
t.root.tracer.GetLogger(t.Next.GetLogger(ctx), span)
return t.root.tracer.GetLogger(t.Next.GetLogger(ctx), span)
}
return t.Next.GetLogger(ctx)
}
Expand Down

0 comments on commit b5ba1d3

Please sign in to comment.