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 4, 2023
1 parent 64fc8d7 commit 70ed112
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

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

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry-ruby.rb#L497-L498

Added lines #L497 - L498 were not covered by tests
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

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

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry-ruby.rb#L506-L507

Added lines #L506 - L507 were not covered by tests
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

Check warning on line 233 in sentry-ruby/lib/sentry/hub.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/hub.rb#L233

Added line #L233 was not covered by tests

current_scope.get_span&.to_sentry_trace ||

Check warning on line 235 in sentry-ruby/lib/sentry/hub.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/hub.rb#L235

Added line #L235 was not covered by tests
current_scope.propagation_context&.get_traceparent
end

def get_baggage
return nil unless current_scope

Check warning on line 240 in sentry-ruby/lib/sentry/hub.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/hub.rb#L240

Added line #L240 was not covered by tests

current_scope.get_span&.to_baggage ||

Check warning on line 242 in sentry-ruby/lib/sentry/hub.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/hub.rb#L242

Added line #L242 was not covered by tests
current_scope.propagation_context&.get_baggage&.serialize
end

private

def current_layer
Expand Down

0 comments on commit 70ed112

Please sign in to comment.