Here are some examples of various browser configurations you can make with GraphQL.
Create a new browser application
You can create browser applications using our NerdGraph API instead of using the UI. The advantage to this is that when it's time to instrument your browser application with New Relic, you can programmatically create and retrieve the JavaScript snippet to copy and paste into your browser app.
For how to use npm to set up for multiple applications, see Instrument multiple apps with npm.
Here's an example mutation to create a new browser application with default settings.
Mutation:
mutation CreateExampleBrowserApplication( $accountId: Int! $name: String! $settings: AgentApplicationBrowserSettingsInput) { agentApplicationCreateBrowser( accountId: $accountId name: $name settings: $settings ) { guid name settings { cookiesEnabled distributedTracingEnabled loaderScript loaderType } }}Variables:
{ "accountId": Int!, "name": String!, "settings": { "cookiesEnabled": Boolean, "distributedTracingEnabled": Boolean, "loaderType": AgentApplicationBrowserLoader }}Retrieve the JavaScript snippet
You can retrieve the JavaScript snippet to copy/paste into your application. Note that the returned snippet is a JSON encoded string that will need to be parsed before it can be copy/pasted.
Query:
query FetchBrowserJavaScriptSnippet($guid: EntityGuid!) { actor { entity(guid: $guid) { ... on BrowserApplicationEntity { guid name browserProperties { jsLoaderScript } } } }}Variables:
{ "guid": EntityGuid!}Examples of configuring browser monitoring
Browser settings can be configured through NerdGraph. Here is an example mutation that changes the apdex of an application.
Mutation:
mutation UpdateBrowserApdexTarget( $guid: EntityGuid! $settings: AgentApplicationSettingsUpdateInput!) { agentApplicationSettingsUpdate(guid: $guid, settings: $settings) { browserSettings { browserConfig { apdexTarget } } errors { description errorClass field } }}Variables:
{ "guid": EntityGuid!, "settings": { "browserConfig": { "apdexTarget": Float } }}For more information on what browser settings can be updated via NerdGraph, reference the following mutation. Documentation for each field can be found in the NerdGraph explorer.
Mutation:
mutation UpdateBrowserSettingsExample( $guid: EntityGuid! $settings: AgentApplicationSettingsUpdateInput!) { agentApplicationSettingsUpdate(guid: $guid, settings: $settings) { browserSettings { browserConfig { apdexTarget } browserMonitoring { ajax { denyList } distributedTracing { allowedOrigins corsEnabled corsUseNewrelicHeader corsUseTracecontextHeaders enabled excludeNewrelicHeader } loader privacy { cookiesEnabled } } dataManagement { sendTransactionEventsToInternalStream } } errors { description errorClass field } }}Variables:
{ "guid": EntityGuid!, "settings": { "browserConfig": { "apdexTarget": Float }, "browserMonitoring": { "ajax": { "denyList": [String!] }, "distributedTracing": { "allowedOrigins": [String!], "corsEnabled": Boolean, "corsUseNewrelicHeader": Boolean, "corsUseTracecontextHeaders": Boolean, "enabled": Boolean, "excludeNewrelicHeader": Boolean } "loader": AgentApplicationSettingsBrowserLoaderInput, "privacy": { "cookiesEnabled": Boolean } } "dataManagement": { "sendTransactionEventsToInternalStream": Boolean } }}Retrieve the application configuration
You can retrieve the browser application configuration to use with the npm package installation method. Depending on your needs, the configuration can be returned in two different formats:
- a JSON encoded string for injection into the
headelement of your webpage. - an object that can be used as is in your application source code.
Query:
query FetchBrowserConfiguration($guid: EntityGuid!) { actor { entity(guid: $guid) { ... on BrowserApplicationEntity { guid name browserProperties { jsConfig jsConfigScript } } } }}Variables:
{ "guid": EntityGuid!}Group your data with browser segments
You can group your browser monitoring results by browser segments to get more meaningful data. Instead of doing this in the UI, you can do it with GraphQL.
List segments
Get started by listing existing segments:
{ actor { entity(guid: "YOUR_GUID") { ... on BrowserApplicationEntity { segmentAllowListAggregate { segments } } } }}Here's the response:
{ "data": { "actor": { "entity": { "segmentAllowListAggregate": { "segments": ["urlsegment1", "urlsegment2"] } } } }}Create segments
Create browser segments using the agentApplicationSegmentsReplaceAllBrowserSegmentAllowList mutation:
mutation { agentApplicationSegmentsReplaceAllBrowserSegmentAllowList( entityGuid: "YOUR_GUID" allowList: { segments: ["urlsegment1", "urlsegment2", "urlsegment3"] } ) { segments }}Here's the response:
{ "data": { "agentApplicationSegmentsReplaceAllBrowserSegmentAllowList": { "segments": ["urlsegment3", "urlsegment2", "urlsegment1"] } }}Create obfuscation rules
You can mask sensitive data before it's harvested by creating ingest obfuscation rules directly from the New Relic platform or NerdGraph. These rules apply to all browser events. Rules configured via the platform or NerdGraph apply to APM-injected applications, copy/paste installations, and NPM installations. To create rules via platform or JavaScript, see Obfuscate sensitive data in the browser agent.
To create obfuscation rules via NerdGraph:
Configure AJAX payload capture
You can retrieve and update the AJAX payload capture setting for your browser application using NerdGraph. This setting controls whether request and response payloads are captured for AJAX calls and corresponds to the payload capture option in your application settings.
You can enable payload capture settings in two steps:
- Retrieve the current payload capture settings.
- Set the
capturePayloadsmode to one of the following values:none: No payload data will be captured.failures: Captures payloads only for requests with a status code of0, a code of400or higher, or a GraphQL error signature in theresponse body.all: Captures payloads for all requests.
Browser agent version pinning
New Relic's GraphQL API provides you a method to "pin" a specific version of the New Relic Browser agent, ensuring it remains consistent within your platform. By pinning a version, you can prevent automatic updates that might introduce unexpected changes or behaviors. The key benefits this feature include these:
- Control: Retain autonomy over when and how updates are applied.
- Confidence: Ensure that a tested and approved version of the agent is running at all times.
- Testability: Easily test new versions in isolated environments before deciding to update.
- Stability: Minimize unexpected disruptions and maintain consistent application behavior.
- Efficiency: Reduce deploy time and mitigate deployment difficulties.
Here is an overview of how to use the Browser Agent Version Pinning API: