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

Add test for child span sampling issue #264

Merged
merged 3 commits into from
Aug 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test/otel_tests.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ defmodule OtelTests do
)}
end

test "child span should not be sampled if root span is not sampled" do
:otel_batch_processor.set_exporter(:otel_exporter_pid, self())
OpenTelemetry.register_tracer(:test_tracer, "0.1.0")

sampler = :otel_sampler.setup(:always_off)

Tracer.with_span "span-1", %{sampler: sampler} do
Tracer.with_span "span-2" do
Tracer.set_attribute("foo", "bar")
end
end

refute_receive {:span, span(name: "span-1")}

# The flag combination SampledFlag == true and IsRecording == false could
# cause gaps in the distributed trace, and because of this OpenTelemetry API
# MUST NOT allow this combination.
#
# source: # https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#sampling
refute_receive {:span, span(name: "span-2", trace_flags: 1, is_recording: false)}

refute_receive {:span, span(name: "span-2")}
end

test "use Tracer to start a Span as currently active with an explicit parent" do
:otel_batch_processor.set_exporter(:otel_exporter_pid, self())
OpenTelemetry.register_tracer(:test_tracer, "0.1.0")
Expand Down