Configuration

Full reference for Sophonz Node.js SDK configuration — SDKConfig options for init()/initSDK() and the SOPHONZ_* / OTEL_* environment variables.

The SDK is configured through SDKConfig options passed to init() / initSDK(), or through environment variables. Options always take precedence over environment variables; environment variables are the fallback (and the only way to configure the preload binary).

init() vs initSDK()

import { init, initSDK } from '@sophonz/node-sdk';
  • init(config?) — recommended entry point. Applies Sophonz defaults (consoleCapture: true, experimentalExceptionCapture: true, sentryIntegrationEnabled: true, programmaticImports: true) and merges your overrides on top.
  • initSDK(config) — lower-level. Applies only the documented per-option defaults below, with no extra opinionated toggles. Use it when you want full control.

NOTE — programmaticImports

init() enables programmaticImports, which re-patches instrumentations after sdk.start(). This makes auto-instrumentation work even when your modules were already imported (common with bundlers and TypeScript transpilation). initSDK() leaves it off unless you set it.

SDKConfig options

Core

OptionTypeDefaultDescription
servicestringOTEL_SERVICE_NAME or auto-detectedService name reported on all telemetry.
apiKeystringSOPHONZ_API_KEYAPI key sent as the Authorization header to the collector.

Capture toggles

OptionTypeDefaultDescription
consoleCapturebooleantrueInstrument console.* and forward calls as logs. Auto-disabled when OTEL_LOG_LEVEL=debug.
experimentalExceptionCapturebooleanfalse*Capture uncaught exceptions and unhandled rejections.
sentryIntegrationEnabledbooleanfalse*Enable Sentry SDK integration.
advancedNetworkCapturebooleanfalseCapture HTTP request/response headers (configured via OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_*).

NOTE — * Defaults differ between init() and initSDK()

experimentalExceptionCapture and sentryIntegrationEnabled default to false in initSDK(), but init() turns them on. The table lists the underlying initSDK() default.

Signal toggles

OptionTypeDefaultDescription
disableTracingbooleanfalseDisable trace export.
disableLogsbooleanfalseDisable log export.
disableMetricsbooleanfalseDisable metric export.
detectResourcesbooleantrueAuto-detect resource attributes (host, process, cloud, etc.).

Lifecycle & diagnostics

OptionTypeDefaultDescription
stopOnTerminationSignalsbooleantrueFlush and shut down on SIGTERM / SIGINT. Set false to manage shutdown yourself.
disableStartupLogsbooleanfalseSuppress the startup spinner and dashboard link.
enableInternalProfilingbooleanfalseLog how long each instrumentation takes to patch.

Advanced / extension

OptionTypeDefaultDescription
instrumentationsInstrumentationConfigMap{}Override or disable specific auto-instrumentations.
additionalInstrumentationsInstrumentationBase[][]Register custom instrumentations.
excludedPathsstring[][] (SOPHONZ_EXCLUDED_PATHS)Request paths that get no server span and no child spans, for health checks. See Excluded paths.
metricReaderMetricReaderSophonz defaultProvide a custom metric reader.
programmaticImportsbooleanfalse (true via init())Re-patch instrumentations after start so already-imported modules are instrumented.

Example

import { initSDK } from '@sophonz/node-sdk';
 
initSDK({
  service: 'checkout-api',
  apiKey: process.env.SOPHONZ_API_KEY,
  consoleCapture: true,
  experimentalExceptionCapture: true,
  advancedNetworkCapture: true,
  disableMetrics: false,
  instrumentations: {
    // disable a noisy auto-instrumentation
    '@opentelemetry/instrumentation-fs': { enabled: false },
  },
});

Database query tracing

pg and mysql2 are instrumented automatically, so query spans are produced without any configuration. Those spans, however, only cover what the application observed. Extending the same trace into the database's query plan requires sending a W3C traceparent with the query, and SQLCommenter, which does that, is disabled by default.

init({
  service: 'checkout-api',
  apiKey: process.env.SOPHONZ_API_KEY,
  instrumentations: {
    '@opentelemetry/instrumentation-pg': {
      addSqlCommenterCommentToQueries: true,
    },
  },
});

Once enabled, every statement carries the trace context as a trailing comment.

SELECT id, email FROM users WHERE id = $1; /*traceparent='00-d4cda95b652f4a1592b449d5929fda1b-6e0c63257de34c92-01'*/

Support varies by instrumentation.

InstrumentationSQLCommenter
@opentelemetry/instrumentation-pgSupported
@opentelemetry/instrumentation-mysql2Supported
@opentelemetry/instrumentation-mysqlNot supported

For the database to read the comment and produce server-side spans, PostgreSQL needs the pg_tracing extension. See Self-hosted PostgreSQL. Without the extension the comment is still recorded in the database log, which is what later joins those logs to the trace.

CAUTION — Named prepared statements

The trace ID in the comment differs per query, so the statement text changes every time. Where statements are named and reused, this can reduce cache effectiveness. It does not apply where statements are unnamed.

Excluded paths

A request to a path listed in excludedPaths gets no server span, and no child spans are started from it. Use it to keep health checks that arrive every few seconds, such as Kubernetes probes, out of your traces. Available from @sophonz/node-sdk 0.2.10.

import { init } from '@sophonz/node-sdk';
 
init({ excludedPaths: ['/health', '/ready'] });

To set it in your deployment, use the environment variable.

SOPHONZ_EXCLUDED_PATHS=/health,/ready
  • Each entry is an exact path. The leading slash is optional and the query string is ignored.
  • Without the option the environment variable is used; with neither, no path is excluded.

Environment variables

Sophonz-specific

VariableDefaultDescription
SOPHONZ_API_KEY—API key for the collector.
SOPHONZ_NODE_CONSOLE_CAPTUREtrueEnable console capture.
SOPHONZ_NODE_ADVANCED_NETWORK_CAPTUREfalseCapture HTTP headers.
SOPHONZ_NODE_EXPERIMENTAL_EXCEPTION_CAPTUREfalseCapture uncaught exceptions.
SOPHONZ_NODE_SENTRY_INTEGRATION_ENABLEDfalseEnable Sentry integration.
SOPHONZ_NODE_STOP_ON_TERMINATION_SIGNALStrueFlush on SIGTERM / SIGINT.
SOPHONZ_NODE_BETA_MODEfalseEnable beta features (global context propagation, custom log metadata).
SOPHONZ_NODE_ENABLE_INTERNAL_PROFILINGfalseProfile instrumentation patch time.
SOPHONZ_EXCLUDED_PATHS—Paths that get no server span (comma-separated).
SOPHONZ_STARTUP_LOGStrueShow the startup banner and dashboard link.

OpenTelemetry

VariableDefaultDescription
OTEL_SERVICE_NAMEauto-detectedService name.
OTEL_EXPORTER_OTLP_ENDPOINThttps://in.sophonz.aiBase OTLP endpoint (traces/logs/metrics paths derived from it).
OTEL_EXPORTER_OTLP_TRACES_ENDPOINThttps://in.sophonz.ai/v1/tracesTrace export endpoint.
OTEL_EXPORTER_OTLP_HEADERS—Extra OTLP headers (the API key is appended as Authorization).
OTEL_TRACES_SAMPLERparentbased_always_onTrace sampler.
OTEL_TRACES_SAMPLER_ARG1Sampler argument.
OTEL_LOG_LEVEL—SDK diagnostics log level (debug disables console capture).
OTEL_LOGS_EXPORTER / OTEL_TRACES_EXPORTER / OTEL_METRICS_EXPORTER—Set to none to disable a signal.

TIP — Precedence

A disableLogs / disableTracing / disableMetrics option, or setting the matching OTEL_*_EXPORTER=none, both turn a signal off. Explicit SDKConfig options win when both are present.