Fork me on GitHub
#pedestal
<
2024-04-05
>
hlship18:04:20

This observer thing is coming along very nicely. PR later today. Here's a preview:

DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.interceptor.observer-test/handler, :stage :enter, :execution-id 2, :context-changes {:added {[:response] {:status 200, :body ...}}}, :line 119}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.interceptor.observer-test/content-type, :stage :leave, :execution-id 2, :context-changes {:added {[:response :headers] {"Content-Type" "application/edn"}}}, :line 119}
I wrote a little code to identify the changes in two maps in terms of key paths. It also has an "omit set" of key paths to be replaced with ... so that you don't spew out request and response bodies to logging (because they are large and possibly sensitive). This is going to be very useful.

ghadi19:04:04

seems like a performance crater

ghadi19:04:06

spewing to log is a choice, but I prefer tapping in/out and being in charge of whether I log, use morse, how to diff, etc.

hlship19:04:52

It's intended for local development.

hlship19:04:21

So the base abstraction is the observer function; the sample above is one particular way to use that abstraction.

hlship19:04:50

But I like the idea of tap>-ing the result.

hlship19:04:24

I've torn my hair out before trying to figure out which interceptor made what change to the context, so I'm really looking forward to using this!

hlship19:04:29

You could literally (chain/add-observer context tap>).

hlship21:04:07

I've hooked it up to the embedded template:

DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.cors/dev-allow-origin, :stage :enter, :execution-id 1, :context-changes {:added {[:request :headers "origin"] ""}}, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.tracing/tracing, :stage :enter, :execution-id 1, :context-changes {:added {[:bindings] ..., [:io.pedestal.http.tracing/otel-context-cleanup] ..., [:io.pedestal.http.tracing/prior-otel-context] ..., [:io.pedestal.http.tracing/otel-context] ..., [:io.pedestal.http.tracing/span] ...}}, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http/log-request, :stage :enter, :execution-id 1, :context-changes nil, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.route/query-params, :stage :enter, :execution-id 1, :context-changes nil, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.route/method-param, :stage :enter, :execution-id 1, :context-changes nil, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.ring-middlewares/resource, :stage :enter, :execution-id 1, :context-changes nil, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.route/router, :stage :enter, :execution-id 1, :context-changes {:added {[:request :url-for] ..., [:request :path-params] [], [:route] ..., [:url-for] ...}, :changed {[:bindings] ..., [:io.pedestal.interceptor.chain/queue] ...}}, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.route/path-params-decoder, :stage :enter, :execution-id 1, :context-changes {:changed {[:request :path-params] {:from [], :to {}}}, :added {[:io.pedestal.http.route/path-params-decoded?] true}}, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor "#Interceptor{}", :stage :enter, :execution-id 1, :context-changes {:added {[:response] {:status 200, :body ...}}}, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.secure-headers/secure-headers, :stage :leave, :execution-id 1, :context-changes {:added {[:response :headers] {"Strict-Transport-Security" "max-age=31536000; includeSubdomains", "X-Frame-Options" "DENY", "X-Content-Type-Options" "nosniff", "X-XSS-Protection" "1; mode=block", "X-Download-Options" "noopen", "X-Permitted-Cross-Domain-Policies" "none", "Content-Security-Policy" "object-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;"}}}, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.ring-middlewares/content-type-interceptor, :stage :leave, :execution-id 1, :context-changes nil, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http/not-found, :stage :leave, :execution-id 1, :context-changes nil, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.tracing/tracing, :stage :leave, :execution-id 1, :context-changes {:changed {[:bindings] ...}, :removed {[:io.pedestal.http.tracing/otel-context-cleanup] ..., [:io.pedestal.http.tracing/prior-otel-context] ..., [:io.pedestal.http.tracing/otel-context] ..., [:io.pedestal.http.tracing/span] ...}}, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.impl.servlet-interceptor/ring-response, :stage :leave, :execution-id 1, :context-changes nil, :line 128}
DEBUG io.pedestal.interceptor.chain.debug - {:interceptor :io.pedestal.http.impl.servlet-interceptor/stylobate, :stage :leave, :execution-id 1, :context-changes nil, :line 128}
Looks like there's a little bug in the :io.pedestal.http.route/router interceptor and the :[:request path-params] key, no?

hlship23:04:40

0.7.0-beta-1 ... just saying.

🎉 9
🚀 3
Zed13:04:11

Can I try this out now in my lacinia-pedestal app, or do I need to wait for lacinia-pedestal to be updated too?

hlship15:04:37

I can’t think of a reason that would prevent them from working together.

hlship22:04:55

Which is to say, there’s only a few non-backwards compatible changes, and I don’t believe that any of those overlap with anything lacinia-pedestal uses.

Zed22:04:16

lacinia-pedestal uses io.pedestal.http.jetty.websockets which was renamed

hlship03:04:28

Ah, then my memory is not good. I’ll have to look into that.

rossputin20:04:20

hey, any details on how? I think this is/will affect me, thanks

hlship20:04:13

It’s on my todo list. Thanks for jogging my memory.

hlship20:04:26

It’ll take a new release of lacinia-pedestal to make it work.

rossputin08:04:04

I’m currently thinking my own issues are sort of related but more about me updating openjdk and clojure on my guix system at the moment - either way… with my local project dependencies identical to before openjdk and clojure updates have led to some weird dependency issues with Jetty for the most part - I’ll confirm when I have time)