OpenFn / lightning

OpenFn/Lightning ⚡️ is the newest version of the OpenFn DPG and provides a web UI to visually manage complex workflow automation projects.
https://openfn.github.io/lightning/
GNU Lesser General Public License v3.0
127 stars 35 forks source link

Inspector: Log arrays are getting flattened #2332

Open josephjclark opened 2 months ago

josephjclark commented 2 months ago

We've noticed some strange behaviour in the Lightning log viewer where items in arrays are not pretty printed.

In fact,the logger seems to entirely ignore arrays.

Repro

Run this against common in lightning:

fn((s) => {
  console.log([22])
  return s 
})

The logs say:

JOB 22

But they SHOULD say:

JOB [22]

Note that an array inside an object is fine:

JOB {
  "a": [
    22
  ]
}

Worker output

The object going out of the Worker contains a message array (because console.log(a,b,c) lets you log multiple things). This in turn contains a single item, itself an array.

I can see this in my Javascript debugger immediately before it's sent to the phoenix web socket:

{
  run_id: "c586f444-2a2f-465b-adca-b920845ec42e",
  message: [
    [
      224,
    ],
  ],
  source: "JOB",
  level: "info",
  timestamp: "1721916937859619",
}

So I'm pretty sure this isn't a worker issue.

So what's up?

Adding a breakpoint to log-viewer/store.tryPrettyJSON, I can see that the message comes as a flat string - 22 not [22]. So the logger won't try and pretty print it or anything.

It looks to me like the messages array is getting stringified and flattened?

taylordowns2000 commented 2 months ago

I think, @josephjclark , that lightning initially expected an array of strings or objects as the basic unit of logs from the worker. This might explain the behaviour we're seeing now.

@stuartc , do you remember/know what might be causing this?