Skip to content

Commit

Permalink
Expose optional end_timestamp argument in Span#finish and Transaction…
Browse files Browse the repository at this point in the history
…#finish
  • Loading branch information
sl0thentr0py committed Nov 22, 2022
1 parent 954d6a2 commit f2d6d71
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- Add OpenTelemetry support with new `sentry-opentelemetry` gem
- Add `config.instrumenter` to switch between sentry and otel instrumentation [#1944](https://github.com/getsentry/sentry-ruby/pull/1944)
- Expose `span_id` in Span constructor [#1945](https://github.com/getsentry/sentry-ruby/pull/1945)
- Expose `span_id` in `Span` constructor [#1945](https://github.com/getsentry/sentry-ruby/pull/1945)
- Expose `end_timestamp` in `Span#finish` and `Transaction#finish` [#1946](https://github.com/getsentry/sentry-ruby/pull/1946)

## 5.6.0

Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/lib/sentry/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def initialize(

# Finishes the span by adding a timestamp.
# @return [self]
def finish
def finish(end_timestamp: nil)
# already finished
return if @timestamp

@timestamp = Sentry.utc_now.to_f
@timestamp = end_timestamp || Sentry.utc_now.to_f
self
end

Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/lib/sentry/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def set_initial_sample_decision(sampling_context:)
# Finishes the transaction's recording and send it to Sentry.
# @param hub [Hub] the hub that'll send this transaction. (Deprecated)
# @return [TransactionEvent]
def finish(hub: nil)
def finish(hub: nil, end_timestamp: nil)
if hub
log_warn(
<<~MSG
Expand All @@ -222,7 +222,7 @@ def finish(hub: nil)

hub ||= @hub

super() # Span#finish doesn't take arguments
super(end_timestamp: end_timestamp)

if @name.nil?
@name = UNLABELD_NAME
Expand Down
10 changes: 10 additions & 0 deletions sentry-ruby/spec/sentry/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@
expect(event[:transaction]).to eq("foo")
end

it "finishes the transaction with explicit timestamp" do
timestamp = Sentry.utc_now.to_f
subject.finish(end_timestamp: timestamp)

expect(events.count).to eq(1)
event = events.last.to_hash

expect(event[:timestamp]).to eq(timestamp)
end

it "assigns the transaction's tags" do
Sentry.set_tags(name: "apple")

Expand Down

0 comments on commit f2d6d71

Please sign in to comment.