Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2024-10-02 dev2next - Application Observability...

2024-10-02 dev2next - Application Observability like you've never heard before

Jonatan Ivanov

October 03, 2024
Tweet

More Decks by Jonatan Ivanov

Other Decks in Programming

Transcript

  1. About Me - Spring Team - Micrometer - Spring Cloud,

    Spring Boot - Spring Observability Team - Seattle Java User Group - develotters.com - @jonatan_ivanov
  2. Gauge the audience • Observability in production? • Spring Boot

    3? • Micrometer? • Prometheus? • OpenTelemetry? How many people are using:
  3. What is Observability? How well we can understand the internals

    of a system based on its outputs (Providing meaningful information about what happens inside) (Data about your app)
  4. Why do we need Observability? Today's systems are increasingly complex

    (cloud) (Death Star Architecture, Big Ball of Mud)
  5. Environments can be chaotic You turn a knob here a

    little and apps are going down there We need to deal with unknown unknowns We can’t know everything Things can be perceived differently by observers Everything is broken for the users but seems ok to you Why do we need Observability?
  6. Why do we need Observability? (business perspective) Reduce lost revenue

    from production incidents Lower mean time to recovery (MTTR) Require less specialized knowledge Shared method of investigating across system Quantify user experience Don't guess, measure!
  7. Logging What happened (why)? Emitting events Metrics What is the

    context? Aggregating data Distributed Tracing Why happened? Recording causal ordering of events Logging - Metrics - Distributed Tracing
  8. Examples Latency Logging (What?) Processing took 140ms Metrics (Context?) P99.999:

    140ms Max: 150ms Distributed Tracing (Why?) DB was slow (lot of data was requested) Error Logging (What?) Processing failed (stacktrace?) Metrics (Context?) The error rate is 0.001/sec 2 errors in the last 30 minutes Distributed Tracing (Why?) DB call failed (invalid input)
  9. SLF4J with Logback comes pre-configured SLF4J (Simple Logging Façade for

    Java) Simple API for logging libraries Logback Natively implements the SLF4J API If you want Log4j2 instead of Logback: - spring-boot-starter-logging + spring-boot-starter-log4j2 Logging with JVM/Spring: SLF4J + Logback
  10. Metrics with JVM/Spring: Micrometer Dimensional Metrics library on the JVM

    Like SLF4J, but for metrics API is independent of the configured metrics backend Supports many backends Comes with spring-boot-actuator Spring projects are instrumented using Micrometer Many third-party libraries use Micrometer
  11. Supported metrics backends/formats/protocols Ganglia Graphite Humio InfluxDB JMX KairosDB New

    Relic (/actuator/metrics) OpenTSDB OTLP Prometheus SignalFx Stackdriver (GCP) StatsD Wavefront (VMware) AppOptics Atlas Azure Monitor CloudWatch (AWS) Datadog Dynatrace Elastic
  12. Distributed Tracing with JVM/Spring Boot 2.x: Spring Cloud Sleuth Boot

    3.x: Micrometer Tracing (Sleuth w/o Spring dependencies) Provide an abstraction layer on top of tracing libraries - Brave (OpenZipkin), “default” - OpenTelemetry (CNCF), “experimental” Instrumentation for Spring Projects, 3rd party libraries, your app Support for various backends
  13. • Add Logs (application logs) • Add Metrics • Add

    Distributed Tracing You want to instrument your application…
  14. Introducing Observation API • “New” module in Micrometer 1.10 (micrometer-observation)

    micrometer-core has a dependency on it • Higher level abstraction than metrics, tracing, etc. • Instrument once, configure handlers for multiple purposes (metrics, tracing, logging, etc.) • Already used for most instrumentation shown
  15. Observation API basic usage example Observation observation = Observation.start("talk",registry); try

    { // TODO: scope doSomething(); // ← This is what we’re observing } catch (Exception exception) { observation.error(exception); throw exception; } finally { // TODO: attach tags (key-value) observation.stop(); }
  16. Configuring an ObservationHandler (without Boot) ObservationRegistry registry = ObservationRegistry.create(); registry.observationConfig()

    .observationHandler(new MetricsHandler(...)) .observationHandler(new TracingHandler(...)) .observationHandler(new LoggingHandler(...)) .observationHandler(new AuditEventHandler(...));
  17. ObservationHandler with Spring Boot Spring Boot auto-configures handlers for meters

    and tracing. Boot will also register ObservationHandler beans to the ObservationRegistry that it auto-configures. @Bean ObservationHandler<MyContext> myHandler() { return new MyObservationHandler(); }
  18. Observation.Context • Holds the state/data of an Observation ◦ e.g.:

    request/response object • ObservationHandler will receive it • Mutable, you can add data to it ◦ Instrumentation time ◦ Pass data between handler methods
  19. Observation Predicate and Filter ObservationPredicate • BiPredicate: (name, context) →

    Boolean • Whether an Observation is ignored (noop) ObservationFilter • Modify the Observation.Context • Right before ObservationHandler#onStop • e.g. common tags (KeyValues)
  20. Conventions for instrumentation • Instrumentation by default provides a convention

    ◦ Naming, tags (KeyValues) • You may want to customize the convention for an instrumentation without rewriting the instrumentation • Control the timing of changing conventions ◦ Convention changes are breaking changes
  21. Introducing ObservationConvention • Instrumentation can use a default ObservationConvention while

    allowing users to provide a custom implementation • Extend a default implementation or implement your own • See, for example, Spring Framework’s docs
  22. Documenting instrumentation • Keeping documentation in sync with the implementation

    is difficult and error-prone. • Introducing Micrometer Docs Generator • Define an ObservationDocumentation enum for your Observation-based instrumentation and generate documentation based on it as part of the build • Integrate it with ObservationConvention
  23. What’s ~new? • Improved Exemplars support • MeterProvider • Prometheus

    Java Client 1.x • New Docs site (micrometer.io) • Observability improvements in the Spring portfolio ◦ Context Propagation + Log Correlation ◦ Auto-Instrumentations, Performance • SBOM Actuator Endpoint
  24. What’s ~next? • Exponential Histograms (OTLP) • TestObservationRegistry validation •

    ProcessInfoContributor • SslInfoContributor • SslHealthIndicator • Spring AI instrumentation