Context propagation on signals in go

I notice that signals use propagators in the same way that an activity/ workflow does. I also notice that I can use these values in the HandleSignal interceptor.
What I am unsure of is how I would propagate this into the context of my workflow as a receive function won’t return a new context. I could use the interceptor to place the relevant context into value that is being received, just wondering if there is a way that is more like how a workflow/ activity would do it?

Just bumping this one. For context what I am trying to do is propage a open telemetry trace via a signal so that a signal to a workflow changes its current trace id. Maybe I don’t need to propage context for this and can handle it in the interceptor for signals?

Signals are not associated with contexts, so you cannot use signal-specific contexts to propagate data to the workflow. You can have a mutable struct on the outer context that you mutate in a signal handler. Or you can change the signal value in the handler with some additional extracted-from-context info.

I am not following this exactly, but if you need to have a signal do something in your workflow, do it explicitly not implicitly. If you have an “update-trace-id” signal, handle that in your workflow and do what is necessary. But I am not sure what you mean by “changes its current trace id”.

That makes sense, thanks.

To clarify the use case, we have a long running workflow where API requests will in turn result in signals into the workflow. Currently the workflow will have a single trace with a trace id that is propagated to it from the initial API request to start it. What we were considering was for each signal to pass in the trace id, so that workflow actions taken after that signal would be associated with the trace id passed in by the signal.

We can pass through the trace id from the API call in the signal payload easy enough. However what’s not clear is how to fork the workflow.Context so it has the passed in trace id rather than the original trace id that was used when the workflow was started. ie see TODO below.

if myPassedInTraceId != nil {
	// we set SpanContextKey in the interceptor to opentelemetry.ContextKeyOtelSpan earlier
	if span, ok := ctx.Value(opentelemetry.ContextKeyOtelSpan).(trace.Span); ok {
		spanCtx := span.SpanContext()
		tId, err := trace.TraceIDFromHex(*myPassedInTraceId)
		if err == nil {
			spanCtx = spanCtx.WithTraceID(tId)
			logger.Info("Overriding context key with custom context value")
			spanWithNewTraceId := //TODO
			ctx = workflow.WithValue(ctx, opentelemetry.ContextKeyOtelSpan, spanWithNewTraceId)
		}
	}
}