docs/docs/reference/core-plugins/telemetry-plugin/get-sdk-configuration.mdx
Creates a configuration object for the OpenTelemetry Node SDK. This is used to set up a custom
preload script which must be run before the main Vendure server is loaded by means of the
Node.js --require flag.
The default instrumentations array covers the libraries Vendure itself uses: HTTP, Express,
NestJS, GraphQL, the PostgreSQL and MySQL2 database drivers, ioredis, plus Node.js runtime
metrics (event-loop lag, GC pause, heap, CPU). SQLite (better-sqlite3) has no OpenTelemetry
instrumentation available upstream and is therefore not covered. To capture spans from other
libraries used in your own plugins (for example kafkajs, mongoose, winston), install the
specific @opentelemetry/instrumentation-* package you need and extend the defaults via
getDefaultInstrumentations():
import { getDefaultInstrumentations, getSdkConfiguration } from '@vendure/telemetry-plugin/preload';
import { KafkaJsInstrumentation } from '@opentelemetry/instrumentation-kafkajs';
const config = getSdkConfiguration({
config: {
instrumentations: [...getDefaultInstrumentations(), new KafkaJsInstrumentation()],
},
});
Passing your own instrumentations via config.instrumentations replaces the curated default
entirely.
Example
// instrumentation.ts
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-proto';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { getSdkConfiguration } from '@vendure/telemetry-plugin/preload';
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://localhost:3100/otlp';
process.env.OTEL_LOGS_EXPORTER = 'otlp';
process.env.OTEL_RESOURCE_ATTRIBUTES = 'service.name=vendure-dev-server';
const traceExporter = new OTLPTraceExporter({
url: 'http://localhost:4318/v1/traces',
});
const logExporter = new OTLPLogExporter();
const config = getSdkConfiguration({
config: {
spanProcessors: [new BatchSpanProcessor(traceExporter)],
logRecordProcessors: [new BatchLogRecordProcessor(logExporter)],
},
});
const sdk = new NodeSDK(config);
sdk.start();
This would them be run as:
node --require ./dist/instrumentation.js ./dist/server.js
function getSdkConfiguration(options?: SdkConfigurationOptions): Partial<NodeSDKConfiguration>
Parameters
<MemberInfo kind="parameter" type={<a href='/reference/core-plugins/telemetry-plugin/get-sdk-configuration#sdkconfigurationoptions'>SdkConfigurationOptions</a>} />
Returns a fresh array of the OpenTelemetry instrumentations Vendure enables by default. Callers
can spread this into their own instrumentations array to add extra integrations without
losing the curated set.
function getDefaultInstrumentations(): NonNullable<NodeSDKConfiguration['instrumentations']>
Options for configuring the OpenTelemetry Node SDK.
interface SdkConfigurationOptions {
logToConsole?: boolean;
config: Partial<NodeSDKConfiguration>;
}
<MemberInfo kind="property" type={boolean} default={false} />
When set to true, the SDK will log spans to the console instead of sending them to an
exporter. This should just be used for debugging purposes.
<MemberInfo kind="property" type={Partial<NodeSDKConfiguration>} />
The configuration object for the OpenTelemetry Node SDK.
</div>