steffan-westcott / clj-otel

An idiomatic Clojure API for adding telemetry to your libraries and applications using OpenTelemetry.
https://cljdoc.org/d/com.github.steffan-westcott/clj-otel-api
Apache License 2.0
183 stars 12 forks source link

clj-otel support to clojure graphql server #4

Open kaushikm02 opened 1 year ago

kaushikm02 commented 1 year ago

Hi @steffan-westcott.. I have a clojure graphql server (NOT a REST base server)which is an orchestration micro service. In my service, there are multiple outbound calls happening. I tried to instrument the service using the clj-otel(both automatic and manual) as mentioned in the tutorial. I am not seeing the traces properly in case of automatic instrumentation and not seeing the traces at all for manual instrumentation. Can you help me with this? is it even possible to instrument the clojure-graphql service with clj-otel as it is not a typical REST base server???

steffan-westcott commented 1 year ago

As you haven't provided much detail, I am limited to a general answer.

I would suggest that you get automatic instrumentation working first. Automatic instrumentation is provided by the OpenTelemetry instrumentation agent, not clj-otel. There is a short guide to running your application with the instrumentation agent in the documentation. The agent supports a wide variety of HTTP server and client libraries.

For inbound requests, your Clojure GraphQL server will likely use an HTTP server to expose the endpoints. For outbound requests, you will likely be using an HTTP client. The fact you are using GraphQL and not REST is irrelevant, as the instrumentation agent works with the HTTP server and client libraries underneath.

For example, say you used lacinia-pedestal for the server and clj-http for client requests. These use Jetty for the HTTP server and Apache HTTPClient for the HTTP client, both of which are supported by the instrumentation agent.

kaushikm02 commented 1 year ago

@steffan-westcott We can not use automatic instrumentation as we have some limitation towards the byte-code converstion. I have to go with manual instrumentation. While doing so, will the library take care of the traceparent header to be passed to the downstream service or we have to pass the traceparent manually in the header to the downstream calls?

steffan-westcott commented 1 year ago

traceparent is used in the W3C Trace Context propagation protocol. Support for W3C Trace Context is included and enabled by default in clj-otel, though for manual instrumentation you will need to write a couple of lines of code to actually use it.

Context propagation is implemented by reading (extracting) and writing (injecting) HTTP headers. For manual instrumentation, you need to make use of clj-otel features to ensure the context is extracted from incoming HTTP requests, and the (modified) context is injected into outgoing HTTP requests.

brett-bim commented 1 year ago

We have a graphql API written in Clojure and have used this library successfully. We're using graphql-java but were using Walmart Labs Lacinia. Both were instrumented using this library. If you have specific questions about implementation, I might be able to provide information on our setup.

kaushikm02 commented 1 year ago

Could you please share the link to the repo just for viewing?? @brett-bim

brett-bim commented 1 year ago

We don't have a public repo with that info. We run the API with the latest opentelemetry-javaagent.jar which has autoinstrumentation for graphql included. This provides spans that include attributes like the graphql query and others.