Skip to content

Commit

Permalink
Top level get_traceparent and get_baggage methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Aug 28, 2023
1 parent 71b288c commit abc0eaa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,24 @@ def add_global_event_processor(&block)
Scope.add_global_event_processor(&block)
end

# Returns the traceparent (sentry-trace) header for distributed tracing.
# Can be either from the currently active span or the propagation context.
#
# @return [String, nil]
def get_traceparent
return nil unless initialized?
get_current_hub.get_traceparent
end

# Returns the baggage header for distributed tracing.
# Can be either from the currently active span or the propagation context.
#
# @return [String, nil]
def get_baggage
return nil unless initialized?
get_current_hub.get_baggage
end

##### Helpers #####

# @!visibility private
Expand Down
14 changes: 14 additions & 0 deletions sentry-ruby/lib/sentry/hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,20 @@ def with_session_tracking(&block)
end_session
end

def get_traceparent
return nil unless current_scope

current_scope.get_span&.to_sentry_trace ||
current_scope.propagation_context&.get_traceparent
end

def get_baggage
return nil unless current_scope

current_scope.get_span&.to_baggage ||
current_scope.propagation_context&.get_baggage&.serialize
end

private

def current_layer
Expand Down

0 comments on commit abc0eaa

Please sign in to comment.