yurishkuro / opentracing-tutorial

A collection of tutorials for the OpenTracing API
Apache License 2.0
1.57k stars 404 forks source link

Tracing async goroutine and child daemon process #40

Open etsangsplk opened 5 years ago

etsangsplk commented 5 years ago

Trace is by itself a directional acrylic graph of spans. But if I have a main processes that spawns off a goroutine that periodic pull data from say AWS? The main program sends the goroutine the target ID via a channel; and the goroutine reports the result back via a channel. How can I trace that from main? But the childspans started within the goroutine never close unless interrupted or errored out.

yurishkuro commented 5 years ago

From your description it is not clear to me what problem you're having, esp. the child spans never closing. I suggest thinking about your app flow in terms of operations and model them with spans. Each operation has a start and end points dictating the life cycle of the spans. Then think about relationships between operations: what causes what and what depends on the outcome of another op. Model those with span references. You should not need a tracing system to tell you the flow (the DAG) of your own app within one process.

As far as passing the references, the current span is stored on the Context. If you're communicating internally via channels, you should pass a struct that contains the Context in addition to your custom payload.

etsangsplk commented 5 years ago

Specifically I have Process A that spwans goroutine B that runs in a loop. Process A the S3 bucketname from user and communicate To B. ProcessA will wait for B to exit. B runs in a loop uses the Bucket name to continuously fetch data under that bucket and send to result back to A. For tracing, I can model the top parent span in Process A and B can create its own span as a child of A. But since A waits for B to.exit it's span won't close. I am wondering if you have any pointer for this

yurishkuro commented 5 years ago

Why wouldn't A close after B exits? Or do you mean that this is a continuously running process. If so, why do you need to keep relationships between A span and B spans?

yurishkuro commented 5 years ago

Also, you said A gets an input from user, does it provide any response back?

etsangsplk commented 5 years ago

A does not provides response back to user but write to a log entry. B is continuous will call AWS on a set interval. Was thinking about to use tracing to track when user tells A which bucket to process data, how that request go though B to AWS, "process the item (can be multistep)"and get the result back, in order to see if there are any steps from A to B that can be optimize. But as you said this is not a DAG.