|
1 | | -#' Temporarily set OpenTelemetry collection level |
| 1 | +#' Temporarily set OpenTelemetry (OTel) collection level |
2 | 2 | #' |
3 | 3 | #' @description |
4 | | -#' `withOtelCollect()` temporarily sets the OpenTelemetry collection level for |
| 4 | +#' Control Shiny's OTel collection level for particular reactive expression(s). |
| 5 | +#' |
| 6 | +#' `withOtelCollect()` sets the OpenTelemetry collection level for |
5 | 7 | #' the duration of evaluating `expr`. `localOtelCollect()` sets the collection |
6 | 8 | #' level for the remainder of the current function scope. |
7 | 9 | #' |
8 | | -#' These functions are useful for temporarily controlling telemetry collection |
9 | | -#' during reactive expression creation. Only the following levels are allowed: |
10 | | -#' * `"none"` - No telemetry data collected |
11 | | -#' * `"reactivity"` - Collect reactive execution spans (includes session and |
12 | | -#' reactive update events) |
13 | | -#' * `"all"` - All available telemetry (currently equivalent to `"reactivity"`) |
14 | | -#' |
| 10 | +#' @details |
15 | 11 | #' Note that `"session"` and `"reactive_update"` levels are not permitted as |
16 | 12 | #' these are runtime-specific levels that should only be set permanently via |
17 | 13 | #' `options(shiny.otel.collect = ...)` or the `SHINY_OTEL_COLLECT` environment |
18 | 14 | #' variable, not temporarily during reactive expression creation. |
19 | 15 | #' |
20 | | -#' @section Intended Usage: |
| 16 | +#' @section Best practice: |
21 | 17 | #' |
22 | | -#' These functions are designed to perform sweeping changes to telemetry |
23 | | -#' collection, such as enabling or disabling OpenTelemetry for an entire module |
24 | | -#' or section of code where reactive expressions are being **created**: |
| 18 | +#' Best practice is to set the collection level for code that *creates* reactive |
| 19 | +#' expressions, not code that *runs* them. For instance: |
25 | 20 | #' |
26 | 21 | #' ```r |
27 | | -#' # Enable telemetry for an entire module |
28 | | -#' withOtelCollect("all", { |
29 | | -#' my_result <- my_module("my_id") |
| 22 | +#' # Disable telemetry for a reactive expression |
| 23 | +#' withOtelCollect("none", { |
| 24 | +#' my_reactive <- reactive({ ... }) |
30 | 25 | #' }) |
31 | 26 | #' |
32 | | -#' # Disable telemetry for expensive development-only reactives |
| 27 | +#' # Disable telemetry for a render function |
33 | 28 | #' withOtelCollect("none", { |
34 | | -#' debug_reactive <- reactive({ expensive_debug_computation() }) |
| 29 | +#' output$my_plot <- renderPlot({ ... }) |
35 | 30 | #' }) |
36 | | -#' ``` |
37 | | -#' |
38 | | -#' @section Pipe Usage (Not Recommended): |
39 | | -#' |
40 | | -#' While using `withOtelCollect()` as a pipe-able method, it is not recommended due to the use case where the reactive object is created before the `withOtelCollect()` call. In such cases, the reactive object will not inherit the intended OpenTelemetry settings. |
41 | 31 | #' |
42 | | -#' Therefore, to avoid this hard-to-debug situation, we recommend that you only create your reactive objects within the `withOtelCollect()` call or after setting the local collection level with `localOtelCollect()`. |
| 32 | +#' #' # Disable telemetry for an observer |
| 33 | +#' withOtelCollect("none", { |
| 34 | +#' observe({ ... })) |
| 35 | +#' }) |
43 | 36 | #' |
44 | | -#' ```r |
45 | | -#' # Technically works, but not recommended |
46 | | -#' x <- reactive({ ... }) %>% withOtelCollect(collect = "all") |
47 | | -#' x <- reactive({ ... }) |> withOtelCollect(collect = "all") |
48 | | -#' # Equivalent to: |
49 | | -#' x <- withOtelCollect("all", reactive({ ... })) |
50 | | -#' |
51 | | -#' # Does NOT work as intended |
52 | | -#' x <- reactive({ ... }) |
53 | | -#' # `x` was created outside of `withOtelCollect()`, |
54 | | -#' # therefore no OTel settings are applied |
55 | | -#' x_no_otel <- withOtelCollect("all", x) |
56 | | -#' |
57 | | -#' # Best practice: Create the reactive object within `expr=` |
58 | | -#' withOtelCollect("all", { |
59 | | -#' x_with_otel <- reactive({ ... }) |
60 | | -#' y_with_otel <- reactive({ ... }) |
| 37 | +#' # Disable telemetry for an entire module |
| 38 | +#' withOtelCollect("none", { |
| 39 | +#' my_result <- my_module("my_id") |
61 | 40 | #' }) |
| 41 | +#' # Use `my_result` as normal here |
62 | 42 | #' ``` |
63 | 43 | #' |
| 44 | +#' NOTE: It's not recommended to pipe existing reactive objects into |
| 45 | +#' `withOtelCollect()` since they won't inherit their intended OTel settings, |
| 46 | +#' leading to confusion. |
| 47 | +#' |
64 | 48 | #' @param collect Character string specifying the OpenTelemetry collection level. |
65 | | -#' Must be one of `"none"`, `"reactivity"`, or `"all"`. |
| 49 | +#' Must be one of the following: |
| 50 | +#' |
| 51 | +#' * `"none"` - No telemetry data collected |
| 52 | +#' * `"reactivity"` - Collect reactive execution spans (includes session and |
| 53 | +#' reactive update events) |
| 54 | +#' * `"all"` - All available telemetry (currently equivalent to `"reactivity"`) |
66 | 55 | #' @param expr Expression to evaluate with the specified collection level |
67 | 56 | #' (for `withOtelCollect()`). |
68 | 57 | #' @param envir Environment where the collection level should be set |
|
0 commit comments