npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@launchdarkly/observability

v1.5.1

Published

Browser observability for your web app. Capture frontend metrics, errors, logs, and traces.

Readme

LaunchDarkly JavaScript Observability SDK for Browsers

NPM Actions Status NPM NPM

NB: APIs are subject to change until a 1.x version is released.

Install

Install the package

# npm
npm i @launchdarkly/observability

# yarn
yarn add @launchdarkly/observability

Update your web app entrypoint.

import { initialize } from 'launchdarkly-js-client-sdk'
import Observability, { LDObserve } from '@launchdarkly/observability'

const client = init3(
	'<CLIENT_SIDE_ID>',
	{ key: '[email protected]' },
	{
		// Not including plugins at all would be equivalent to the current LaunchDarkly SDK.
		plugins: [
			new Observability({
				networkRecording: {
					enabled: true,
					recordHeadersAndBody: true,
				},
			}),
		],
	},
)

Getting started

Refer to the SDK documentation for instructions on getting started with using the SDK.

Adding attributes to all telemetry

Use LDObserve.setAttributes to tag everything recorded afterwards with values known only after start-up, such as the campaign that brought the user in. The attributes are added to every span (including document load, fetch/XHR, click and page view spans), log, error and metric.

LDObserve.setAttributes({ utm_campaign: 'spring_promo', utm_source: 'email' })

// Later: stop sending a key. A `null` value in setAttributes does the same.
LDObserve.removeAttributes(['utm_campaign'])
  • Attributes are kept in memory for the current page load only. They are never persisted, so after a full page load, call setAttributes again (persist the values yourself if you need them to survive the load; see Keeping campaign data across a full page load).
  • UTM query parameters are captured this way automatically; see Capturing UTM and other query parameters.
  • Calls made before the SDK initializes are applied once it does.
  • Attributes passed to an individual call (log metadata, span or metric attributes) take precedence. Keys in the namespaces the SDK sets itself (highlight.*, launchdarkly.*, session.*, context.contextKeys.*) are ignored.
  • Values can be strings, numbers, booleans or arrays of those.
  • Every attribute is also added to metrics, so an attribute with many distinct values creates as many metric series.

LaunchDarkly context keys from identify (context.contextKeys.<kind>) are added to every span in the same way.

Capturing UTM and other query parameters

By default, the SDK reads the UTM parameters (utm_source, utm_medium, utm_campaign, utm_term, utm_content) from the page URL and adds the ones that are present as attributes, exactly as if you had passed them to setAttributes. A visitor landing on /?utm_campaign=spring&utm_source=email&other=x gets utm_campaign: 'spring' and utm_source: 'email' on every span (including document load, page view and fetch/XHR spans), log, error and metric for the rest of the page load, even after SPA navigation drops the query string from the URL. other is not captured.

new Observability({
	// Replace the default list. A trailing `*` matches a prefix, e.g. 'utm_*'.
	captureQueryParams: ['utm_source', 'utm_campaign', 'gclid'],
})

new Observability({ captureQueryParams: false }) // turn capture off ([] does the same)
  • Only the listed keys are captured. Other query parameters, which may hold personal data such as emails or tokens, are never recorded this way. The default list contains UTM parameters only, so check any key you add.
  • The URL is read when the SDK initializes (with manualStart, too: the values are on telemetry recorded before and after start()). Each attribute is named after its parameter.
  • Last touch: when an SPA navigation lands on a URL with any listed parameter (for example /promo?utm_campaign=fall), the captured values are replaced by that URL's values and previously captured keys it lacks are removed, so the attributes always describe one landing. The page view span of that navigation already carries the new values; spans started earlier keep theirs. A navigation without listed parameters keeps the current values.
  • Values you set with setAttributes win: capture never replaces or removes a key your app set. removeAttributes(['utm_campaign']) removes a captured value (a later landing with utm_campaign captures it again). Keys in the SDK's own namespaces are ignored.
  • Values are kept in memory for the current page load only; nothing is written to storage or cookies. A later full page load captures again from its own URL.

Keeping campaign data across a full page load

If the landing page redirects (for example through a sign-in provider) or the user reloads, the next page load has no UTM parameters. To keep them for the rest of the browser tab's life, store them yourself and set them again on loads whose URL has none:

const KEY = 'utm-attributes'
const names = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']
const params = new URLSearchParams(window.location.search)
const fromUrl = Object.fromEntries(
	names.filter((n) => params.get(n)).map((n) => [n, params.get(n)!]),
)
if (Object.keys(fromUrl).length) {
	// The SDK captures these itself; just remember them.
	sessionStorage.setItem(KEY, JSON.stringify(fromUrl))
} else {
	// Safe to call before the SDK initializes; it is applied once it does.
	LDObserve.setAttributes(JSON.parse(sessionStorage.getItem(KEY) ?? '{}'))
}

Values set this way are your app's, so a later SPA landing with new UTM parameters does not replace them. SPA landings are not stored by this snippet.

Landing referrer

By default, when the page was opened from another site, the SDK adds landing.referrer to all telemetry for the page load: the document.referrer URL with its query string, fragment and credentials stripped (origin and path only, e.g. https://www.google.com/search), so tokens or personal data in the referring URL are not recorded. A same-origin or empty referrer sets nothing, and the value is not updated on SPA navigation. Turn it off with captureReferrer: false.

Session continuity

A session continues across full page loads on the same origin until it has been idle for 15 minutes; a full page load on a different origin starts a new session.

When a full page load starts a new session instead of continuing the stored one (for example, because it has been idle past the timeout), the new session's telemetry carries session.previous_id: the ID of the session it replaced. Use it to chain related sessions in analysis, for example to join events before and after a long idle gap.

Session storage options:

  • sessionCookie: true — also store the session in a cookie (expiring 15 minutes after it is last written). This can help with cookie-consent compliance.
  • sessionCookieDomain: 'example.com' — set the session cookie's Domain attribute so the session can be continued across your subdomains (e.g. app.example.com and checkout.example.com). Requires sessionCookie: true. By default, the cookie is scoped to the exact host that created it.
  • storageMode: 'sessionStorage' — keep the session in sessionStorage instead of localStorage, so each tab has its own session and closing the tab ends it.

Continuing a session across domains

Storage is per-origin, so a flow that moves a user from one of your domains to another (for example from a landing site, through a hosted identity provider, to your app on a different domain) starts a new session on the second domain. To link the two, generate a sessionKey on the first domain, pass it to the SDK there, carry it through the redirect (for example in the OAuth state parameter), and pass the same value to the SDK on the second domain. When no unexpired session exists yet, the SDK derives the session ID from the sessionKey, so both domains report the same session.

// First domain, before redirecting:
const sessionKey = crypto.randomUUID()
new Observability({ sessionKey })

// Second domain, after reading the key back from the OAuth `state`:
new Observability({ sessionKey: keyFromState })

Only pass keys you generate and control: anyone who knows a sessionKey can continue that session.

The @launchdarkly/session-replay SDK accepts the same options.

Verifying SDK build provenance with the SLSA framework

LaunchDarkly uses the SLSA framework (Supply-chain Levels for Software Artifacts) to help developers make their supply chain more secure by ensuring the authenticity and build integrity of our published SDK packages. To learn more, see the provenance guide.

About LaunchDarkly

  • LaunchDarkly Observability provies a way to collect and send errors, logs, traces to LaunchDarkly. Correlate latency or exceptions with your releases to safely ship code.
  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan).
    • Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read our documentation for a complete list.
  • Explore LaunchDarkly