Commit 2e49ba1
Use a weak reference to sqlalchemy Engine to avoid memory leak (#1771)
* Use a weak reference to sqlalchemy Engine to avoid memory leak
Closes #1761
By using a weak reference to the `Engine` object, we can avoid the memory leak as disposed `Engines` get properly deallocated. Whenever `SQLAlchemy` is uninstrumented, we only trigger a removal for those event listeners which are listening for objects that haven't been garbage-collected yet.
* Made a mistake in resolving the weak reference
* Fixed formatting issues
* Updated changelog
* Added unit test to check that engine was garbage collected
* Do not save engine in EngineTracer to avoid memory leak
* Add an empty line to satisfy black formatter
* Fix isort complaints
* Fixed the issue when pool name is not set and =None
* Fix formatting issue
* Rebased after changes in a recent commit
* Updated PR number in changelog
---------
Co-authored-by: Shalev Roda <[email protected]>1 parent a45c9c3 commit 2e49ba1
File tree
3 files changed
+60
-18
lines changed- instrumentation/opentelemetry-instrumentation-sqlalchemy
- src/opentelemetry/instrumentation/sqlalchemy
- tests
3 files changed
+60
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
Lines changed: 35 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | | - | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | 122 | | |
134 | 123 | | |
135 | 124 | | |
136 | 125 | | |
137 | | - | |
| 126 | + | |
138 | 127 | | |
139 | 128 | | |
140 | 129 | | |
| |||
143 | 132 | | |
144 | 133 | | |
145 | 134 | | |
146 | | - | |
| 135 | + | |
147 | 136 | | |
148 | 137 | | |
149 | 138 | | |
| |||
169 | 158 | | |
170 | 159 | | |
171 | 160 | | |
172 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
173 | 164 | | |
174 | 165 | | |
175 | 166 | | |
176 | | - | |
177 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
178 | 176 | | |
179 | 177 | | |
180 | 178 | | |
| |||
300 | 298 | | |
301 | 299 | | |
302 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
0 commit comments