Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

root spans are not recorded with trace_id_ratio_based #262

Closed
dvic opened this issue Aug 5, 2021 · 2 comments · Fixed by #263
Closed

root spans are not recorded with trace_id_ratio_based #262

dvic opened this issue Aug 5, 2021 · 2 comments · Fixed by #263

Comments

@dvic
Copy link
Contributor

dvic commented Aug 5, 2021

I'm not sure what should be done here but this doesn't seem right does it?

trace_id_ratio_based_sampler(_Config) ->
    Tracer = opentelemetry:get_tracer(),

    Sampler1 = otel_sampler:setup(always_on),

    %% this succeeds
    SpanCtx1 = otel_tracer:start_span(Tracer, <<"span-1">>, #{sampler => Sampler1}),
    ?assertMatch(true, SpanCtx1#span_ctx.is_recording),

    Sampler2 = otel_sampler:setup({trace_id_ratio_based, 1.0}),

    %% this fails
    SpanCtx2 = otel_tracer:start_span(Tracer, <<"span-1">>, #{sampler => Sampler2}),
    ?assertMatch(true, SpanCtx2#span_ctx.is_recording),

    ok.

It's because ParentTraceId = trace_id(Ctx), is undefined (in otel_span_utils), and that's because start_span inside opentelemetry/otel_tracer:

start_span(Tracer={Module, _}, Name, Opts) ->
    Module:start_span(otel_ctx:get_current(), Tracer, Name, Opts).

in which otel_ctx:get_current() here returns #{}.

@dvic
Copy link
Contributor Author

dvic commented Aug 5, 2021

The test case above can be dropped inside opentelemetry_SUITE.erl and run with rebar3 ct --suite apps/opentelemetry/test/opentelemetry_SUITE.erl --case trace_id_ratio_based_sampler

@dvic
Copy link
Contributor Author

dvic commented Aug 5, 2021

if I move (all in otel_span_utils)

{NewSpanCtx, ParentSpanId} = new_span_ctx(Ctx),

to the top

and use

ParentTraceId = trace_id(NewSpanCtx),

and

trace_id(Ctx) ->
    case Ctx of
        #span_ctx{trace_id = TraceId} ->
            TraceId;
        _ ->
            undefined
    end.

then all tests pass (including the one in this issue).

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

Successfully merging a pull request may close this issue.

1 participant