|
21 | 21 | package workflow |
22 | 22 |
|
23 | 23 | import ( |
24 | | - "fmt" |
25 | | - |
26 | 24 | "github.com/opentracing/opentracing-go" |
| 25 | + |
27 | 26 | "go.uber.org/cadence/internal" |
28 | 27 | ) |
29 | 28 |
|
@@ -100,42 +99,44 @@ func GetSpanContext(ctx Context) opentracing.SpanContext { |
100 | 99 | // This is useful to modify baggage items of current workflow and pass it to activities and child workflows. |
101 | 100 | // |
102 | 101 | // Example Usage: |
103 | | -// func goodWorkflow(ctx Context) (string, error) { |
104 | | -// // start a short lived new workflow span within SideEffect to avoid duplicate span creation during replay |
105 | | -// spanContextValue := SideEffect(ctx, func(ctx Context) interface{} { |
106 | | -// wSpan := opentracing.StartSpan("workflow-operation-with-new-span", opentracing.ChildOf(GetSpanContext(ctx))) |
107 | | -// defer wSpan.Finish() |
108 | | -// wSpan.SetTag("some-key", "some-value") |
109 | | -// return wSpan.Context() |
110 | | -// }) |
111 | | -// var spanContext opentracing.SpanContext |
112 | | -// err := spanContextValue.Get(&spanContext) |
113 | | -// if err != nil { |
114 | | -// return "",fmt.Errorf("failed to get span context: %w", err) |
115 | | -// } |
116 | | -// |
117 | | -// aCtx := WithSpanContext(ctx, spanContext) |
118 | | -// var activityFooResult string |
119 | | -// err = ExecuteActivity(aCtx, activityFoo).Get(aCtx, &activityFooResult) |
120 | | -// return activityFooResult, err |
121 | | -// } |
| 102 | +// |
| 103 | +// func goodWorkflow(ctx Context) (string, error) { |
| 104 | +// // start a short lived new workflow span within SideEffect to avoid duplicate span creation during replay |
| 105 | +// spanContextValue := SideEffect(ctx, func(ctx Context) interface{} { |
| 106 | +// wSpan := opentracing.StartSpan("workflow-operation-with-new-span", opentracing.ChildOf(GetSpanContext(ctx))) |
| 107 | +// defer wSpan.Finish() |
| 108 | +// wSpan.SetTag("some-key", "some-value") |
| 109 | +// return wSpan.Context() |
| 110 | +// }) |
| 111 | +// var spanContext opentracing.SpanContext |
| 112 | +// err := spanContextValue.Get(&spanContext) |
| 113 | +// if err != nil { |
| 114 | +// return "",fmt.Errorf("failed to get span context: %w", err) |
| 115 | +// } |
| 116 | +// |
| 117 | +// aCtx := WithSpanContext(ctx, spanContext) |
| 118 | +// var activityFooResult string |
| 119 | +// err = ExecuteActivity(aCtx, activityFoo).Get(aCtx, &activityFooResult) |
| 120 | +// return activityFooResult, err |
| 121 | +// } |
122 | 122 | // |
123 | 123 | // Bad Example: |
124 | | -// func badWorkflow(ctx Context) (string, error) { |
125 | | -// // start a new workflow span for EVERY REPLAY |
126 | | -// wSpan := opentracing.StartSpan("workflow-operation", opentracing.ChildOf(GetSpanContext(ctx))) |
127 | | -// wSpan.SetBaggageItem("some-key", "some-value") |
128 | | -// // pass the new span context to activity |
129 | | -// aCtx := WithSpanContext(ctx, wSpan.Context()) |
130 | | -// var activityFooResult string |
131 | | -// err := ExecuteActivity(aCtx, activityFoo).Get(aCtx, &activityFooResult) |
132 | | -// wSpan.Finish() |
133 | | -// return activityFooResult, err |
134 | | -// } |
135 | | -// |
136 | | -// func activityFoo(ctx Context) (string, error) { |
137 | | -// return "activity-foo-result", nil |
138 | | -// } |
| 124 | +// |
| 125 | +// func badWorkflow(ctx Context) (string, error) { |
| 126 | +// // start a new workflow span for EVERY REPLAY |
| 127 | +// wSpan := opentracing.StartSpan("workflow-operation", opentracing.ChildOf(GetSpanContext(ctx))) |
| 128 | +// wSpan.SetBaggageItem("some-key", "some-value") |
| 129 | +// // pass the new span context to activity |
| 130 | +// aCtx := WithSpanContext(ctx, wSpan.Context()) |
| 131 | +// var activityFooResult string |
| 132 | +// err := ExecuteActivity(aCtx, activityFoo).Get(aCtx, &activityFooResult) |
| 133 | +// wSpan.Finish() |
| 134 | +// return activityFooResult, err |
| 135 | +// } |
| 136 | +// |
| 137 | +// func activityFoo(ctx Context) (string, error) { |
| 138 | +// return "activity-foo-result", nil |
| 139 | +// } |
139 | 140 | func WithSpanContext(ctx Context, spanContext opentracing.SpanContext) Context { |
140 | 141 | return internal.WithSpanContext(ctx, spanContext) |
141 | 142 | } |
0 commit comments