Debian Codegraph @

R/otel-error.R

raw
1
2 has_seen_otel_exception <- function(cnd) {
3 !is.null(cnd$.shiny_otel_exception)
4 }
5
6 mark_otel_exception_as_seen <- function(cnd) {
7 cnd$.shiny_otel_exception <- TRUE
8 cnd
9 }
10
11 set_otel_exception_status_and_throw <- function(cnd) {
12 cnd <- set_otel_exception_status(cnd)
13
14 # Rethrow the (possibly updated) error
15 signalCondition(cnd)
16 }
17
18 set_otel_exception_status <- function(cnd) {
19 if (inherits(cnd, "shiny.custom.error")) {
20 # No-op
21 } else if (inherits(cnd, "shiny.output.cancel")) {
22 # No-op
23 } else if (inherits(cnd, "shiny.output.progress")) {
24 # No-op
25 } else if (cnd_inherits(cnd, "shiny.silent.error")) {
26 # No-op
27 } else {
28 # Only when an unknown error occurs do we set the span status to error
29 span <- otel::get_active_span()
30
31 # Only record the exception once at the original point of failure,
32 # not every reactive expression that it passes through
33 if (!has_seen_otel_exception(cnd)) {
34 span$record_exception(
35 # Record a sanitized error if sanitization is enabled
36 get_otel_error_obj(cnd)
37 )
38 cnd <- mark_otel_exception_as_seen(cnd)
39 }
40
41 # Record the error status on the span for any context touching this error
42 span$set_status("error")
43 }
44
45 cnd
46 }
47
48
49 get_otel_error_obj <- function(e) {
50 # Do not expose errors to otel if sanitization is enabled
51 if (getOption("shiny.otel.sanitize.errors", TRUE)) {
52 sanitized_error()
53 } else {
54 e
55 }
56 }