Skip to content

Commit fcc98ff

Browse files
authored
Merge pull request #365 from cschleiden/improve-tracing
Improve tracing
2 parents 8dee177 + 8bfa7a6 commit fcc98ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1123
-490
lines changed

.github/workflows/go.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020

2121
- name: Set up Go
22-
uses: actions/setup-go@v3
22+
uses: actions/setup-go@v5
2323
with:
24-
go-version: 1.21
24+
go-version: 1.22
2525
check-latest: true
2626
cache: true
2727

backend/history/history.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const (
5555

5656
// Recorded result of a side-efect
5757
EventType_SideEffectResult
58+
59+
// Distributed tracing span has been started
60+
EventType_TraceStarted
5861
)
5962

6063
func (et EventType) String() string {
@@ -102,6 +105,9 @@ func (et EventType) String() string {
102105
case EventType_SideEffectResult:
103106
return "SideEffectResult"
104107

108+
case EventType_TraceStarted:
109+
return "TraceStarted"
110+
105111
default:
106112
return "Unknown"
107113
}

backend/history/serialization.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func DeserializeAttributes(eventType EventType, attributes []byte) (attr interfa
5959
case EventType_SideEffectResult:
6060
attr = &SideEffectResultAttributes{}
6161

62+
case EventType_TraceStarted:
63+
attr = &TraceStartedAttributes{}
64+
6265
case EventType_TimerScheduled:
6366
attr = &TimerScheduledAttributes{}
6467
case EventType_TimerFired:

backend/history/span_started.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package history
2+
3+
import "github.com/cschleiden/go-workflows/backend/payload"
4+
5+
type TraceStartedAttributes struct {
6+
SpanID payload.Payload `json:"spanID"`
7+
}

backend/history/subworkflow_scheduled.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ type SubWorkflowScheduledAttributes struct {
1616
Inputs []payload.Payload `json:"inputs,omitempty"`
1717

1818
Metadata *metadata.WorkflowMetadata `json:"metadata,omitempty"`
19+
20+
WorkflowSpanID [8]byte `json:"workflow_span_id,omitempty"`
1921
}

backend/history/timer_fired.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package history
22

3-
import "time"
3+
import (
4+
"time"
5+
6+
"github.com/cschleiden/go-workflows/internal/tracing"
7+
)
48

59
type TimerFiredAttributes struct {
6-
At time.Time `json:"at,omitempty"`
10+
ScheduledAt time.Time `json:"scheduled_at,omitempty"`
11+
At time.Time `json:"at,omitempty"`
12+
Name string `json:"name,omitempty"`
13+
TraceContext tracing.Context `json:"span_metadata,omitempty"`
714
}

backend/history/timer_scheduled.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ package history
33
import "time"
44

55
type TimerScheduledAttributes struct {
6-
At time.Time `json:"at,omitempty"`
6+
At time.Time `json:"at,omitempty"`
7+
Name string `json:"name,omitempty"`
78
}

backend/history/workflow_started.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ type ExecutionStartedAttributes struct {
1414
Metadata *metadata.WorkflowMetadata `json:"metadata,omitempty"`
1515

1616
Inputs []payload.Payload `json:"inputs,omitempty"`
17+
18+
WorkflowSpanID [8]byte `json:"workflowSpanID,omitempty"`
1719
}

backend/options.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"github.com/cschleiden/go-workflows/backend/converter"
88
"github.com/cschleiden/go-workflows/backend/metrics"
99
mi "github.com/cschleiden/go-workflows/internal/metrics"
10-
"github.com/cschleiden/go-workflows/internal/tracing"
10+
"github.com/cschleiden/go-workflows/internal/propagators"
1111
"github.com/cschleiden/go-workflows/workflow"
1212
"go.opentelemetry.io/otel/trace"
13+
"go.opentelemetry.io/otel/trace/noop"
1314
)
1415

1516
type Options struct {
@@ -51,10 +52,10 @@ var DefaultOptions Options = Options{
5152

5253
Logger: slog.Default(),
5354
Metrics: mi.NewNoopMetricsClient(),
54-
TracerProvider: trace.NewNoopTracerProvider(),
55+
TracerProvider: noop.NewTracerProvider(),
5556
Converter: converter.DefaultConverter,
5657

57-
ContextPropagators: []workflow.ContextPropagator{&tracing.TracingContextPropagator{}},
58+
ContextPropagators: []workflow.ContextPropagator{&propagators.TracingContextPropagator{}},
5859

5960
RemoveContinuedAsNewInstances: false,
6061
}

backend/redis/instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ func (rb *redisBackend) CancelWorkflowInstance(ctx context.Context, instance *co
133133
}
134134

135135
// Cancel instance
136-
if cmds, err := rb.rdb.Pipelined(ctx, func(p redis.Pipeliner) error {
136+
if _, err := rb.rdb.Pipelined(ctx, func(p redis.Pipeliner) error {
137137
return rb.addWorkflowInstanceEventP(ctx, p, workflow.Queue(instanceState.Queue), instance, event)
138138
}); err != nil {
139-
fmt.Println(cmds)
139+
// fmt.Println(cmds)
140140
return fmt.Errorf("adding cancellation event to workflow instance: %w", err)
141141
}
142142

0 commit comments

Comments
 (0)