Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

How to set a custom Tracestate to a root span #2054

Open
HongZhaoHua opened this issue Sep 11, 2020 · 1 comment
Open

How to set a custom Tracestate to a root span #2054

HongZhaoHua opened this issue Sep 11, 2020 · 1 comment

Comments

@HongZhaoHua
Copy link

HongZhaoHua commented Sep 11, 2020

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.

@HongZhaoHua
Copy link
Author

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant