Fork me on GitHub
#clj-otel
<
2023-02-16
>
Dimitar Uzunov08:02:15

Hi! What is the best way to add attributes to a server-span, like ones created with wrap-server-span?

Dimitar Uzunov12:02:54

I see span-interceptor accepts additional attributes

Dimitar Uzunov13:02:11

I think it is very useful to add attributes when instrumenting routes

steffan21:02:24

• If the attributes you wish to add take the same values for every span, you should consider adding the attributes to the https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.1.5/doc/concepts#_resources (an OpenTelemetry concept) rather than the server span. For applications that use autoconfiguration (this includes applications run with the OpenTelemetry instrumentation agent), use the otel.resource.attributes property documented https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#opentelemetry-resource. For applications using programmatic configuration, use the :resources option of function https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-sdk/0.1.5/api/steffan-westcott.clj-otel.sdk.otel-sdk#init-otel-sdk!, see an example https://github.com/steffan-westcott/clj-otel/blob/3103cef4a0badf946e1511521ab764202e7eb1f7/examples/programmatic-sdk-config/src/example/programmatic_sdk_config.clj#L38. • On the other hand, if the attribute values vary with each server span, add the attributes to the existing server span using the function https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.1.5/api/steffan-westcott.clj-otel.api.trace.span#add-span-data! as covered in this https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api/0.1.5/doc/guides#_add_attributes_to_a_span. There are several uses of add-span-data! in the https://github.com/search?q=%22add-span-data%21%22+repo%3Asteffan-westcott%2Fclj-otel+path%3A%2Fexamples&amp;type=Code&amp;ref=advsearch&amp;l=&amp;l=. • The interceptors provided by clj-otel add route data to the server span, as Pedestal routers follow a common convention. Ring is not so fortunate as there is no common convention for routers defined. It is easy to write your own Ring middleware to add route data though, as https://github.com/steffan-westcott/clj-otel/blob/3103cef4a0badf946e1511521ab764202e7eb1f7/examples/common-utils/middleware/src/example/common_utils/middleware.clj#L33.

Dimitar Uzunov08:02:50

Hi @U2C6SPLDS thanks for your response! From the above I tried doing the second and third bullet as spans are indeed different (I want to attach some user info), glad to see that it is a good approach.