Skip to content

Documentation for custom observation conventions is missing important hints #40158

@hadjiski

Description

@hadjiski

Considering a standard spring boot rest controller application with some business and data repository layers + outgoing client communication:

Customizing observation conventions might get tricky, when you go beyond the trivial well documented examples in the spring boot docu, spring framework docu and micrometer

Here my thoughts:

  • customization is not consistent: even for the commonly used metrics like http.server.requests, http.client.requests, spring.data.repository.invocations, tasks.scheduled.execution you either extend some default convention or define a bean of a tags customizer etc.
  • most of the time folks want to customize the tags dynamically based on some business data (e.g. business entity, customer type, etc.). This data is often not part of the servlet request as parameter, body or header, rather collected as part of the business logic during the execution of the particular rest controller call. Now when it comes to propagating the data to the observation convention customizers, it tricky, cause:
    • in case of http.server.requests the data can be added to the servlet request's attributes in the business layer, which are then available in the customizer in the ServerRequestObservationContext -> getCarrier()
    • in case of http.client.requests the data can be added to the observation registry's current observation context's map in the business layer, which are then available in the customizer in the ClientRequestObservationContext map
    • in case of spring.data.repository.invocations the data can be added to the observation registry's current observation context's map in the business layer, which are then available in the customizer in the same way (observation registry's current observation context's map), because the carrier is not of any such use
    • in case of tasks.scheduled.execution the data can be added to the observation registry's current observation context's map in the business layer, which are then available in the customizer in the ScheduledTaskObservationContext map
      (as you can see, for the "top" 4 metrics, we have 3 different ways of propagating business data)
      I know people promote using of context propagation lib, which I did not study so far deeply, but it seems like an overhead for the small thing we are trying to achieve here. Not to mention the fact, that without the extra lib, we can rely on the context being reset for us, not worrying about clearing all the thread locals properly

It would be nice to align those, but I assume it is in the nature of things, when many projects are building on top of each other - then let it be better documented with examples

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixstatus: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions