n8n
Version:
n8n Workflow Automation Tool
88 lines • 4.43 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OtelSettingsService = exports.OTEL_SETTINGS_KEY = void 0;
const db_1 = require("@n8n/db");
const di_1 = require("@n8n/di");
const n8n_workflow_1 = require("n8n-workflow");
const otel_config_1 = require("./otel.config");
const otel_constants_1 = require("./otel.constants");
exports.OTEL_SETTINGS_KEY = 'features.otel';
let OtelSettingsService = class OtelSettingsService {
constructor(config, settingsRepository) {
this.config = config;
this.settingsRepository = settingsRepository;
this.currentSettings = null;
this.envManagedFields = [];
}
getSettings() {
if (!this.currentSettings)
throw new Error('OTel settings not yet initialized');
return { ...this.currentSettings, envManagedFields: this.envManagedFields };
}
async loadSettings() {
const persisted = await this.getPersistedSettings();
this.envManagedFields = Object.keys(otel_constants_1.OTEL_ENV_VARS).filter((key) => this.isEnvManaged(key));
this.currentSettings = this.buildConfig((key) => this.isEnvManaged(key) ? this.config[key] : (persisted?.[key] ?? this.config[key]));
return this.currentSettings;
}
async getPersistedSettings() {
const row = await this.settingsRepository.findByKey(exports.OTEL_SETTINGS_KEY);
if (!row?.value)
return undefined;
return (0, n8n_workflow_1.jsonParse)(row.value, { fallbackValue: undefined });
}
async saveSettings(incoming) {
const sanitized = this.buildConfig((key) => this.isEnvManaged(key) ? this.config[key] : incoming[key]);
const existing = await this.settingsRepository.findByKey(exports.OTEL_SETTINGS_KEY);
const value = JSON.stringify(sanitized);
if (existing) {
existing.value = value;
await this.settingsRepository.save(existing, { transaction: false });
}
else {
await this.settingsRepository.save({ key: exports.OTEL_SETTINGS_KEY, value, loadOnStartup: true }, { transaction: false });
}
}
resolveTestConnection(incoming) {
const pick = (key) => this.isEnvManaged(key) ? this.config[key] : incoming[key];
return {
exporterEndpoint: pick('exporterEndpoint'),
exporterTracingPath: pick('exporterTracingPath'),
exporterServiceName: pick('exporterServiceName'),
exporterHeaders: pick('exporterHeaders'),
startupConnectivityTimeoutMs: pick('startupConnectivityTimeoutMs'),
};
}
isEnvManaged(key) {
return process.env[otel_constants_1.OTEL_ENV_VARS[key]] !== undefined;
}
buildConfig(pick) {
return {
enabled: pick('enabled'),
exporterEndpoint: pick('exporterEndpoint'),
exporterTracingPath: pick('exporterTracingPath'),
exporterServiceName: pick('exporterServiceName'),
exporterHeaders: pick('exporterHeaders'),
tracesSampleRate: pick('tracesSampleRate'),
startupConnectivityTimeoutMs: pick('startupConnectivityTimeoutMs'),
includeNodeSpans: pick('includeNodeSpans'),
injectOutbound: pick('injectOutbound'),
productionExecutionsOnly: pick('productionExecutionsOnly'),
};
}
};
exports.OtelSettingsService = OtelSettingsService;
exports.OtelSettingsService = OtelSettingsService = __decorate([
(0, di_1.Service)(),
__metadata("design:paramtypes", [otel_config_1.OtelConfig, db_1.SettingsRepository])
], OtelSettingsService);
//# sourceMappingURL=otel-settings.service.js.map