Allow disabling per-filter events in SecurityObservationSettings

Aperta
#19,922 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@erfannvb ci sta già lavorando.

Dal 18/10/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java, spring
Ambito
observability

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
9.7k
Fork
6.4k
Merge medio
3h 11m
PR unite (30g)
19

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di spring-projects/spring-security

Tutte le issue di spring-projects/spring-security

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.