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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hyperdx/browser

v0.21.2

Published

### Install

Downloads

15,585

Readme

Getting Started

Install

npm install @hyperdx/browser

Initialize HyperDX

import HyperDX from '@hyperdx/browser';

HyperDX.init({
  apiKey: '<YOUR_API_KEY_HERE>',
  service: 'my-frontend-app',
  tracePropagationTargets: [/api.myapp.domain/i], // Set to link traces from frontend to backend requests
  consoleCapture: true, // Capture console logs (default false)
  advancedNetworkCapture: true, // Capture full HTTP request/response headers and bodies (default false)
});

Options

  • apiKey - Your HyperDX Ingestion API Key.
  • service - The service name events will show up as in HyperDX.
  • tracePropagationTargets - A list of regex patterns to match against HTTP requests to link frontend and backend traces, it will add an additional traceparent header to all requests matching any of the patterns. This should be set to your backend API domain (ex. api.yoursite.com).
  • consoleCapture - (Optional) Capture all console logs (default false).
  • advancedNetworkCapture - (Optional) Capture full request/response headers and bodies (default false).
  • url - (Optional) The OpenTelemetry collector URL, only needed for self-hosted instances.
  • maskAllInputs - (Optional) Whether to mask all input fields in session replay (default false).
  • maskAllText - (Optional) Whether to mask all text in session replay (default false).
  • disableIntercom - (Optional) Whether to disable Intercom integration (default false)
  • disableReplay - (Optional) Whether to disable session replay (default false)
  • recordCanvas - (Optional) Whether to record canvas elements (default false)
  • sampling - (Optional) The sampling config in the session recording

Additional Configuration

Attach User Information or Metadata

Attaching user information will allow you to search/filter sessions and events in HyperDX. This can be called at any point during the client session. The current client session and all events sent after the call will be associated with the user information.

userEmail, userName, and teamName will populate the sessions UI with the corresponding values, but can be omitted. Any other additional values can be specified and used to search for events.

HyperDX.setGlobalAttributes({
  userId: user.id,
  userEmail: user.email,
  userName: user.name,
  teamName: user.team.name,
  // Other custom properties...
});

Auto Capture React Error Boundary Errors

If you're using React, you can automatically capture errors that occur within React error boundaries by passing your error boundary component into the attachToReactErrorBoundary function.

// Import your ErrorBoundary (we're using react-error-boundary as an example)
import { ErrorBoundary } from 'react-error-boundary';

// This will hook into the ErrorBoundary component and capture any errors that occur
// within any instance of it.
HyperDX.attachToReactErrorBoundary(ErrorBoundary);

Send Custom Actions

To explicitly track a specific application event (ex. sign up, submission, etc.), you can call the addAction function with an event name and optional event metadata.

Example:

HyperDX.addAction('Form-Completed', {
  formId: 'signup-form',
  formName: 'Signup Form',
  formType: 'signup',
});

Enable Network Capture Dynamically

To enable or disable network capture dynamically, simply invoke the enableAdvancedNetworkCapture or disableAdvancedNetworkCapture function as needed.

HyperDX.enableAdvancedNetworkCapture();

Stop/Resume Session Recorder Dynamically

To stop or resume session recording dynamically, simply invoke the resumeSessionRecorder or stopSessionRecorder function as needed.

HyperDX.resumeSessionRecorder();

Enable Resource Timing for CORS Requests

If your frontend application makes API requests to a different domain, you can optionally enable the Timing-Allow-Origin header to be sent with the request. This will allow HyperDX to capture fine-grained resource timing information for the request such as DNS lookup, response download, etc. via PerformanceResourceTiming.

If you're using express with cors packages, you can use the following snippet to enable the header:

var cors = require('cors');
var onHeaders = require('on-headers');

// ... all your stuff

app.use(function (req, res, next) {
  onHeaders(res, function () {
    var allowOrigin = res.getHeader('Access-Control-Allow-Origin');
    if (allowOrigin) {
      res.setHeader('Timing-Allow-Origin', allowOrigin);
    }
  });
  next();
});
app.use(cors());

Retrieve Session ID

To retrieve the current session ID, you can call the getSessionId function.

const sessionId = HyperDX.getSessionId();