Skip to content

Commit

Permalink
Add get_trace_context and apply in scope
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Aug 2, 2023
1 parent 9c833b5 commit ab95f3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions sentry-ruby/lib/sentry/propagation_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,15 @@ def initialize
@parent_span_id = nil
@dynamic_sampling_context = nil
end

# Returns the trace context that can be used to embed in an Event.
# @return [Hash]
def get_trace_context
{
trace_id: @trace_id,
span_id: @span_id,
parent_span_id: @parent_span_id
}
end
end
end
10 changes: 8 additions & 2 deletions sentry-ruby/lib/sentry/scope.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "sentry/breadcrumb_buffer"
require "sentry/propagation_context"
require "etc"

module Sentry
Expand All @@ -20,7 +21,8 @@ class Scope
:event_processors,
:rack_env,
:span,
:session
:session,
:propagation_context
]

attr_reader(*ATTRIBUTES)
Expand Down Expand Up @@ -50,7 +52,9 @@ def apply_to_event(event, hint = nil)
event.transaction_info = { source: transaction_source } if transaction_source

if span
event.contexts[:trace] = span.get_trace_context
event.contexts[:trace] ||= span.get_trace_context

Check warning on line 55 in sentry-ruby/lib/sentry/scope.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/scope.rb#L55

Added line #L55 was not covered by tests
else
event.contexts[:trace] ||= propagation_context.get_trace_context
end

event.fingerprint = fingerprint
Expand Down Expand Up @@ -95,6 +99,7 @@ def dup
copy.fingerprint = fingerprint.deep_dup
copy.span = span.deep_dup
copy.session = session.deep_dup
copy.propagation_context = propagation_context.deep_dup
copy
end

Expand All @@ -111,6 +116,7 @@ def update_from_scope(scope)
self.transaction_sources = scope.transaction_sources
self.fingerprint = scope.fingerprint
self.span = scope.span
self.propagation_context = scope.propagation_context

Check warning on line 119 in sentry-ruby/lib/sentry/scope.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/scope.rb#L119

Added line #L119 was not covered by tests
end

# Updates the scope's data from the given options.
Expand Down

0 comments on commit ab95f3a

Please sign in to comment.