https://www.hyperdx.io/docs/install/javascript

Node.js - HyperDX Docs

HyperDX uses the OpenTelemetry standard for collecting telemetry data (logs, metrics, traces and exceptions). Traces are auto-generated with automatic instrumentation, so manual instrumentation isn't required to get value out of tracing.

This Guide Integrates:  Logs  ·  Metrics  ·  Traces  ·  Exceptions

Getting Started Permalink for this section

Install HyperDX OpenTelemetry Instrumentation Package Permalink for this section

Use the following command to install the HyperDX OpenTelemetry package (opens in a new tab).

Initializing the SDK Permalink for this section

To initialize the SDK, you'll need to call the init function at the top of the entry point of your application.

This will automatically capture tracing, metrics, and logs from your Node.js application.

Setup Log Collection Permalink for this section

By default, console.* logs are collected by default. If you're using a logger such as winston or pino, you'll need to add a transport to your logger to send logs to HyperDX. If you're using another type of logger, reach out or explore one of our platform integrations if applicable (such as Kubernetes or Fly.io)

If you're using winston as your logger, you'll need to add the following transport to your logger.

Setup Error Collection Permalink for this section

The HyperDX SDK can automatically capture uncaught exceptions and errors in your application with full stack trace and code context. To enable this, you'll need to add the following code to the end of your application's error handling middleware, or manually capture exceptions using the recordException function.

Troubleshooting Permalink for this section

If you're having trouble with the SDK, you can enable verbose logging by setting the OTEL_LOG_LEVEL environment variable to debug.

Advanced Instrumentation Configuration Permalink for this section

Capture Console Logs Permalink for this section

By default, the HyperDX SDK will capture console logs. You can disable it by setting HDX_NODE_CONSOLE_CAPTURE environment variable to 0.

Attach User Information or Metadata Permalink for this section

To easily tag all events related to a given attribute or identifier (ex. user id or email), you can call the setTraceAttributes function which will tag every log/span associated with the current trace after the call with the declared attributes. It's recommended to call this function as early as possible within a given request/trace (ex. as early in an Express middleware stack as possible).

This is a convenient way to ensure all logs/spans are automatically tagged with the right identifiers to be searched on later, instead of needing to manually tagging and propagating identifiers yourself.

userId, 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.

Make sure to enable HyperDX beta mode by setting HDX_NODE_BETA_MODE environment variable to 1 or by passing betaMode: true to the init function to enable trace attributes.

Google Cloud Run Permalink for this section

If you're running your application on Google Cloud Run, Cloud Trace automatically injects sampling headers into incoming requests, currently restricting traces to be sampled at 0.1 requests per second for each instance.

The @hyperdx/node-opentelemetry package overwrites the sample rate to 1.0 by default.

To change this behavior, or to configure other OpenTelemetry installations, you can manually configure the environment variables OTEL_TRACES_SAMPLER=parentbased_always_on and OTEL_TRACES_SAMPLER_ARG=1 to achieve the same result.

To learn more, and to force tracing of specific requests, please refer to the Google Cloud Run documentation (opens in a new tab).

Auto-Instrumented Libraries Permalink for this section

The following libraries will be automatically instrumented (traced) by the SDK:

Alternative Installation Permalink for this section

Run the Application with HyperDX OpenTelemetry CLI Permalink for this section

Alternatively, you can auto-instrument your application without any code changes by using the opentelemetry-instrument CLI or using the Node.js --require flag. The CLI installation exposes a wider range of auto-instrumented libraries and frameworks.

HYPERDX_API_KEY='<YOUR_INGESTION_KEY>' OTEL_SERVICE_NAME='<YOUR_APP_NAME>' npx opentelemetry-instrument index.js

The OTEL_SERVICE_NAME environment variable is used to identify your service in the HyperDX app, it can be any name you want.

Enabling Exception Capturing Permalink for this section

To enable uncaught exception capturing, you'll need to set the HDX_NODE_EXPERIMENTAL_EXCEPTION_CAPTURE environment variable to 1.

Afterwards, to automatically capture exceptions from Express, Koa, or manually caught exceptions, follow the instructions in the Setup Error Collection section above.

Auto-Instrumented Libraries Permalink for this section

The following libraries will be automatically instrumented (traced) via the above installation methods:

Next.js Deno