In Lesson 3 we have seen how span context is propagated over the wire between different applications. It is not hard to see that this process can be generalized to propagating more than just the tracing context. With OpenTracing instrumentation in place, we can support general purpose distributed context propagation where we associate some metadata with the transaction and make that metadata available anywhere in the distributed call graph. In OpenTracing this metadata is called baggage, to highlight the fact that it is carried over in-band with all RPC requests, just like baggage.
We'll start this lesson where we stopped in lesson 3.
The formatter
service takes the helloTo
parameter and returns a string Hello, {helloTo}!
. Let's modify it so that we can customize the greeting too, but without modifying the public API of that service.
This scenario is based on the OpenTracing tutorial located at https://github.com/yurishkuro/opentracing-tutorial
This concludes our OpenTracing tutorial. Make sure to check out the OpenTracing documentation and join our community!

Steps
OpenTracing Tutorial - Lesson 4
Set Baggage in the Client
We'll start this lesson where we left the previous one. We are providing the Publisher
and the RequestBuilderCarrier
on the workspace, as there's no need to change anything on them during this lesson, but refer to the previous versions of the Hello
client and Formatter
when working on this lesson.
Let's add a new parameter to our Hello's main method, so that it accepts a greeting
in addition to a name. This is how the main method would look like in the end:
public static void main(String[] args) { if (args.length != 2) { throw new IllegalArgumentException("Expecting two arguments, helloTo and greeting"); } String helloTo = args[0]; String greeting = args[1]; Tracer tracer = Tracing.init("hello-world"); new Hello(tracer).sayHello(helloTo, greeting); }
Don't forget to change the signature of the method sayHello()
to accept this new parameter:
private void sayHello(String helloTo, String greeting) {
And add this instruction to sayHello
method after starting the span:
scope.span().setBaggageItem("greeting", greeting);
By doing this we read a second command line argument as a "greeting" and store it in the baggage under "greeting"
key.
You’ll love Katacoda

Guided Path
Knowing what you need to know is the hardest part. Our guided pathways help build your knowledge around real-world scenarios.

Learn By Doing
The best way to learn is by doing. All our tutorials are interactive with pre-configured live environments ready for you to use.

Stay up-to-date
It's a competitive industry. Your skills need to keep up with the latest approaches. Katacoda keeps your skills up-to-date.
You’ll love Katacoda

Guided Path
Knowing what you need to know is the hardest part. Our guided pathways help build your knowledge around real-world scenarios.

Learn By Doing
The best way to learn is by doing. All our tutorials are interactive with pre-configured live environments ready for you to use.

Stay up-to-date
It's a competitive industry. Your skills need to keep up with the latest approaches. Katacoda keeps your skills up-to-date.