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
| Option | Type | Default | Description |
|---|---|---|---|
service | string | OTEL_SERVICE_NAME or auto-detected | Service name reported on all telemetry. |
apiKey | string | SOPHONZ_API_KEY | API key sent as the Authorization header to the collector. |
Capture toggles
| Option | Type | Default | Description |
|---|---|---|---|
consoleCapture | boolean | true | Instrument console.* and forward calls as logs. Auto-disabled when OTEL_LOG_LEVEL=debug. |
experimentalExceptionCapture | boolean | false* | Capture uncaught exceptions and unhandled rejections. |
sentryIntegrationEnabled | boolean | false* | Enable Sentry SDK integration. |
advancedNetworkCapture | boolean | false | Capture 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
| Option | Type | Default | Description |
|---|---|---|---|
disableTracing | boolean | false | Disable trace export. |
disableLogs | boolean | false | Disable log export. |
disableMetrics | boolean | false | Disable metric export. |
detectResources | boolean | true | Auto-detect resource attributes (host, process, cloud, etc.). |
Lifecycle & diagnostics
| Option | Type | Default | Description |
|---|---|---|---|
stopOnTerminationSignals | boolean | true | Flush and shut down on SIGTERM / SIGINT. Set false to manage shutdown yourself. |
disableStartupLogs | boolean | false | Suppress the startup spinner and dashboard link. |
enableInternalProfiling | boolean | false | Log how long each instrumentation takes to patch. |
Advanced / extension
| Option | Type | Default | Description |
|---|---|---|---|
instrumentations | InstrumentationConfigMap | {} | Override or disable specific auto-instrumentations. |
additionalInstrumentations | InstrumentationBase[] | [] | Register custom instrumentations. |
excludedPaths | string[] | [] (SOPHONZ_EXCLUDED_PATHS) | Request paths that get no server span and no child spans, for health checks. See Excluded paths. |
metricReader | MetricReader | Sophonz default | Provide a custom metric reader. |
programmaticImports | boolean | false (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.
| Instrumentation | SQLCommenter |
|---|---|
@opentelemetry/instrumentation-pg | Supported |
@opentelemetry/instrumentation-mysql2 | Supported |
@opentelemetry/instrumentation-mysql | Not 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
| Variable | Default | Description |
|---|---|---|
SOPHONZ_API_KEY | — | API key for the collector. |
SOPHONZ_NODE_CONSOLE_CAPTURE | true | Enable console capture. |
SOPHONZ_NODE_ADVANCED_NETWORK_CAPTURE | false | Capture HTTP headers. |
SOPHONZ_NODE_EXPERIMENTAL_EXCEPTION_CAPTURE | false | Capture uncaught exceptions. |
SOPHONZ_NODE_SENTRY_INTEGRATION_ENABLED | false | Enable Sentry integration. |
SOPHONZ_NODE_STOP_ON_TERMINATION_SIGNALS | true | Flush on SIGTERM / SIGINT. |
SOPHONZ_NODE_BETA_MODE | false | Enable beta features (global context propagation, custom log metadata). |
SOPHONZ_NODE_ENABLE_INTERNAL_PROFILING | false | Profile instrumentation patch time. |
SOPHONZ_EXCLUDED_PATHS | — | Paths that get no server span (comma-separated). |
SOPHONZ_STARTUP_LOGS | true | Show the startup banner and dashboard link. |
OpenTelemetry
| Variable | Default | Description |
|---|---|---|
OTEL_SERVICE_NAME | auto-detected | Service name. |
OTEL_EXPORTER_OTLP_ENDPOINT | https://in.sophonz.ai | Base OTLP endpoint (traces/logs/metrics paths derived from it). |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | https://in.sophonz.ai/v1/traces | Trace export endpoint. |
OTEL_EXPORTER_OTLP_HEADERS | — | Extra OTLP headers (the API key is appended as Authorization). |
OTEL_TRACES_SAMPLER | parentbased_always_on | Trace sampler. |
OTEL_TRACES_SAMPLER_ARG | 1 | Sampler 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.