You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With OIV *disabled*, the observation interaction looks like this:
85
91
86
-
However, with OSIV enabled, the DB connection closing is delayed, leading to the following order:
92
+
----
93
+
Action | Name
94
+
----------------------|--------------------
95
+
START Observation | "http.server.requests"
96
+
OPEN Scope | "http.server.requests"
97
+
START Observation | "my.observation"
98
+
OPEN Scope | "my.observation"
99
+
START Observation | "jdbc.connection"
100
+
OPEN Scope | "jdbc.connection"
101
+
... | ...
102
+
CLOSE Scope | "jdbc.connection"
103
+
STOP Observation | "jdbc.connection"
104
+
CLOSE Scope | "my.observation"
105
+
STOP Observation | "my.observation"
106
+
CLOSE Scope | "http.server.requests"
107
+
STOP Observation | "http.server.requests"
108
+
----
109
+
110
+
With OIV *enabled*, the order changes:
111
+
112
+
----
113
+
Action | Name
114
+
----------------------|--------------------
115
+
START Observation | "http.server.requests"
116
+
OPEN Scope | "http.server.requests"
117
+
START Observation | "my.observation"
118
+
OPEN Scope | "my.observation"
119
+
START Observation | "jdbc.connection"
120
+
OPEN Scope | "jdbc.connection"
121
+
... | ...
122
+
CLOSE Scope | "my.observation" <==
123
+
STOP Observation | "my.observation" <==
124
+
CLOSE Scope | "jdbc.connection" <==
125
+
STOP Observation | "jdbc.connection" <==
126
+
CLOSE Scope | "http.server.requests"
127
+
STOP Observation | "http.server.requests"
128
+
----
87
129
88
-
. Open HTTP request observation scope
89
-
. Open DB connection observation scope
90
-
. (Other observation scopes)
91
-
. *(SWAPPED)* Close HTTP request observation scope
92
-
. *(SWAPPED)* Close DB connection observation scope
130
+
As you can see, when OIV is enabled, the `jdbc.connection` observation/scope is closed *after* the `my.observation` observation/scope.
131
+
Since scopes must be closed in the reverse order of their opening, this swapped order can cause leaks in thread-local bound values (such as spans), because opening and closing scopes trigger thread-local operations.
93
132
94
-
Since observation scopes must be closed in the reverse order of their creation, this swapped ordering causes observation leaks.
133
+
The example above uses an explicitly created observation, but the same applies if you use the `@Observed` annotation or another instrumentation library.
134
+
Therefore, when OIV is enabled, pay careful attention to observation boundaries — especially if the observation includes database access.
95
135
96
-
To disable OSIV, set `spring.jpa.open-in-view=false`.
136
+
In upcoming versions, we plan to narrow the scope of connection observations to better support the OIV pattern.
0 commit comments