in packages/synthetics-sdk-api/src/auto_instrumentation.ts [89:135]
constructor(args: { googleAuthOptions?: GoogleAuthOptions } = {}) {
this.authArgs = args.googleAuthOptions || {};
this.provider = new NodeTracerProvider({
sampler: new AlwaysOnSampler(),
});
const exporter = new TraceExporter();
this.provider.addSpanProcessor(new BatchSpanProcessor(exporter));
this.provider.register();
// add node auto instrumentation
registerInstrumentations({
instrumentations: [
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-winston': {
logHook: (span: Span, record: Record<string, string | boolean>) => {
// If the auto instrumentation has detected a project id, convert
// otel fields that are automatically added to the record to use
// structured logging fields instead.
if (this.gcpProjectId) {
record[LOGGING_TRACE_KEY] = `projects/${
this.gcpProjectId
}/traces/${span.spanContext().traceId}`;
record[LOGGING_SPAN_KEY] = span.spanContext().spanId;
record[LOGGING_SAMPLED_KEY] =
span.spanContext().traceFlags === TraceFlags.SAMPLED;
record[LOGGING_SEVERITY_KEY] =
levelToSeverityMap[String(record.level)] ?? 'DEFAULT';
delete record['span_id'];
delete record['trace_flags'];
delete record['level'];
delete record['trace_id'];
}
},
},
}),
],
});
// Require dependencies after instrumentation is registered,
// otherwise they wont be instrumented.
const winston = require('winston');
const logger = winston.createLogger({
transports: [new winston.transports.Console()],
});
this.logger = logger;
}