diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7eaff1a37..f5d4328d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/sentry-ruby/lib/sentry-ruby.rb b/sentry-ruby/lib/sentry-ruby.rb
index d412dec2a..a48906925 100644
--- a/sentry-ruby/lib/sentry-ruby.rb
+++ b/sentry-ruby/lib/sentry-ruby.rb
@@ -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]
diff --git a/sentry-ruby/lib/sentry/hub.rb b/sentry-ruby/lib/sentry/hub.rb
index 05d22152b..d0615ee28 100644
--- a/sentry-ruby/lib/sentry/hub.rb
+++ b/sentry-ruby/lib/sentry/hub.rb
@@ -284,6 +284,12 @@ def get_trace_propagation_headers
headers
end
+ def get_trace_propagation_meta
+ get_trace_propagation_headers.map do |k, v|
+ ""
+ end.join("\n")
+ end
+
def continue_trace(env, **options)
configure_scope { |s| s.generate_propagation_context(env) }
diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb
index c3f12777a..0e30d150e 100644
--- a/sentry-ruby/spec/sentry_spec.rb
+++ b/sentry-ruby/spec/sentry_spec.rb
@@ -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
+
+ 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" } }