Configuration for client-side observability
Configuration for client-side observability
Configuration for client-side observability
This topic explains how to configure the observability plugin for client-side SDKs.
The observability plugin collects and sends observability data to LaunchDarkly, so you can review error monitoring, logs, traces, and more from within the LaunchDarkly UI.
To get started with the observability plugin, read the observability reference guide for your SDK. Use the docs site navigation on the left, or find your SDK under Observability SDKs.
Details about each SDK’s configuration are available in the SDK-specific sections below:
This feature is available in the observability plugin for the following client-side SDKs:
To specify the observability plugin configuration options, use Options for the plugin.
Here’s how:
For a complete list of configuration options, read Configuration.
To specify the observability plugin configuration options, use Options for the plugin.
Here’s how:
For a complete list of configuration options, read Options javadoc.
The observability plugin supports the following configuration options. After you initialize the SDK, you can set these when you configure the observability plugin options. Then, you can access the related features from within your application.
By default, the observability plugin shows you all the network request durations, response codes, and sizes for a session.
You can configure the options for the observability plugin to additionally record the headers and bodies of network requests and responses. Then, provide these options when you initialize the SDK client.
Here’s how to construct the options object:
By default, the plugin does not record the following headers:
AuthorizationCookieProxy-AuthorizationTo redact other headers, set networkRecording.networkHeadersToRedact. To redact specific keys in the request/response body, set networkRecording.networkBodyKeysToRedact. Alternatively, you can use an allowlist, and set networkRecording.headerKeysToRecord and networkRecording.bodyKeysToRecord.
By default, the plugins do not record the following URLs:
https://www.googleapis.com/identitytoolkithttps://securetoken.googleapis.comTo redact other URLs, for example if you have APIs that you know will always return secrets in their headers, body, or both, add the option urlBlocklist to your plugin options and set it to a list of URLs:
If none of these options are specific enough, you can write your own method to sanitize network responses. Define a networkRecording.requestResponseSanitizer function that receives a request/response pair and returns either null, if you want to drop the request entirely, or a sanitized request/response pair. We do not recommend dropping requests completely unless absolutely necessary, as it can cause issues with debugging due to the missing requests. Instead, we recommend deleting or redacting header and body fields in your requestResponseSanitizer function.
When networkRecording.recordHeadersAndBody is true, the plugins record all of the WebSocket events in your sessions, including opening a connection, sending and receiving messages, receiving an error, and closing a connection.
To disable WebSocket events, but keep recording the headers and bodies of network requests, set networkRecording.disableWebSocketEventRecordings to true.
By default, the plugins show the console messages that were logged during a session.
To disable console recording, set disableConsoleRecording to true when you configure the plugin options for either the observability plugin or the session replay plugin.
If you are not seeing console logs in your session recordings, ensure that disableConsoleRecording is set to false in your plugin options.
To specify which console methods to record, set consoleMethodsToRecord.
If your sessions or errors are not appearing in LaunchDarkly, it may be that requests to LaunchDarkly are being blocked. This may be happening for any of several reasons, including third-party browser extensions, browser configuration, or VPN settings.
If you have access to your domain’s DNS settings, you can set up a proxy from your domain to LaunchDarkly to avoid having requests blocked.
Here’s how:
On your domain, add two CNAME records:
CNAME record that points pub.ld.<your_domain> to pub.observability.app.launchdarkly.comCNAME record that points otel.ld.<your_domain> to otel.observability.app.launchdarkly.comTogether, these records mean that if you have an app running at <your_domain>, your DNS records will point pub.ld.<your_domain> and otel.ld.<your_domain> to the LaunchDarkly servers.
In your application, set the backendUrl and otel options when you configure the observability plugin.
backendUrl option to pub.ld.<your_domain>otel option to otel.ld.<your_domain>Here’s how:
We recommend instrumenting your application so that you can attribute frontend requests with backend errors and logs.
To do this, set following plugin options:
tracingOrigins:
traceparent HTTP header that propagates the trace context, allowing server-side tracing and logging to associate its data with the frontend trace.true to include all domains and subdomains of the URL for your frontend application.https://backend.example.com/api, set the value to ['backend.example.com/api'].networkRecording:
enabled to truerecordHeadersAndBody to trueHere’s how:
When you configure the plugin options, you can optionally set a version field. The version is then included in the error and session views in the LaunchDarkly UI.
This version field is configured manually, and is separate from any versions that may be set if you configure automatic environment attributes in the LaunchDarkly SDK.
To specify the observability plugin configuration options, use the ReactNativeOptions interface to set the options.
Here’s how:
For a complete list of configuration options, read ReactNativeOptions.
Configuring the observability plugin in the React Web SDK follows the examples given for the JavaScript SDK.
Configuring the observability plugin in the Vue SDK follows the examples given for the JavaScript SDK.
When the observability plugin runs, it monkey patches browser APIs in order to record errors, console messages, network requests, and changes on the page.
The observability plugin patches browser APIs in the following order:
DocumentLoadInstrumentation tracks document and resource load timingsUserInteractionInstrumentation patches addEventListener, removeEventListener, and History API methodsLocationChangeInstrumentation tracks page view changesFetchInstrumentation patches window.fetch for network request monitoringXMLHttpRequestInstrumentation patches XMLHttpRequest for network request monitoringBecause the plugin wraps native browser APIs, the order in which you initialize the LaunchDarkly observability plugin relative to other monitoring tools matters. Other tools that also monkey patch browser APIs, such as Datadog RUM, Sentry, New Relic, or AppDynamics, can conflict if they wrap the same APIs.
To avoid conflicts, initialize the LaunchDarkly observability plugin before other monitoring or error tracking scripts. When multiple tools patch the same API (for example, window.fetch), the last tool to patch it wraps the previous tool’s wrapper, creating a chain. If a later tool replaces the function entirely rather than wrapping it, earlier patches are lost.
If you experience issues with missing network requests, duplicated console logs, or incomplete traces, check for conflicts with the following commonly patched APIs:
window.fetch and XMLHttpRequest are also patched by Datadog RUM, Sentry, New Relic Browser, and AppDynamicsconsole.* methods are also patched by Sentry, Datadog, and LogRocketaddEventListener / removeEventListener are also patched by Zone.js (Angular), Datadog RUM, and New Relichistory.pushState / history.replaceState are also patched by Datadog RUM, Sentry, and most SPA routing trackersIf you use Angular with Zone.js, the observability plugin detects Zone.js and patches zone.runTask, scheduleTask, and cancelTask for more accurate async task tracking.
If you cannot control the initialization order, you can disable specific recording features using plugin options. For example, set disableConsoleRecording to true if another tool is already capturing console output.
Here is a list of the browser APIs that the LaunchDarkly observability plugins may monkey patch:
window.sessionStorage.setItemwindow.sessionStorage.getItemwindow.sessionStorage.removeItemwindow.onerrorwindow.fetchwindow.FontFacewindow.scrollwindow.scrollTowindow.scrollBywindow.scrollIntoViewwindow.WebGLRenderingContextwindow.WebGL2RenderingContextwindow.CanvasRenderingContext2Dwindow.HTMLCanvasElementwindow.CSSStyleSheet.prototype.insertRulewindow.CSSStyleSheet.prototype.deleteRulewindow.CSSGroupingRulewindow.CSSMediaRulewindow.CSSConditionRulewindow.CSSSupportsRulewindow.CSSStyleDeclaration.prototype.setPropertywindow.CSSStyleDeclaration.prototype.removePropertyhistory.pushStatehistory.replaceStateXMLHttpRequest.prototype.openXMLHttpRequest.prototype.setRequestHeaderXMLHttpRequest.prototype.sendconsole.assertconsole.clearconsole.countconsole.countResetconsole.debugconsole.dirconsole.dirxmlconsole.errorconsole.groupconsole.groupCollapsedconsole.groupEndconsole.infoconsole.logconsole.tableconsole.timeconsole.timeEndconsole.timeLogconsole.traceconsole.warn