Skip to content

Commit

Permalink
fix: Fix a bug breaking all span tags
Browse files Browse the repository at this point in the history
Somehow I brain-farted and mixed up if and unless, and then also didn't
run the test suite which would've told me that this isn't working.

Also adding more test coverage in this, just to be safe.
  • Loading branch information
sulami committed Dec 10, 2024
1 parent 927556c commit 831ae03
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/degica_datadog/tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ def error!(e)

# Returns the current span.
def current_span
Datadog::Tracing.active_span unless Config.enabled?
Datadog::Tracing.active_span if Config.enabled?
end

# Returns the current root span. Root here meaning within the service, not necessarily the
# actual trace root span if that is from a different service.
def root_span
# forgive me my friends
Datadog::Tracing.active_trace.instance_variable_get(:@root_span) unless Config.enabled?
Datadog::Tracing.active_trace.instance_variable_get(:@root_span) if Config.enabled?
end

# Please don't use this. It's just a temporary thing until we can get the
Expand Down
32 changes: 32 additions & 0 deletions spec/tracing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@
end
end

describe ".current_span" do
it "does nothing when disabled" do
allow(DegicaDatadog::Config).to receive(:enabled?).and_return(false)
described_class.span!("test") do
expect(described_class.current_span).to be_nil
end
end

it "returns the current span" do
allow(DegicaDatadog::Config).to receive(:enabled?).and_return(true)
described_class.span!("test") do
expect(described_class.current_span).to_not be_nil
end
end
end

describe ".root_span" do
it "does nothing when disabled" do
allow(DegicaDatadog::Config).to receive(:enabled?).and_return(false)
described_class.span!("test") do
expect(described_class.root_span).to be_nil
end
end

it "returns the current span" do
allow(DegicaDatadog::Config).to receive(:enabled?).and_return(true)
described_class.span!("test") do
expect(described_class.root_span).to_not be_nil
end
end
end

describe ".span!" do
it "starts a new span" do
expect { described_class.span!("test") }.to change { Datadog::Tracing.active_span }.from(nil)
Expand Down

0 comments on commit 831ae03

Please sign in to comment.