Debian Codegraph @

man/withOtelCollect.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/otel-with.R
3 \name{withOtelCollect}
4 \alias{withOtelCollect}
5 \alias{localOtelCollect}
6 \title{Temporarily set OpenTelemetry (OTel) collection level}
7 \usage{
8 withOtelCollect(collect, expr)
9
10 localOtelCollect(collect, envir = parent.frame())
11 }
12 \arguments{
13 \item{collect}{Character string specifying the OpenTelemetry collection level.
14 Must be one of the following:
15
16 \if{html}{\out{<div class="sourceCode">}}\preformatted{* `"none"` - No telemetry data collected
17 * `"reactivity"` - Collect reactive execution spans (includes session and
18 reactive update events)
19 * `"all"` - All available telemetry (currently equivalent to `"reactivity"`)
20 }\if{html}{\out{</div>}}}
21
22 \item{expr}{Expression to evaluate with the specified collection level
23 (for \code{withOtelCollect()}).}
24
25 \item{envir}{Environment where the collection level should be set
26 (for \code{localOtelCollect()}). Defaults to the parent frame.}
27 }
28 \value{
29 \itemize{
30 \item \code{withOtelCollect()} returns the value of \code{expr}.
31 \item \code{localOtelCollect()} is called for its side effect and returns the previous
32 \code{collect} value invisibly.
33 }
34 }
35 \description{
36 Control Shiny's OTel collection level for particular reactive expression(s).
37
38 \code{withOtelCollect()} sets the OpenTelemetry collection level for
39 the duration of evaluating \code{expr}. \code{localOtelCollect()} sets the collection
40 level for the remainder of the current function scope.
41 }
42 \details{
43 Note that \code{"session"} and \code{"reactive_update"} levels are not permitted as
44 these are runtime-specific levels that should only be set permanently via
45 \code{options(shiny.otel.collect = ...)} or the \code{SHINY_OTEL_COLLECT} environment
46 variable, not temporarily during reactive expression creation.
47 }
48 \section{Best practice}{
49
50
51 Best practice is to set the collection level for code that \emph{creates} reactive
52 expressions, not code that \emph{runs} them. For instance:
53
54 \if{html}{\out{<div class="sourceCode r">}}\preformatted{# Disable telemetry for a reactive expression
55 withOtelCollect("none", \{
56 my_reactive <- reactive(\{ ... \})
57 \})
58
59 # Disable telemetry for a render function
60 withOtelCollect("none", \{
61 output$my_plot <- renderPlot(\{ ... \})
62 \})
63
64 #' # Disable telemetry for an observer
65 withOtelCollect("none", \{
66 observe(\{ ... \}))
67 \})
68
69 # Disable telemetry for an entire module
70 withOtelCollect("none", \{
71 my_result <- my_module("my_id")
72 \})
73 # Use `my_result` as normal here
74 }\if{html}{\out{</div>}}
75
76 NOTE: It's not recommended to pipe existing reactive objects into
77 \code{withOtelCollect()} since they won't inherit their intended OTel settings,
78 leading to confusion.
79 }
80
81 \examples{
82 \dontrun{
83 # Temporarily disable telemetry collection
84 withOtelCollect("none", {
85 # Code here won't generate telemetry
86 reactive({ input$x + 1 })
87 })
88
89 # Collect reactivity telemetry but not other events
90 withOtelCollect("reactivity", {
91 # Reactive execution will be traced
92 observe({ print(input$x) })
93 })
94
95 # Use local variant in a function
96 my_function <- function() {
97 localOtelCollect("none")
98 # Rest of function executes without telemetry
99 reactive({ input$y * 2 })
100 }
101 }
102
103 }
104 \seealso{
105 See the \code{shiny.otel.collect} option within \code{\link{shinyOptions}}. Setting
106 this value will globally control OpenTelemetry collection levels.
107 }