| 1 |
otel_collect_choices <- c( |
| 2 |
"none", |
| 3 |
"session", |
| 4 |
"reactive_update", |
| 5 |
"reactivity", |
| 6 |
"all" |
| 7 |
) |
| 8 |
|
| 9 |
# Check if the collect level is sufficient |
| 10 |
otel_collect_is_enabled <- function( |
| 11 |
impl_level, |
| 12 |
# Listen to option and fall back to the env var |
| 13 |
opt_collect_level = getOption("shiny.otel.collect", Sys.getenv("SHINY_OTEL_COLLECT", "all")) |
| 14 |
) { |
| 15 |
opt_collect_level <- as_otel_collect(opt_collect_level) |
| 16 |
|
| 17 |
which(opt_collect_level == otel_collect_choices) >= |
| 18 |
which(impl_level == otel_collect_choices) |
| 19 |
} |
| 20 |
|
| 21 |
# Check if tracing is enabled and if the collect level is sufficient |
| 22 |
has_otel_collect <- function(collect) { |
| 23 |
# Only check pkg author input iff loaded with pkgload |
| 24 |
if (IS_SHINY_LOCAL_PKG) { |
| 25 |
stopifnot(length(collect) == 1, any(collect == otel_collect_choices)) |
| 26 |
} |
| 27 |
|
| 28 |
otel_is_tracing_enabled() && otel_collect_is_enabled(collect) |
| 29 |
} |
| 30 |
|
| 31 |
# Run expr with otel collection disabled |
| 32 |
with_no_otel_collect <- function(expr) { |
| 33 |
withOtelCollect("none", expr) |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
## -- Helpers ----------------------------------------------------- |
| 38 |
|
| 39 |
# shiny.otel.collect can be: |
| 40 |
# "none"; To do nothing / fully opt-out |
| 41 |
# "session" for session/start events |
| 42 |
# "reactive_update" (includes "session" features) and reactive_update spans |
| 43 |
# "reactivity" (includes "reactive_update" features) and spans for all reactive things |
| 44 |
# "all" - Anything that Shiny can do. (Currently equivalent to the "reactivity" level) |
| 45 |
|
| 46 |
as_otel_collect <- function(collect = "all") { |
| 47 |
if (!is.character(collect)) { |
| 48 |
stop("`collect` must be a character vector.") |
| 49 |
} |
| 50 |
|
| 51 |
# Match to collect enum |
| 52 |
collect <- match.arg(collect, otel_collect_choices, several.ok = FALSE) |
| 53 |
|
| 54 |
return(collect) |
| 55 |
} |