OpenFn / OpenFn/lightning

Inspector: Log arrays are getting flattened

Open
#2,332 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Elixir
Stars
296
Forks
86
Avg merge
1d 13h
Merged PRs (30d)
50

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the named log-viewer/store.tryPrettyJSON entry point and reproduce the issue with the provided console.log([22]) example. Trace the message from the Worker through the Phoenix websocket and identify where the outer array loses its brackets; done means the viewer displays JOB [22] while preserving arrays nested in objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir, javascript
Domain
backend, observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.