Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_trace_propagation_meta helper #2314

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
config.enabled_patches += [:graphql]
end
```
- Add `Sentry.get_trace_propagation_meta` helper for injecting meta tags into views ([#2314](https://github.com/getsentry/sentry-ruby/pull/2314))

### Bug Fixes

Expand Down
9 changes: 9 additions & 0 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,15 @@ def get_trace_propagation_headers
get_current_hub.get_trace_propagation_headers
end

# Returns the a Hash containing sentry-trace and baggage.
# Can be either from the currently active span or the propagation context.
#
# @return [String]
def get_trace_propagation_meta
return '' unless initialized?
get_current_hub.get_trace_propagation_meta
end

# Continue an incoming trace from a rack env like hash.
#
# @param env [Hash]
Expand Down
6 changes: 6 additions & 0 deletions sentry-ruby/lib/sentry/hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ def get_trace_propagation_headers
headers
end

def get_trace_propagation_meta
get_trace_propagation_headers.map do |k, v|
"<meta name=\"#{k}\" content=\"#{v}\">"
end.join("\n")
end

def continue_trace(env, **options)
configure_scope { |s| s.generate_propagation_context(env) }

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

describe ".get_trace_propagation_meta" do
it "returns meta tags for sentry-trace and baggage" do
meta = <<~META
<meta name="sentry-trace" content="#{described_class.get_traceparent}">
<meta name="baggage" content="#{described_class.get_baggage}">
META

expect(described_class.get_trace_propagation_meta).to eq(meta.chomp)
end
end

describe ".continue_trace" do
context "without incoming sentry trace" do
let(:env) { { "HTTP_FOO" => "bar" } }
Expand Down
Loading