Skip to content

Conversation

injectives
Copy link

@injectives injectives commented Oct 14, 2025

At present, the neo4jObservationCustomizer has an effective Ordered.LOWEST_PRECEDENCE, meaning that it goes last in Neo4jAutoConfiguration:

configBuilderCustomizers.orderedStream().toList()
...
customizers.forEach((customizer) -> customizer.customize(builder));

This update sets its order to Ordered.HIGHEST_PRECEDENCE, meaning that a user-defined ConfigBuilderCustomizer can effectively override it.

As an example, this is useful when user wants to customize MicrometerObservationProvider as it actually has some optional properties that may be useful. Here is an example:

@Bean
ConfigBuilderCustomizer observationCustomizer(ObservationRegistry observationRegistry) {
    return configBuilder -> {
        var observationProvider = MicrometerObservationProvider.builder(observationRegistry)
                .alwaysIncludeQuery(true)
                .includeQueryParameters(true)
                .includeUrlScheme(true)
                .includeUrlTemplate(true)
                .requestHeaderPredicate(name -> true)
                .responseHeaderPredicate(name -> true)
                .build();
        configBuilder.withObservationProvider(observationProvider);
    };
}

@injectives injectives force-pushed the fix/neo4j-customizer branch from b5941b9 to daa7f23 Compare October 14, 2025 13:48
@injectives
Copy link
Author

@snicoll, sorry to ping you directly. Just came across this during my testing and thought it might be useful to submit a PR.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 14, 2025
@snicoll snicoll changed the title Make sure it is possible to override neo4jObservationCustomizer Provide explicit order for Neo4j observation customizer Oct 14, 2025
@snicoll snicoll added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 14, 2025
@snicoll snicoll self-assigned this Oct 14, 2025
@snicoll snicoll added this to the 4.0.0-RC1 milestone Oct 14, 2025
@snicoll
Copy link
Member

snicoll commented Oct 14, 2025

@injectives thanks for the PR. please amend your commit with -s as the DCO check is failing at the moment.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Oct 14, 2025
At present, the `neo4jObservationCustomizer` has an effective `Ordered.LOWEST_PRECEDENCE`, meaning that it goes last in `Neo4jAutoConfiguration`:
```java
configBuilderCustomizers.orderedStream().toList()
...
customizers.forEach((customizer) -> customizer.customize(builder));
```

This update sets its order to `Ordered.HIGHEST_PRECEDENCE`, meaning that a user-defined `ConfigBuilderCustomizer` can effectively override it.

As an example, this is useful when user wants to customize `MicrometerObservationProvider` as it actually has some optional properties that may be useful. Here is an example:
```java
@bean
ConfigBuilderCustomizer observationCustomizer(ObservationRegistry observationRegistry) {
    return configBuilder -> {
        var observationProvider = MicrometerObservationProvider.builder(observationRegistry)
                .alwaysIncludeQuery(true)
                .includeQueryParameters(true)
                .includeUrlScheme(true)
                .includeUrlTemplate(true)
                .requestHeaderPredicate(name -> true)
                .responseHeaderPredicate(name -> true)
                .build();
        configBuilder.withObservationProvider(observationProvider);
    };
}
```

Signed-off-by: Dmitriy Tverdiakov <[email protected]>
@injectives injectives force-pushed the fix/neo4j-customizer branch from daa7f23 to 34b4846 Compare October 14, 2025 14:09
@injectives
Copy link
Author

@injectives thanks for the PR. please amend your commit with -s as the DCO check is failing at the moment.

Thanks! Done 👍

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 14, 2025
@wilkinsona
Copy link
Member

I wonder if we should use 0 for the order so that user-provided customizers can go before or after it.

@snicoll
Copy link
Member

snicoll commented Oct 14, 2025

@wilkinsona Yes, my plan was to polish the PR to use 0. In this case, the method replaces the whole implementation so it's likely to run after. But for consistency with other customizer I'd put it at 0 anyways (plus the content of the customizer could change in the future).

@injectives
Copy link
Author

injectives commented Oct 14, 2025

I wonder if we should use 0 for the order so that user-provided customizers can go before or after it.

There is probably no effective benefit in this as ConfigBuilder#withObservationProvider simply overrides the previous value with a new one. If user defines something, I suspect they would never want the default one to take precedence.

Having said this, please feel free to polish as you see fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: feedback-provided Feedback has been provided type: task A general task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants