Allow disabling per-filter events in SecurityObservationSettings

オープン
#19,922 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@erfannvb がすでに取り組んでいます。

2026年10月18日 から。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java, spring
領域
observability

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Java
スター
9.7k
フォーク
6.4k
平均マージ
3時間 11分
マージ済み PR(30日)
19

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

spring-projects/spring-security のほかの issue

spring-projects/spring-security の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。