Allow disabling per-filter events in SecurityObservationSettings

Abierto
#19,922 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@erfannvb ya está trabajando en esto.

Desde el 18/10/2026.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
java, spring

Línea de trabajo

Start by reading SecurityObservationSettings and ObservationFilterChainDecorator, which the issue identifies as the settings API and the source of per-filter events. Trace how settings control filter chain observations and how the decorator adds events; the payload names no tests or specific files beyond these entry points. Done means filter chain spans and their existing key values remain recorded while per-filter events can be disabled.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

status: waiting-for-triage type: enhancement

Expected Behavior

SecurityObservationSettings offers a way to keep the filter chain observations (i.e. the existing shouldObserveRequests(true) method) but turn off the per-filter events, for example:

   @Bean
   SecurityObservationSettings securityObservations() {
       return SecurityObservationSettings.withDefaults()
               .shouldObserveRequests(true)
               .shouldObserveFilterEvents(false) // new
               .build();
   }

With this setting, the security filter spans are still recorded, with their existing key values, but no before XxxFilter / after XxxFilter events are added to them.

Current Behavior

ObservationFilterChainDecorator adds two events per filter to the chain observation (spring.security.filterchains): one named <filter>.before with contextual name before <FilterClass> and one named <filter>.after with contextual name after <FilterClass>. When distributed tracing is enabled, they become span events, so every request produces a dozen or more events such as before LogoutFilter, before RequestCacheAwareFilter, before AuthorizationFilter, and their after counterparts.

SecurityObservationSettings is all-or-nothing per observation type. shouldObserveRequests(false) removes the events, but also removes all the filter chain spans which are really useful for latency analysis and for investigating where a request was rejected. So if we want to remove the span events, we are also forced to get rid of the spans as well currently.

The events cannot be filtered downstream either: Micrometer's ObservationFilter only operates on the context, and events are forwarded to handlers directly.

Replacing the decorator is not really feasible. ObservationFilterChainDecorator is final, has a single ObservationRegistry constructor, and its FilterChainObservationConvention and FilterChainObservationContext are package-private and final.

Context

This was previously requested in #18646, which was closed as "not planned".

Such events might be useful in specific scenarios, but I found that more often than not they are not really needed, yet they are enabled by default and there's no way today to disable them. The consequence of keeping them on is extra noise on the spans when using observability platforms that support span events (e.g. Grafana), which is still acceptable. The main problem happens with observability platforms that don't support span event, such as Elasticsearch, which translates each span event to a log. That is not only noisy but also results in lots of extra disk space used.

There's always an option to operate at the OpenTelemetry level, but that's not optimal since it's not a portable solution and it's not straightforward to target only specific events at that point.

In this issue, I'm suggesting adding a new method to SecurityObservationSettings as a simple solution. But for even greater flexibility, it would be nice to follow the Micrometer best practices and accept an ObservationConvention to customize the filter chain observations, including the events (e.g. ObservationConvention<FilterChainObservationContext>). Perhaps SecurityObservationSettings could accept observation conventions for that.

Lenguaje dominante
Java
Estrellas
9.7k
Forks
6.4k
Merge medio
3 h 11 min
PR fusionados (30 d)
19

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de spring-projects/spring-security

Todos los issues de spring-projects/spring-security

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.