Skip to content

Commit c7116eb

Browse files
authored
Merge branch 'main' into rc-v1.12.1
2 parents ebcf816 + b436d2a commit c7116eb

File tree

2 files changed

+63
-87
lines changed

2 files changed

+63
-87
lines changed

R/otel-with.R

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,57 @@
1-
#' Temporarily set OpenTelemetry collection level
1+
#' Temporarily set OpenTelemetry (OTel) collection level
22
#'
33
#' @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
57
#' the duration of evaluating `expr`. `localOtelCollect()` sets the collection
68
#' level for the remainder of the current function scope.
79
#'
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
1511
#' Note that `"session"` and `"reactive_update"` levels are not permitted as
1612
#' these are runtime-specific levels that should only be set permanently via
1713
#' `options(shiny.otel.collect = ...)` or the `SHINY_OTEL_COLLECT` environment
1814
#' variable, not temporarily during reactive expression creation.
1915
#'
20-
#' @section Intended Usage:
16+
#' @section Best practice:
2117
#'
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:
2520
#'
2621
#' ```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({ ... })
3025
#' })
3126
#'
32-
#' # Disable telemetry for expensive development-only reactives
27+
#' # Disable telemetry for a render function
3328
#' withOtelCollect("none", {
34-
#' debug_reactive <- reactive({ expensive_debug_computation() })
29+
#' output$my_plot <- renderPlot({ ... })
3530
#' })
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.
4131
#'
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+
#' })
4336
#'
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")
6140
#' })
41+
#' # Use `my_result` as normal here
6242
#' ```
6343
#'
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+
#'
6448
#' @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"`)
6655
#' @param expr Expression to evaluate with the specified collection level
6756
#' (for `withOtelCollect()`).
6857
#' @param envir Environment where the collection level should be set

man/withOtelCollect.Rd

Lines changed: 32 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)