clj-otel

Ítallo Rian 2023-03-31T16:35:17.552949Z

guys, when the information is sent the "NAME" parameter is going as GET, POST and the like... How do I put "GET: /route"? Without using the common span but the http...

steffan 2023-03-31T20:25:57.287899Z

The name and semantic attributes of existing HTTP server spans can be updated when the route is known. To set the route data for an existing server span, use the function add-route-data! as covered by https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.1.5/doc/guides#_manually_add_route_data_to_a_server_span, or (coming in the next clj-otel release) use https://github.com/steffan-westcott/clj-otel/blob/ab16943e0fa9a327a8fd8da4f1f890d2abe92619/clj-otel-api/src/steffan_westcott/clj_otel/api/trace/http.clj#L272 middleware for Ring. The examples show how wrap-route can be https://github.com/steffan-westcott/clj-otel/blob/ab16943e0fa9a327a8fd8da4f1f890d2abe92619/examples/common-utils/middleware/src/example/common_utils/middleware.clj#L34.

Ítallo Rian 2023-03-31T21:24:56.918529Z

I tried to use this function, but I always fall into the same error... java.lang.ClassCastException at / io.opentelemetry.api.trace.PropagatedSpan cannot be cast to clojure.lang.IFn

steffan 2023-03-31T21:48:34.857039Z

Can you share the code you wrote? It may be a simple syntax error, like using parentheses ( ) where they should not be. In Clojure using ( ) means functional call.

Ítallo Rian 2023-03-31T21:51:49.165579Z

Ítallo Rian 2023-03-31T22:29:34.551969Z

I managed to do!!

Ítallo Rian 2023-03-31T22:30:56.653349Z

Just one point, I got to where I would like to change... Today, the lib allows doing this for known routes, correct? In this case, an application with 300, 500, 1000 routes... You would have to configure one by one. Today, is there a way to automate this? this is my idea lol

steffan 2023-03-31T22:54:45.447689Z

I'm glad you've figured it out. As you've probably found for yourself, the Clojure code to execute should be in the correct place. You are using Compojure macros to create your handlers, here is a minimal example:

(ns example.hello
  (:require [compojure.core :refer :all]
            [ring.adapter.jetty :as jetty]
            [steffan-westcott.clj-otel.api.trace.http :as trace-http]))

(defroutes
  hello-routes
  (GET "/user/:id" [id]
    (do
      (trace-http/add-route-data! "/user/:id")
      (str "<h1>Hello user " id "</h1>"))))

(defonce
  server
  (jetty/run-jetty #'hello-routes
                   {:port  8080
                    :join? false}))

steffan 2023-03-31T23:06:12.615269Z

Compojure does not expose the matched route as data, unfortunately. If this is a problem, I suggest using Reitit instead, a very popular HTTP router, which does expose the route as data. The upcoming clj-otel release includes a wrap-route middleware, which together with Reitit automates the setting of route data on HTTP server spans.

Ítallo Rian 2023-03-31T23:07:31.349789Z

perfect, if the next version will already do that, my problem will be solved.

Ítallo Rian 2023-03-31T23:08:04.645629Z

Steffan, thank you very much for your attention, sorry for all the inconvenience. You are amazing.

🙇🏼 1
steffan 2023-03-31T23:11:53.695749Z

❤️ 1