Skip to content

Commit 98b30d2

Browse files
cyberdeliasolnic
andauthored
Default to internal_error rather than unknown_error (#2473)
* Default to internal_error rather than unknown_error * Add tests for SpanProcessor#update_span_status * Update CHANGELOG * Update CHANGELOG.md --------- Co-authored-by: Peter Solnica <peter@solnica.online>
1 parent bb9ce72 commit 98b30d2

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
### Bug fixes
4+
5+
- Default to `internal_error` error type for OpenTelemetry spans [#2473](https://github.com/getsentry/sentry-ruby/pull/2473)
6+
17
## 5.22.1
28

39
### Bug Fixes

sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def update_span_status(sentry_span, otel_span)
151151
if (http_status_code = otel_span.attributes[SEMANTIC_CONVENTIONS::HTTP_STATUS_CODE])
152152
sentry_span.set_http_status(http_status_code)
153153
elsif (status_code = otel_span.status.code)
154-
status = [0, 1].include?(status_code) ? "ok" : "unknown_error"
154+
status = [0, 1].include?(status_code) ? "ok" : "internal_error"
155155
sentry_span.set_status(status)
156156
end
157157
end

sentry-opentelemetry/spec/sentry/opentelemetry/span_processor_spec.rb

+53-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@
88
let(:tracer) { ::OpenTelemetry.tracer_provider.tracer('sentry', '1.0') }
99
let(:empty_context) { ::OpenTelemetry::Context.empty }
1010
let(:invalid_span) { ::OpenTelemetry::SDK::Trace::Span::INVALID }
11+
let(:error_span) do
12+
attributes = {
13+
'http.method' => 'GET',
14+
'http.host' => 'sentry.io',
15+
'http.scheme' => 'https'
16+
}
17+
18+
tracer.start_root_span('HTTP GET', attributes: attributes, kind: :server).tap do |span|
19+
span.status = OpenTelemetry::Trace::Status.error("not a success")
20+
end
21+
end
22+
let(:http_error_span) do
23+
attributes = {
24+
'http.method' => 'GET',
25+
'http.host' => 'sentry.io',
26+
'http.scheme' => 'https',
27+
'http.status_code' => '409'
28+
}
29+
30+
tracer.start_root_span('HTTP GET', attributes: attributes, kind: :server)
31+
end
1132

1233
let(:root_span) do
1334
attributes = {
@@ -197,12 +218,16 @@
197218
subject.on_start(root_span, empty_context)
198219
subject.on_start(child_db_span, root_parent_context)
199220
subject.on_start(child_http_span, root_parent_context)
221+
subject.on_start(error_span, empty_context)
222+
subject.on_start(http_error_span, empty_context)
200223
end
201224

202225
let(:finished_db_span) { child_db_span.finish }
203226
let(:finished_http_span) { child_http_span.finish }
204227
let(:finished_root_span) { root_span.finish }
205228
let(:finished_invalid_span) { invalid_span.finish }
229+
let(:finished_error_span) { error_span.finish }
230+
let(:finished_http_error_span) { http_error_span.finish }
206231

207232
it 'noops when not initialized' do
208233
expect(Sentry).to receive(:initialized?).and_return(false)
@@ -224,6 +249,30 @@
224249
subject.on_finish(finished_invalid_span)
225250
end
226251

252+
it 'updates span status on error' do
253+
expect(subject.span_map).to receive(:delete).and_call_original
254+
255+
span_id = finished_error_span.context.hex_span_id
256+
sentry_span = subject.span_map[span_id]
257+
258+
expect(sentry_span).to receive(:finish).and_call_original
259+
subject.on_finish(finished_error_span)
260+
261+
expect(sentry_span.status).to eq('internal_error')
262+
end
263+
264+
it 'updates span status on HTTP error' do
265+
expect(subject.span_map).to receive(:delete).and_call_original
266+
267+
span_id = finished_http_error_span.context.hex_span_id
268+
sentry_span = subject.span_map[span_id]
269+
270+
expect(sentry_span).to receive(:finish).and_call_original
271+
subject.on_finish(finished_http_error_span)
272+
273+
expect(sentry_span.status).to eq('already_exists')
274+
end
275+
227276
it 'finishes sentry child span on otel child db span finish' do
228277
expect(subject.span_map).to receive(:delete).and_call_original
229278

@@ -241,7 +290,7 @@
241290
expect(sentry_span.data).to include({ 'otel.kind' => finished_db_span.kind })
242291
expect(sentry_span.timestamp).to eq(finished_db_span.end_timestamp / 1e9)
243292

244-
expect(subject.span_map.size).to eq(2)
293+
expect(subject.span_map.size).to eq(4)
245294
expect(subject.span_map.keys).not_to include(span_id)
246295
end
247296

@@ -263,13 +312,15 @@
263312
expect(sentry_span.timestamp).to eq(finished_http_span.end_timestamp / 1e9)
264313
expect(sentry_span.status).to eq('ok')
265314

266-
expect(subject.span_map.size).to eq(2)
315+
expect(subject.span_map.size).to eq(4)
267316
expect(subject.span_map.keys).not_to include(span_id)
268317
end
269318

270319
it 'finishes sentry transaction on otel root span finish' do
271320
subject.on_finish(finished_db_span)
272321
subject.on_finish(finished_http_span)
322+
subject.on_finish(finished_error_span)
323+
subject.on_finish(finished_http_error_span)
273324

274325
expect(subject.span_map).to receive(:delete).and_call_original
275326

0 commit comments

Comments
 (0)