Skip to content

Commit

Permalink
Change APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Nov 20, 2020
1 parent 1d50851 commit c686a62
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 78 deletions.
8 changes: 0 additions & 8 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ def get_current_hub
Thread.current[THREAD_LOCAL] || clone_hub_to_current_thread
end

def get_transaction
get_current_hub.get_transaction
end

def clone_hub_to_current_thread
Thread.current[THREAD_LOCAL] = get_main_hub.clone
end
Expand Down Expand Up @@ -99,10 +95,6 @@ def capture_message(message, **options, &block)
get_current_hub.capture_message(message, **options, &block)
end

def start_span(**options)
get_current_hub.start_span(**options)
end

def start_transaction(**options)
get_current_hub.start_transaction(**options)
end
Expand Down
12 changes: 0 additions & 12 deletions sentry-ruby/lib/sentry/hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ def pop_scope
@stack.pop
end

def get_transaction
current_scope.span
end

def start_span(**options)
if span = current_scope.span
span.start_child(**options)
else
Span.new(**options)
end
end

def start_transaction(transaction: nil, **options)
transaction ||= Transaction.new(**options, sampled: true)
# TODO: Add sampling logic
Expand Down
14 changes: 10 additions & 4 deletions sentry-ruby/lib/sentry/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ def set_span(span)
@span = span
end

def get_span
@span
end

def set_user(user_hash)
check_argument_type!(user_hash, Hash)
@user = user_hash
Expand Down Expand Up @@ -146,6 +142,15 @@ def transaction_name
@transaction_names.last
end

def get_transaction
# transaction will always be the first in the span_recorder
span.span_recorder.spans.first if span
end

def get_span
span
end

def set_fingerprint(fingerprint)
check_argument_type!(fingerprint, Array)

Expand Down Expand Up @@ -180,6 +185,7 @@ def set_default_value
@transaction_names = []
@event_processors = []
@rack_env = {}
@span = nil
end

class << self
Expand Down
40 changes: 0 additions & 40 deletions sentry-ruby/spec/sentry/hub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,46 +137,6 @@
end
end

describe "#start_span" do
it "initializes a new span object" do
span = subject.start_span(op: "foo")

expect(span).to be_a(Sentry::Span)
expect(span.op).to eq("foo")
end

context "already has a span in scope" do
let(:span) do
subject.start_span(op: "foo")
end

before do
subject.current_scope.set_span(span)
end

it "starts a child span of the current span" do
child_span = subject.start_span(op: "bar")

expect(child_span.op).to eq("bar")
expect(child_span.parent_span_id).to eq(span.span_id)
end
end
end

describe "#get_transaction" do
let(:span) do
subject.start_span(op: "foo")
end

before do
subject.current_scope.set_span(span)
end

it "gets the transaction/span stored in the current scope" do
expect(subject.get_transaction).to eq(span)
end
end

describe "#with_scope" do
it "builds a temporary scope" do
inner_event = nil
Expand Down
36 changes: 36 additions & 0 deletions sentry-ruby/spec/sentry/scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
scope.set_extras({additional_info: "hello"})
scope.set_user({id: 1})
scope.set_transaction_name("WelcomeController#index")
scope.set_span(Sentry::Span.new)
scope.set_fingerprint(["foo"])
scope
end
Expand All @@ -102,6 +103,41 @@
expect(subject.user).to eq({})
expect(subject.fingerprint).to eq([])
expect(subject.transaction_names).to eq([])
expect(subject.span).to eq(nil)
end
end

describe "#get_transaction & #get_span" do
let(:transaction) do
Sentry::Transaction.new(op: "parent")
end

context "with span in the scope" do
let(:span) do
transaction.start_child(op: "child")
end

before do
subject.set_span(span)
end

it "gets the span from the scope" do
expect(subject.get_span).to eq(span)
end

it "gets the transaction from the span recorder" do
expect(subject.get_transaction).to eq(transaction)
end
end

context "without span in the scope" do
it "returns nil" do
expect(subject.get_transaction).to eq(nil)
end

it "returns nil" do
expect(subject.get_span).to eq(nil)
end
end
end

Expand Down
14 changes: 0 additions & 14 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,6 @@
end
end

describe ".get_transaction" do
let(:transaction) { described_class.start_transaction }

before do
described_class.configure_scope do |scope|
scope.set_span(transaction)
end
end

it "gets the current transaction" do
expect(described_class.get_transaction).to eq(transaction)
end
end

describe ".capture_message" do
it "sends the message via current hub" do
expect(described_class.get_current_hub).to receive(:capture_message).with("Test", tags: { foo: "baz" })
Expand Down

0 comments on commit c686a62

Please sign in to comment.