|
97 | 97 | it "does not re-clone the hub and reuses the existing propagation context" do |
98 | 98 | Sentry.clone_hub_to_current_thread |
99 | 99 | Sentry.get_current_scope.generate_propagation_context(env) |
100 | | - env[Sentry::PropagationContext::ESTABLISHED_ENV_KEY] = true |
| 100 | + env[Sentry::PropagationContext::ESTABLISHED_ENV_KEY] = Sentry.get_current_scope.propagation_context |
101 | 101 |
|
102 | 102 | established_propagation_context = Sentry.get_current_scope.propagation_context |
103 | 103 |
|
|
118 | 118 | it "deletes the established flag from env so it doesn't leak into later reuses of the same env" do |
119 | 119 | Sentry.clone_hub_to_current_thread |
120 | 120 | Sentry.get_current_scope.generate_propagation_context(env) |
121 | | - env[Sentry::PropagationContext::ESTABLISHED_ENV_KEY] = true |
| 121 | + env[Sentry::PropagationContext::ESTABLISHED_ENV_KEY] = Sentry.get_current_scope.propagation_context |
122 | 122 |
|
123 | 123 | app = ->(_e) { [200, {}, ['okay']] } |
124 | 124 | stack = Sentry::Rack::CaptureExceptions.new(app) |
|
127 | 127 | expect(env.key?(Sentry::PropagationContext::ESTABLISHED_ENV_KEY)).to eq(false) |
128 | 128 | end |
129 | 129 |
|
| 130 | + it "honors the incoming trace when the established context belongs to another execution context" do |
| 131 | + external_transaction = Sentry::Transaction.new(op: "pageload", status: "ok", sampled: true, name: "a/path") |
| 132 | + env["HTTP_SENTRY_TRACE"] = external_transaction.to_sentry_trace |
| 133 | + |
| 134 | + Sentry.clone_hub_to_current_thread |
| 135 | + Sentry.get_current_scope.generate_propagation_context(env) |
| 136 | + env[Sentry::PropagationContext::ESTABLISHED_ENV_KEY] = Sentry.get_current_scope.propagation_context |
| 137 | + |
| 138 | + trace_id_in_app = nil |
| 139 | + app = lambda do |_e| |
| 140 | + trace_id_in_app = Sentry.get_current_scope.get_trace_context[:trace_id] |
| 141 | + [200, {}, ['okay']] |
| 142 | + end |
| 143 | + |
| 144 | + stack = Sentry::Rack::CaptureExceptions.new(app) |
| 145 | + Thread.new { stack.call(env) }.join |
| 146 | + |
| 147 | + expect(trace_id_in_app).to eq(external_transaction.trace_id) |
| 148 | + end |
| 149 | + |
130 | 150 | it "does not reuse a stale established context on a later, unrelated call with the same env" do |
131 | 151 | # Simulates a long-lived connection (e.g. Action Cable) that stores the handshake's |
132 | 152 | # env and reuses it for many separate operations over its lifetime - only the very |
133 | 153 | # first operation immediately following CaptureContext should honor the flag. |
134 | 154 | Sentry.clone_hub_to_current_thread |
135 | 155 | Sentry.get_current_scope.generate_propagation_context(env) |
136 | | - env[Sentry::PropagationContext::ESTABLISHED_ENV_KEY] = true |
| 156 | + env[Sentry::PropagationContext::ESTABLISHED_ENV_KEY] = Sentry.get_current_scope.propagation_context |
137 | 157 |
|
138 | 158 | app = ->(_e) { [200, {}, ['okay']] } |
139 | 159 | stack = Sentry::Rack::CaptureExceptions.new(app) |
|
0 commit comments