@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.esm.js CHANGED
@@ -73424,55 +73424,54 @@ class LogsService {
73424
73424
  queryLogs(logQueryBody) {
73425
73425
  return this.dxSaasService.oiPost('oi/loganalytics/v1/api/logs/filter', logQueryBody);
73426
73426
  }
73427
- /** Ingests a single log entry into the log gateway. */
73428
- ingestLog(entry) {
73429
- return this.ingestLogs([entry]);
73430
- }
73431
73427
  /**
73432
- * Builds the enriched payload array that will be sent to the uim_logs endpoint.
73433
- * Exposed so callers can inspect the payload without sending (e.g. dry-run).
73428
+ * Builds the enriched payload object for a single log entry.
73429
+ *
73430
+ * @param options - Known log entry fields (all optional with sensible defaults).
73431
+ * @param additionalFields - Arbitrary extra fields to include in the indexed document.
73432
+ * @returns The payload object ready to POST to the uim_logs ingestion endpoint.
73434
73433
  */
73435
- buildLogPayload(entries) {
73434
+ buildLogPayload(options, additionalFields) {
73436
73435
  const cohortId = this.dxSaasService.dxdoConfiguration.dxConfiguration.cohortId;
73437
73436
  const tenantIdUpper = cohortId.toUpperCase();
73438
- const now = new Date().toISOString();
73439
- return entries.map((e) => {
73440
- const host = e.host ?? hostname();
73441
- const logtype = e.logtype;
73442
- const ip = e.ip ?? detectIPv4();
73443
- const agentInstance = e.agentInstance ?? 'dx-do';
73444
- const agentName = e.agentName ?? 'Logs Collector';
73445
- const containerId = e.containerId ?? host;
73446
- const containerName = e.containerName ?? agentInstance;
73447
- const file = e.file ?? 'dx-do.cli';
73448
- const tag = `${logtype} logs`;
73449
- // temp_fields must have exactly 9 space-separated components before the message
73450
- // is appended by the SaaS filter (agentbase_msg = temp_fields + " " + message).
73451
- // The Kafka consumer parses positionally: [0]=tenant [1]=logtype [2]=host
73452
- // [3]=container_id [4]=container_name [5]=ip [6-7]=tags [8]=source_file [9+]=message.
73453
- const temp_fields = `${tenantIdUpper} ${logtype} ${host} ${containerId} ${containerName} ${ip} ${tag} ${file}`;
73454
- return {
73455
- '@timestamp': now,
73456
- // logtype must be top-level: the SaaS filter does `update => ["type", "%{logtype}"]`
73457
- // which drives Kafka consumer index routing — without it type stays as "ingestionapi"
73458
- logtype,
73459
- message: e.message ?? '',
73460
- host: { name: host, hostname: host },
73461
- tenant_id: tenantIdUpper,
73462
- temp_fields,
73463
- tags: [tag],
73464
- __agent_name: agentName,
73465
- __agent_instance: agentInstance,
73466
- container_id: containerId,
73467
- container_name: containerName,
73468
- ...Object.fromEntries(Object.entries(e).filter(([k]) => !['logtype', 'message', 'host', 'timestamp', 'ip',
73469
- 'agentInstance', 'agentName', 'containerId', 'containerName', 'file'].includes(k))),
73470
- };
73471
- });
73437
+ const logtype = options.logtype ?? 'generic';
73438
+ const host = options.host ?? hostname();
73439
+ const ip = options.ip ?? detectIPv4();
73440
+ const agentInstance = options.agentInstance ?? 'dx-do';
73441
+ const agentName = options.agentName ?? 'Logs Collector';
73442
+ const containerId = options.containerId ?? host;
73443
+ const containerName = options.containerName ?? agentInstance;
73444
+ const file = options.file ?? 'dx-do.cli';
73445
+ const tag = `${logtype} logs`;
73446
+ // temp_fields must have exactly 9 space-separated components before the message
73447
+ // is appended by the SaaS filter (agentbase_msg = temp_fields + " " + message).
73448
+ // The Kafka consumer parses positionally: [0]=tenant [1]=logtype [2]=host
73449
+ // [3]=container_id [4]=container_name [5]=ip [6-7]=tags [8]=source_file [9+]=message.
73450
+ const temp_fields = `${tenantIdUpper} ${logtype} ${host} ${containerId} ${containerName} ${ip} ${tag} ${file}`;
73451
+ return {
73452
+ '@timestamp': options.timestamp ?? new Date().toISOString(),
73453
+ // logtype must be top-level: the SaaS filter does `update => ["type", "%{logtype}"]`
73454
+ // which drives Kafka consumer index routing — without it type stays as "ingestionapi"
73455
+ logtype,
73456
+ message: options.message,
73457
+ host: { name: host, hostname: host },
73458
+ tenant_id: tenantIdUpper,
73459
+ temp_fields,
73460
+ tags: [tag],
73461
+ __agent_name: agentName,
73462
+ __agent_instance: agentInstance,
73463
+ container_id: containerId,
73464
+ container_name: containerName,
73465
+ ...additionalFields,
73466
+ };
73467
+ }
73468
+ /** Ingests a single log entry into the log gateway. */
73469
+ ingestLog(options, additionalFields) {
73470
+ return this.dxSaasService.logPost('mdo/v2/aoanalytics/ingestion/uim_logs', [this.buildLogPayload(options, additionalFields)]);
73472
73471
  }
73473
73472
  /** Ingests a batch of log entries into the log gateway. */
73474
73473
  ingestLogs(entries) {
73475
- return this.dxSaasService.logPost('mdo/v2/aoanalytics/ingestion/uim_logs', this.buildLogPayload(entries));
73474
+ return this.dxSaasService.logPost('mdo/v2/aoanalytics/ingestion/uim_logs', entries.map((e) => this.buildLogPayload(e.options, e.additionalFields)));
73476
73475
  }
73477
73476
  }
73478
73477