Azure App Insights
Azure App Insights
Azure App Insights
R topics documented:
AzureAppInsights-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
is_instrumentation_key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
startAzureAppInsights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
trackEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1
2 config
Index 8
AzureAppInsights-package
Azure Application Insights for web pages
Description
Add Azure Application Insights tracking to a Shiny App. Requires an active Azure subscription
and Application Insights instrumentation key! Based on https://docs.microsoft.com/en-us/
azure/azure-monitor/app/javascript / https://github.com/microsoft/ApplicationInsights-JS.
Details
Documentation in this page will be limited, as most is explained on the main page.
Supports so far only pageViews (automatically sent), autoTrackPageVisitTime (when configured
with config), customEvents (see trackEvent).
Author(s)
Stefan McKinnon Edwards <smhe@kamstrup.dk>
See Also
Useful links:
Description
Ensures an instrumentationKey/connectionString and appId is provided.
Usage
config(
appId,
instrumentationKey,
connectionString,
autoTrackPageVisitTime = TRUE,
...
)
demo 3
Arguments
appId String for identifying your app, if you use same Application Insights for multiple
apps.
instrumentationKey, connectionString
Credentials for sending to Application Insights. connectionString is pre-
ferred for newer accounts and must contain both InstrumentationKey and
IngestionEndpoint.
autoTrackPageVisitTime
Submits how long time a user spent on the *previous* page (see website for
more information).
... Additional options, as given in https://docs.microsoft.com/en-us/azure/
azure-monitor/app/javascript#configuration. No checks performed here.
Details
Value
List.
Description
Launches a simple demonstration of using Application Insights for Shiny apps. Requires that you
have a Microsoft Azure Application Insights resource to send to; demonstration will still work –
your metrics will just be sent to oblivion.
Usage
demo(
connectionString,
debug = TRUE,
appId = "Test AzureAppInsights",
launch.browser = FALSE,
instrumentationKey
)
4 is_instrumentation_key
Arguments
connectionString, instrumentationKey
Credentials for sending to Application Insights. See arguments for config.
debug Logical, see startAzureAppInsights.
appId A id for this particular application.
launch.browser Logical, see runApp.
Details
It may take some minutes before the values sent to Application Insights are visible in the logs on
portal.azure.com.
If neither connectionString nor instrumentationKey is provided, a connection string is found
in the environment variable AAI_CONNSTR.
Examples
connstr <- paste0(
'InstrumentationKey=00000000-0000-0000-0000-000000000000;',
'IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/;',
'LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/')
## Not run:
demo(connstr)
## End(Not run)
is_instrumentation_key
Check if string matches pattern for an instrumentation key.
Description
Check if string matches pattern for an instrumentation key.
Usage
is_instrumentation_key(x)
Arguments
x A string containing nothing else but an instrumentation key.
Value
Logical value.
startAzureAppInsights 5
startAzureAppInsights Include and run Azure Application Insights for web pages
Description
Include the JS snippet in your ui-function with includeAzureAppInsights and start the tracking
with startAzureAppInsights in your server-function.
Usage
startAzureAppInsights(
session,
cfg,
instance.name = "appInsights",
ld = 0,
useXhr = TRUE,
crossOrigin = "anonymous",
onInit = NULL,
heartbeat = 3e+05,
extras = list(),
include.ip = FALSE,
cookie.user = FALSE,
debug = FALSE
)
Arguments
session The session object passed to function given to shinyServer.
cfg List-object from config.
instance.name Global JavaScript Instance name defaults to "appInsights" when not supplied.
NOT the app’s name. Used for accessing the instance from other JavaScript
routines.
ld Defines the load delay (in ms) before attempting to load the sdk. -1 = block page
load and add to head. (default) = 0ms load after timeout,
useXhr Logical, use XHR instead of fetch to report failures (if available).
crossOrigin When supplied this will add the provided value as the cross origin attribute on
the script tag.
onInit Once the application insights instance has loaded and initialized this callback
function will be called with 1 argument – the sdk instance
heartbeat Integer, how often should the heartbeat beat – or set to FALSE to disable.
extras (Named) list of values to add to any tracking.
include.ip Logical, adds ip to all tracking’s customDimension. See note.
6 trackEvent
cookie.user Logical, when TRUE sets a cookie with a random string and submits this along
with any tracking with the key userid.
debug Logical, JS loader uses console.log.
version Version of the Application Insights JavaScript SDK to load.
Value
Methods sends data to client’s browser; returns the sent list, invisibly.
References
https://docs.microsoft.com/en-us/azure/azure-monitor/app/javascript and https://github.com/microsoft/ApplicationInsights-
JS and https://learn.microsoft.com/en-us/azure/azure-monitor/app/ip-collection?tabs=net
Description
Use trackEvent for tracking a single event together with any extra properties.
Use trackMetric to track a summary of some measured metrics.
Usage
trackEvent(session, name, properties)
Arguments
session The session object passed to function given to shinyServer.
name Name of the event.
properties List of properties to track. appId and any extras given in startAzureAppInsights
is automatically inserted.
metrics Numeric vector of values to calculate summary on. Non-finite values are re-
moved.
trackEvent 7
Value
Method sends data to client’s browser; returns the sent list, invisibly.
Tracking Metrics
Individual measured values are not sent to Application Insights. Instead, summaries of the values
(mean, range, average, standard deviation) are sent. Note: Standard deviation doesn’t quite work
yet.
Before calculating summaries, non-finite values are removed (see is.finite). If there are no values
in metrics, nothing is sent.
Index
AzureAppInsights
(AzureAppInsights-package), 2
AzureAppInsights-package, 2
config, 2, 2, 4, 5
demo, 3
includeAzureAppInsights
(startAzureAppInsights), 5
is.finite, 7
is_instrumentation_key, 4
runApp, 4
startAzureAppInsights, 4, 5, 6
trackEvent, 2, 6
trackMetric (trackEvent), 6