Skip to content

Provide a way to make decisions based on the parent in ObservationPredicate #3678

Closed

Description

@jonatan-ivanov

This issue was originally discussed in spring-projects/spring-boot#34400
The scenario is the following: if Spring Security is used and users want to ignore /actuator endpoints, there is no easy way to do it today because Spring Security does not add details about the request. One potential solution would be checking the parent (root) Observation but it is not available through the context when the predicate is tested.

There is a reproducer in the issue mentioned above.

Also see: spring-projects/spring-security#12854

Activity

  1. added
    enhancement
    internal
    on Mar 8, 2023
  2. braunsonm commented on Mar 8, 2023

    @braunsonm

    Thanks for opening this @jonatan-ivanov
    Can you clarify if the intention of this issue is to also have the parent set if the parent was ignored in a previous predicate?

    ie:

    @Configuration
    public class TestConfiguration {
        @Bean
        ObservationPredicate ignoreActuator() {
            return (s, context) -> ignoreActuatorRecursive(context);
        };
    
        public boolean ignoreActuatorRecursive(Observation.ContextView context) {
            if (context instanceof ServerRequestObservationContext serverRequestObservationContext) {
                HttpServletRequest carrier = serverRequestObservationContext.getCarrier();
                return !carrier.getServletPath().startsWith("/actuator"); // <----- Line (*)
            }
    
            if (context.getParentObservation() != null) {  // <-- Will the parent still be set if it was ignored in line (*)?
                return ignoreActuatorRecursive(context.getParentObservation().getContextView());
            }
    
            return true;
        }
    }

    It would be great for the parent to remain set even if the parent observation was ignored in a previous predicate. The reason being so that you can properly ignore any subsequent observations deriving from a root span that was ignored.

  3. jonatan-ivanov commented on Mar 9, 2023

    @jonatan-ivanov
    MemberAuthor

    No, and there the parent can't be really set in these cases. If an Observation is ignored we will create a noop one that is hopefully eliminated by JIT.

  4. quaff commented on May 31, 2023

    @quaff
    Contributor

    @braunsonm context.getParentObservation() will always be null in ObservationPredicate, I'm trying to fix it by #3867.

  5. added and removed
    internal
    on Aug 16, 2023
  6. added this to the 1.12.0-M3 milestone on Aug 16, 2023
  7. added a commit that references this issue on Aug 16, 2023
    c959eb3
  8. changed the title [-]Provide a simple way to make decisions based on the parent in ObservationPredicate[/-] [+]Provide a way to make decisions based on the parent in ObservationPredicate[/+] on Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions