Replies: 2 comments 3 replies
-
Hi, How about passing a struct to your channel? It can then contain a context. Something like this (untested): type msg struct {
ctx context.Context
val int
}
var (
cha = make(chan msg, 10)
chb = make(chan msg, 10)
)
func (a *moduleA) run(cha chan int) {
for {
select {
case data := <-cha:
ctx, span := tracer.Start(data.ctx, "moduleA")
// doSomeTask
chb <- msg{ctx, 2 * num}
// doSomeTask
span.End()
}
}
}
func (a *moduleB) run(chb chan int) {
for {
select {
case data := <-chb:
ctx, span := tracer.Start(data.ctx, "moduleB")
// doSomeTask
time.Sleep(time.Second * 10)
span.End()
}
}
}
func main() {
exit := make(chan struct{}, 1)
modA := &moduleA{}
modB := &moduleB{}
go modA.run(cha)
go modB.run(chb)
cha <- msg{context.Background(), 1} // push msg to queue cha
<-exit
} |
Beta Was this translation helpful? Give feedback.
3 replies
-
HI, I also had this question. Given the stricture against storing contexts on structs (though violated by go stdlib itself), I thought something like the following: // Spanned is a message that includes a span context
type Spanned[T any] struct {
Span trace.SpanContext
T T
} then again, it seems like a bit of a weird situation, since my parent span will end after successfully pushing to the channel, as opposed to after the child function call has ended. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Scene Call In Gorutinues
“modB.run” groutinue is driven by channel chb and In "modA.run" goroutinue we put a message to chb.Is there any way to handle this situation when we tracing go program:
Beta Was this translation helpful? Give feedback.
All reactions