@dx-do/client 6.1.0 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -73446,55 +73446,54 @@ class LogsService {
73446
73446
  queryLogs(logQueryBody) {
73447
73447
  return this.dxSaasService.oiPost('oi/loganalytics/v1/api/logs/filter', logQueryBody);
73448
73448
  }
73449
- /** Ingests a single log entry into the log gateway. */
73450
- ingestLog(entry) {
73451
- return this.ingestLogs([entry]);
73452
- }
73453
73449
  /**
73454
- * Builds the enriched payload array that will be sent to the uim_logs endpoint.
73455
- * Exposed so callers can inspect the payload without sending (e.g. dry-run).
73450
+ * Builds the enriched payload object for a single log entry.
73451
+ *
73452
+ * @param options - Known log entry fields (all optional with sensible defaults).
73453
+ * @param additionalFields - Arbitrary extra fields to include in the indexed document.
73454
+ * @returns The payload object ready to POST to the uim_logs ingestion endpoint.
73456
73455
  */
73457
- buildLogPayload(entries) {
73456
+ buildLogPayload(options, additionalFields) {
73458
73457
  const cohortId = this.dxSaasService.dxdoConfiguration.dxConfiguration.cohortId;
73459
73458
  const tenantIdUpper = cohortId.toUpperCase();
73460
- const now = new Date().toISOString();
73461
- return entries.map((e) => {
73462
- const host = e.host ?? require$$0$4.hostname();
73463
- const logtype = e.logtype;
73464
- const ip = e.ip ?? detectIPv4();
73465
- const agentInstance = e.agentInstance ?? 'dx-do';
73466
- const agentName = e.agentName ?? 'Logs Collector';
73467
- const containerId = e.containerId ?? host;
73468
- const containerName = e.containerName ?? agentInstance;
73469
- const file = e.file ?? 'dx-do.cli';
73470
- const tag = `${logtype} logs`;
73471
- // temp_fields must have exactly 9 space-separated components before the message
73472
- // is appended by the SaaS filter (agentbase_msg = temp_fields + " " + message).
73473
- // The Kafka consumer parses positionally: [0]=tenant [1]=logtype [2]=host
73474
- // [3]=container_id [4]=container_name [5]=ip [6-7]=tags [8]=source_file [9+]=message.
73475
- const temp_fields = `${tenantIdUpper} ${logtype} ${host} ${containerId} ${containerName} ${ip} ${tag} ${file}`;
73476
- return {
73477
- '@timestamp': now,
73478
- // logtype must be top-level: the SaaS filter does `update => ["type", "%{logtype}"]`
73479
- // which drives Kafka consumer index routing — without it type stays as "ingestionapi"
73480
- logtype,
73481
- message: e.message ?? '',
73482
- host: { name: host, hostname: host },
73483
- tenant_id: tenantIdUpper,
73484
- temp_fields,
73485
- tags: [tag],
73486
- __agent_name: agentName,
73487
- __agent_instance: agentInstance,
73488
- container_id: containerId,
73489
- container_name: containerName,
73490
- ...Object.fromEntries(Object.entries(e).filter(([k]) => !['logtype', 'message', 'host', 'timestamp', 'ip',
73491
- 'agentInstance', 'agentName', 'containerId', 'containerName', 'file'].includes(k))),
73492
- };
73493
- });
73459
+ const logtype = options.logtype ?? 'generic';
73460
+ const host = options.host ?? require$$0$4.hostname();
73461
+ const ip = options.ip ?? detectIPv4();
73462
+ const agentInstance = options.agentInstance ?? 'dx-do';
73463
+ const agentName = options.agentName ?? 'Logs Collector';
73464
+ const containerId = options.containerId ?? host;
73465
+ const containerName = options.containerName ?? agentInstance;
73466
+ const file = options.file ?? 'dx-do.cli';
73467
+ const tag = `${logtype} logs`;
73468
+ // temp_fields must have exactly 9 space-separated components before the message
73469
+ // is appended by the SaaS filter (agentbase_msg = temp_fields + " " + message).
73470
+ // The Kafka consumer parses positionally: [0]=tenant [1]=logtype [2]=host
73471
+ // [3]=container_id [4]=container_name [5]=ip [6-7]=tags [8]=source_file [9+]=message.
73472
+ const temp_fields = `${tenantIdUpper} ${logtype} ${host} ${containerId} ${containerName} ${ip} ${tag} ${file}`;
73473
+ return {
73474
+ '@timestamp': options.timestamp ?? new Date().toISOString(),
73475
+ // logtype must be top-level: the SaaS filter does `update => ["type", "%{logtype}"]`
73476
+ // which drives Kafka consumer index routing — without it type stays as "ingestionapi"
73477
+ logtype,
73478
+ message: options.message,
73479
+ host: { name: host, hostname: host },
73480
+ tenant_id: tenantIdUpper,
73481
+ temp_fields,
73482
+ tags: [tag],
73483
+ __agent_name: agentName,
73484
+ __agent_instance: agentInstance,
73485
+ container_id: containerId,
73486
+ container_name: containerName,
73487
+ ...additionalFields,
73488
+ };
73489
+ }
73490
+ /** Ingests a single log entry into the log gateway. */
73491
+ ingestLog(options, additionalFields) {
73492
+ return this.dxSaasService.logPost('mdo/v2/aoanalytics/ingestion/uim_logs', [this.buildLogPayload(options, additionalFields)]);
73494
73493
  }
73495
73494
  /** Ingests a batch of log entries into the log gateway. */
73496
73495
  ingestLogs(entries) {
73497
- return this.dxSaasService.logPost('mdo/v2/aoanalytics/ingestion/uim_logs', this.buildLogPayload(entries));
73496
+ return this.dxSaasService.logPost('mdo/v2/aoanalytics/ingestion/uim_logs', entries.map((e) => this.buildLogPayload(e.options, e.additionalFields)));
73498
73497
  }
73499
73498
  }
73500
73499