Fork me on GitHub
Ítallo Rian16:03:17

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...


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, or (coming in the next clj-otel release) use middleware for Ring. The examples show how wrap-route can be

Ítallo Rian21:03:56

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


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 Rian22:03:34

I managed to do!!

Ítallo Rian22:03:56

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


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]))

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

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


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 Rian23:03:31

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

Ítallo Rian23:03:04

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