open-telemetrymicrometerspring-micrometermicrometer-tracingobservability

When you create a new span directly in Observability, in what cases do you typically create it?


I'm implementing Observability with Springboot + OpenTelemetry + Micrometer. I'm still not sure when it's a good idea to create my own spans. When do you guys usually create your own spans ?


Solution

  • You might want to read the docs: https://docs.micrometer.io/tracing/reference/glossary.html

    Span is a basic unit of work so you ant to create one if you are doing something that you want to observe separately (especially if it can fail can have latency issues). For example a DB call, or an HTTP call to a different application, or an "expensive"/"important" piece of business logic (calculating something CPU intensive).

    You might also want to check the Observation API (spans and metrics will be created automatically from Observations). It might be a bit more straightforward: you can create Observations for those things that you want to "observe".

    (Fyi: incoming/outgoing http calls, DB calls, JMS, Kafka, RabbitMQ, etc. are auto-instrumented by Spring, you just need to enable this instrumentation as needed/use the right dependencies.)