Fork me on GitHub
#portal
<
2023-07-20
>
Steven Lombardi18:07:16

I find myself very often copy-pasting EDN from my console to Portal. But given that my EDN often has functions in it, the copy-paste routinely fails. I've worked around it by doing something like this manually:

(defn datafy-copied-edn
  [copied-edn-str]
  (clojure.edn/read-string {:readers {'function identity}} copied-edn-str))
And then tapping the result to Portal. But is there room for Portal to make some more assumptions so copy-paste can work out of the box?

djblue18:07:35

Yeah, making things easier would be nice. Do you have an example of what the edn looks like?

djblue05:08:29

@U02GSTHEX3M Following up on what type of edn strings caused issues for you 🙏

Steven Lombardi18:08:57

Sorry for letting this hang in limbo. Here are some details that will likely be useful.

Steven Lombardi18:08:18

To reproduce the limitation (not necessarily a bug), log a data structure using a logging library of your choice. Be sure it has a function attached to it:

(log/info "Test: " {:key1 "val1" :key2 (constantly :val2)})
Then copy the data structure to the clipboard and paste it into portal. You'll get an error:
Invalid symbol: clojure.core/constantly/fn--5740.

Steven Lombardi18:08:44

It's worth noting that attempting to tap> the output causes an error too, so you can't use that as a workaround:

(tap> {:key1 "val1", :key2 #function[clojure.core/constantly/fn--5740]})
; Syntax error reading source at (REPL:9570:71).
; No reader function for tag function

Steven Lombardi18:08:41

One sort of workaround I've identified is with a helper function like this, but it requires the data be a string which is not ergonomic at all, since you have manually tweak the data tediously (escaping quotes, etc) to get it to work.

(defn datafy-copied-edn
  [copied-edn-str]
  (clojure.edn/read-string {:readers {'function identity}} copied-edn-str))

Steven Lombardi18:08:27

The alternative is to update all logging sites to make the data a string...

clj꞉cis.sm-customer-stream.roundtrip-test꞉> 
(str {:key1 "val1" :key2 (constantly :val2)})
"{:key1 \"val1\", :key2 #function[clojure.core/constantly/fn--5740]}"
clj꞉cis.sm-customer-stream.roundtrip-test꞉> 
(datafy-copied-edn *1)
{:key1 "val1", :key2 [clojure.core/constantly/fn--5740]}
...but that make retargeting logs to portal almost pointless because the data isn't rich and explorable anymore.

Steven Lombardi18:08:56

So the question here is how to improve portal's ergonomics so that you can copy paste data from logs into portal to get a rich representation on-demand. We tend to have very large maps full of context/functions/other data so its very helpful to selectively move stuff to portal for more detailed inspection.

Steven Lombardi18:08:21

The answer might be that we just need to filter out our functions from our context map before logging. But maybe it makes sense for portal to do that for you.

djblue18:08:22

Ohh, this main issue here is that clojure accepts clojure.core/constantly/fn--5740 as a valid symbol while clojurescript doesn't.

djblue18:08:13

Have you seen https://cljdoc.org/d/djblue/portal/0.46.0/doc/guides/logging/timbre? It shows how you can send your logs directly from timbre to portal which would side step this issue.

Steven Lombardi18:08:10

Yeah I've already configured logs to go to portal when I need them to. The problem is when I'm looking at a log in our staging or prod environment and i want to send that data to portal.

👍 2
djblue18:08:24

Yeah, I think the main reason why datafy-copied-edn works for you is that the edn is being read in via clojure instead of clojurescript

Steven Lombardi18:08:35

And I'm guessing because Portal aims to have wide dialect support you're kind of stuck with the ClojureScript limitation right?

Steven Lombardi18:08:08

Or is it because your EDN parsing lives in ClojureScript?

☝️ 2
djblue18:08:50

Yeah, all of the paste parsing happens in cljs since it's more convenient

Steven Lombardi18:08:47

Ah I'm following. So if it used Clojure's EDN parsing, paste would "just work"?

djblue19:08:02

Yeah. I think some options to address this are: • Figure out how to get this edn parsable in cljs • Allow users to specify a command on paste

👍 2
Steven Lombardi20:08:51

Oh wow that looks like it'll do it. I'll try the new version out and let you know.

djblue21:08:07

I haven't released this to clojars yet, but it should be available via the standalone version at https://djblue.github.io/portal/