opentracing / opentracing-java

OpenTracing API for Java. 🛑 This library is DEPRECATED! https://github.com/opentracing/specification/issues/163
http://opentracing.io
Apache License 2.0
1.68k stars 344 forks source link

tracing parallel jobs #360

Closed yogeshVU closed 4 years ago

yogeshVU commented 4 years ago

I have a set of distributed tasks (BSP task jar files running in separate docker containers instantiated using docker-compose up) which starts separately, but need be traced for the makespan at each synchronized barrier. Is there a way to set the parent trace id using a config file(so that all the jar files have same trace-id)? Because if they are initialized separately, each of them appear as a separate service in the Jaeger UI, and it is not possible to see the progress of all the parallel tasks in a single view.

Any suggestions how to accomplish this?

yurishkuro commented 4 years ago

It's not much different from rpc case. You need to serialize the parent context, find a way to pass it to the tasks as program argument (eg via a file or json string), then in each task deserialize it and use to start a child span.

yogeshVU commented 4 years ago

any example of how this is done ? Is there an example to serialize and save to a file? also which source file in this repo will help to create the above implementation? Thanks again

yurishkuro commented 4 years ago

If you're not familiar with using OpenTracing, you can look though https://github.com/yurishkuro/opentracing-tutorial/. Lesson 3 shows how to serialize the trace context when using RPC, but the intermediate format is just a Map, you can be creative about how to pass it in your environment.

yogeshVU commented 4 years ago

@yurishkuro thanks for the pointers and reference to the examples. I have a got a setup where I can set the traceid of a child span. I would like to know how to set the traceID of a parent trace. This is what I do for the creating a span for the child trace, where I can set the parentspanCtx manually in my case I am setting a hashmap where:

traceID=12312312312l
k="uber-trace-id", value= "traceID:traceID:0:1"

I create a child span using:

SpanContext parentSpanCtx = this.tracer.extract(Format.Builtin.TEXT_MAP, this.tracerContext);
spanBuilder = this.tracer.buildSpan(operationName).asChildOf(parentSpanCtx);

My question is how to set the traceID of the parent trace manually? Any suggestions? Thanks in advance.

Screen Shot 2019-10-15 at 12 21 37 PM
yurishkuro commented 4 years ago

trace id is generated by the tracer, OpenTracing does not provide a way to set it manually

yogeshVU commented 4 years ago

@yurishkuro , ok. But as you can see I was able to set the traceID to '1010101' manually. However this works for the child trace case using my code snippet above. I would like to set for the parent trace, and that is where I am stuck.

As I mentioned the usecase is a master Node to whom I can manually set the trace ID to goldentraceid passed as an input argument. This same goldentraceid is set as an argument to the slave nodes program.

yogeshVU commented 4 years ago

Another update:

For the rootspan the way I handled this is by using following condition:

                if (isRoot){
                    spanBuilder = this.tracer.buildSpan(operationName).addReference(References.FOLLOWS_FROM,parentSpanCtx);

                }
                else
                    spanBuilder = this.tracer.buildSpan(operationName).asChildOf(parentSpanCtx);

This way I am able to see both the spans from Master as well as the Slave node in one view. However, the root span name is showing as trace-without-root-span.

image
yogeshVU commented 4 years ago

Also, in this example I only have two parallel tasks who are executing a given operation in an iterative fashion. Is it possible to just have two spans rather than creating a new span for each iteration?

image