Skip to content

Commit

Permalink
[CLI] fix incorrect propagation of span context in start workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shijiesheng committed Oct 15, 2024
1 parent 084464e commit c49bd26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions tools/cli/workflow_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,15 @@ func processHeader(c *cli.Context) (map[string][]byte, error) {
headers := mapFromKeysValues(headerKeys, headerValues)
// append context headers if exist
if span := opentracing.SpanFromContext(c.Context); span != nil && span.Context() != nil {
span.Context().ForeachBaggageItem(func(k, v string) bool {
spanHeaders := make(map[string]string)
if err := span.Tracer().Inject(span.Context(), opentracing.TextMap, opentracing.TextMapCarrier(spanHeaders)); err != nil {
return nil, fmt.Errorf("error in inject span context: %w", err)
}
for k, v := range spanHeaders {
if _, exist := headers[k]; !exist { // append only if not exist
headers[k] = []byte(v)
}
return true
})
}
}
return headers, nil
}
Expand Down
3 changes: 2 additions & 1 deletion tools/cli/workflow_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func TestConstructStartWorkflowRequest(t *testing.T) {
assert.NotNil(t, request.WorkflowIDReusePolicy)
assert.Equal(t, int32(5), *request.DelayStartSeconds)
assert.Equal(t, int32(2), *request.JitterStartSeconds)
assert.Equal(t, map[string][]byte{"tracer-test-key": []byte("tracer-test-value")}, request.Header.Fields)
assert.Contains(t, request.Header.Fields, "mockpfx-baggage-tracer-test-key")
assert.Equal(t, []byte("tracer-test-value"), request.Header.Fields["mockpfx-baggage-tracer-test-key"])

firstRunAt, err := time.Parse(time.RFC3339, "2024-07-24T12:00:00Z")
assert.NoError(t, err)
Expand Down

0 comments on commit c49bd26

Please sign in to comment.