SkyAPM / go2sky

Distributed tracing and monitor SDK in Go for Apache SkyWalking APM
https://skywalking.apache.org/
Apache License 2.0
448 stars 122 forks source link

Is Go2sky can build relationship between two process #56

Closed NilChow closed 4 years ago

NilChow commented 4 years ago

I'm trying to monitor this, for example, Service A calling a method from Service B(just like RPC). And I create Tracer and Span in both of them. I can only build relationship between two spans from one process. How can I build the relationship between two spans from different process. In one process, I build relationship like this: ` span1, ctx, err := tracer.CreateEntrySpan(context.Background(), "/API/Login", func() (string, error) { return "", nil })

...

span2, err := tracer.CreateExitSpan(ctx, "Service/OnLogin", "client_1", func(header string) error { return nil }) `

I'm already read some documents, and I think it should be done by span's context. But how can I reach it, is it a possible thing? Expect for your reply!

wu-sheng commented 4 years ago

When you create exit span, you could have the ContextCarrier, inject it into your RPC header. Take a look of existing plugin, you will have the clue.

NilChow commented 4 years ago

When you create exit span, you could have the ContextCarrier, inject it into your RPC header. Take a look of existing plugin, you will have the clue.

My code is like this:

client.go:
span1, err := tracer.CreateExitSpan(ctx1, "/API/Login", peer, func(header string) error {return nil})

server.go:
span2, err := tracer.CreateEntrySpan(ctx2, "Service/Login", func() (string, error) {return "", nil})

How could I build relationship between span1 and span2 from different process. Use span1's context as ctx2? Or do something in Injector and Extractor. And about the ContextCarrier you mentioned, I can't find any information about it in source code of Go2sky, but find some in OpenTracing. Can I use it in my code?

wu-sheng commented 4 years ago

The document is very clear at the doc, do you miss this? https://github.com/SkyAPM/go2sky#crossing-process

And things in the other plugin, https://github.com/SkyAPM/go2sky/blob/master/plugins/http/client.go#L95-L98.

Please read the document and codes.

NilChow commented 4 years ago

The document is very clear at the doc, do you miss this? https://github.com/SkyAPM/go2sky#crossing-process

And things in the other plugin, https://github.com/SkyAPM/go2sky/blob/master/plugins/http/client.go#L95-L98.

Please read the document and codes.

Very sorry to ask again, I am confused now. I have read both of them before, but it's a rpc calling in my code, not the http. So there is no http.Request in my code, I can't Set and Get the header. And I can't get the req.Context() either.

image

wu-sheng commented 4 years ago

That based on your RPC, you need find a way to propagate the information across the network, anyway your want. Otherwise, no topology.

NilChow commented 4 years ago

Oh I got it, I should to propagate the information by RPC request, and then provide Set and Get mythod by myself, just like the r.Header.Get() and r.Header.Set(). Now it's work, thanks so much for your help.