clj-otel

lepistane 2024-06-14T20:55:25.101619Z

Having some trouble setting up agent for this particular project.

:java-source-paths ["java_src"]
  :jvm-opts ["-javaagent:grafana-opentelemetry-java.jar"
             "-Dotel.resource.attributes=service.name=dev-webserver"
             "-Dotel.metrics.exporter=prometheus"
             "-Dotel.metric.export.interval=5000"
             "-Dotel.logs.exporter=none"
             "-Dotel.traces.exporter=none"
             ]
these options together causes lein repl to be stuck
Leiningen 2.11.2 on Java 11.0.23 OpenJDK 64-Bit Server VM
Without java_src - projects starts fine without jvm-opts - project starts fine This is reproducible with basic lein new app, add agent, add java class and java-source-paths -> lein repl -> gets stuck after
Compiling 1 source files to /target/classes
What am i doing wrong here?

steffan 2024-06-14T21:10:07.527029Z

I don't use lein but I suspect the issue lies with the project setup. If you publish your full project then hopefully someone can help out with your lein setup.

steffan 2024-06-14T21:11:12.274789Z

Remember also that applications run with the agent can take longer to start.

lepistane 2024-06-14T21:12:28.031849Z

It's not that for sure. Without java-source-paths repl starts within 20sec. With it it's just stuck on the step i wrote above. I will see if i can recreate it with deps.edn

steffan 2024-06-14T21:15:00.869399Z

Just so I'm clear, you have not added any clj-otel dependencies to the project?

lepistane 2024-06-14T21:17:09.928799Z

Exactly. I haven't added any clj-otel.

[[org.clojure/clojure "1.11.1"]
                 [software.amazon.glue/schema-registry-serde "1.1.17"]]
these are deps at the moment. I will share the link to minimum example soon By the way i am not going to setup deps.edn project i am not verse in it enough to do this fast enough. It doesn't have java-source-paths equivalent.

lepistane 2024-06-14T21:19:48.798809Z

https://github.com/StankovicMarko/test-agent

lepistane 2024-06-14T21:22:05.349489Z

Also i asked in #leiningen but they forwarded me back here 😄

steffan 2024-06-14T21:27:24.525029Z

I don't see where Prometheus is started in your project. In the clj-otel microservices examples, I use Docker Compose to start the application and Prometheus instances.

steffan 2024-06-14T21:29:29.056899Z

As is stands, when starting your project the agent would complain it can't reach Prometheus, as there is no instance for it to talk to.

lepistane 2024-06-14T21:32:37.113429Z

Just tried it. Doesn't work. Same behavior Used the same setup from the project that is using agent but doesn't have java-source-paths

lein repl
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
[otel.javaagent 2024-06-14 21:30:41:642 +0000] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 2.4.0
[otel.javaagent 2024-06-14 21:30:41:673 +0000] [main] INFO com.grafana.extensions.instrumentations.TestedInstrumentationsContext - Grafana OpenTelemetry Javaagent: version=2.4.0-beta.1, includeAllInstrumentations=true, useTestedInstrumentations=false, includedUntestedInstrumentations=[], excludedInstrumentations=[]
[otel.javaagent 2024-06-14 21:30:41:675 +0000] [main] INFO com.grafana.extensions.cloud.GrafanaCloudConfigCustomizer - will not attempt to send data to Grafana Cloud: zone is not set
[otel.javaagent 2024-06-14 21:30:41:744 +0000] [main] INFO io.opentelemetry.sdk.resources.Resource - Attempting to merge Resources with different schemaUrls. The resulting Resource will have no schemaUrl assigned. Schema 1:  Schema 2: 
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See  for further details.
Warning: protocol #'java-time.core/Amount is overwriting function abs
WARNING: abs already refers to: #'clojure.core/abs in namespace: java-time.core, being replaced by: #'java-time.core/abs
WARNING: abs already refers to: #'clojure.core/abs in namespace: java-time, being replaced by: #'java-time/abs
Reflection warning, jackdaw/data/consumer.clj:20:3 - call to org.apache.kafka.clients.consumer.ConsumerRecord ctor can't be resolved.
Compiling 1 source files to /<path>target/classes

steffan 2024-06-14T21:34:04.385429Z

Are you using Grafana Cloud, or attempting to use a backend deployed locally on your machine?

lepistane 2024-06-14T21:35:02.853679Z

I am not using grafana cloud. I am attempting to just start the app locally yes

steffan 2024-06-14T21:36:35.867979Z

Then you need to use the regular OpenTelemetry instrumentation agent, not grafana-opentelemetry-java.jar. Download the agent opentelemetry-javaagent.jar from https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases

lepistane 2024-06-14T21:41:03.965099Z

I switched. Behavior is the same and output is

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
[otel.javaagent 2024-06-14 23:40:18:487 +0200] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 2.4.0
Compiling 1 source files to /home/marko/clojure/helper/mini-projects/test-agent/target/classes

steffan 2024-06-14T21:42:28.031919Z

Have you also got a Prometheus instance running? How are you starting that?

lepistane 2024-06-14T21:46:15.000579Z

Simple docker compose

prometheus:
    network_mode: "host"
    image: prom/prometheus
    volumes:
      - ./dev-resources/otel/prometheus2.yml:/etc/prometheus/prometheus.yml
Yes prometheus container is running. Even agent is running because gives me results But repl isn't starting

steffan 2024-06-14T21:48:58.872979Z

Could you update your test project so I can reproduce your setup? I don't use lein at all so it will take me some time to analyse.

lepistane 2024-06-14T21:50:14.930929Z

You mean to convert it to deps.edn project?

steffan 2024-06-14T21:52:08.649129Z

I mean include details like your Docker Compose files, prometheus.yaml and any other files so that I can reproduce the issue. There is likely some issue with the project setup.

lepistane 2024-06-14T21:57:24.688489Z

I pushed. Here are the steps docker-compose up and then lein repl it's hanging. Commenting out java-source-pahts everything works

steffan 2024-06-14T22:02:21.887129Z

Not sure if this affects it, but I noticed your test project uses a different method than divisor-app for the Prometheus instance to access the local machine. https://github.com/steffan-westcott/clj-otel/tree/master/examples/divisor-app

lepistane 2024-06-14T22:10:13.236999Z

I tried, same behavior. I think it's related to lein somehow. i created an issue: https://github.com/technomancy/leiningen/issues/2818

steffan 2024-06-14T22:10:20.118699Z

I spotted something : You should use the command docker compose up, not docker-compose up These are different commands, despite looking very similar!

lepistane 2024-06-14T22:13:04.137279Z

Thank you very much for spending time and looking into this i appreciate it 🙇

steffan 2024-06-14T22:19:38.324859Z

I have recreated your issue, but I'm at a loss as to what is happening. Perhaps someone who knows how lein works can help you.

lepistane 2024-06-14T22:21:52.601819Z

it must be some interaction between agent, jvm and lein that is causing this. I will see what comes out of the issue i created. Thank you again 🙇

steffan 2024-06-14T22:23:28.121529Z

I do note this in the Leiningen docs: > To pass extra arguments to the JVM, set the :jvm-opts vector. This will override any default JVM opts set by Leiningen.

steffan 2024-06-14T22:24:22.291339Z

So I'm guessing that there are some opts needed by lein to make the REPL work. It's not clear to me if the JVM opts you supply are added with the default ones, or replace them entirely.

steffan 2024-06-14T22:36:50.249349Z

I can see the thread in #leiningen has a useful suggestion about separating the build and run steps. lein definitely tries to be too automatic (magical) and ends up being quite brittle, from what I know of it.

lepistane 2024-06-14T22:37:45.327949Z

Yeah, maybe we will switch to deps.edn because of this 😄 or at least have an option for local dev

steffan 2024-06-14T22:40:43.136299Z

I would strongly recommend using deps.edn for any project, you have good control on what is happening. tools.build documentation says that builds are programs, which I find is a powerful truth!

🙇 1
steffan 2024-06-14T22:42:14.564729Z

I've written more than my fair share of Makefiles, Ant, Maven and Gradle build files to know this 😄

😄 1
steffan 2024-06-14T22:55:06.525009Z

Compiling Java source files is done with clojure.tools.build.api/javac . Your build.clj would be quite simple, like this https://clojure.org/guides/tools_build#_mixed_java_clojure_build