opencensus-java
opencensus-java copied to clipboard
How to set a custom Tracestate to a root span
I want to set a custom Tracestate to a root span.
But the api only support set a Tracestate as follow:
tracestate.set("key", "value"); SpanContext spanContext = SpanContext.create(traceId, spanId, traceOption, tracestate); Span span = tracer.spanBuilderWithRemoteParent(spanName, spanContext);
But in this way. if spanContext.isValid == true, i only can get a non root span. if spanContext.isValid == false, i will loss tracestate.
here is the code:
Tracer tracer = Tracing.getTracer();
TraceId traceId = TraceId.generateRandomId(RandomUtility.getRandom());
SpanId spanId = SpanId.generateRandomId(RandomUtility.getRandom());
TraceOptions traceOption = TraceOptions.builder().build();
Tracestate traceState = Tracestate.builder().set("userId", "xxxxx").build();
SpanContext spanContext = SpanContext.create(traceId, spanId, traceOption, traceState);
// TODO I hope get a root span, but in fact, i just get a non root span
Span span = tracer.spanBuilderWithRemoteParent("root", spanContext).startSpan();
How do I build a root span with Tracestate?