Commit 2d9eaed
committed
observability: phase 6.1 PR-B logs SDK migration + filter bug fix
The OTel SDK's ``opentelemetry.sdk._logs.LoggingHandler`` is
deprecated and slated for removal in SDK 2.x. Migrate
``install_log_bridge`` to use the handler from
``opentelemetry-instrumentation-logging`` (the package the SDK's
deprecation message points at) so the deprecation goes away and
the bridge keeps working past SDK 2.x.
Constructor shape is unchanged (``LoggingHandler(level=...,
logger_provider=...)``); the contrib package's main public class
is ``LoggingInstrumentor`` but it's too opinionated for our use
(reads ``get_logger_provider()`` globally and overrides the
logging format) — direct handler import is the documented escape
hatch for callers like us with a caller-supplied LoggerProvider.
Dependency changes:
- Add ``opentelemetry-instrumentation-logging>=0.62.0b1`` to the
``[otel]`` extras. No upper bound — the contrib repo cycles
fast on minor releases below 1.0; revisit when 1.0 lands.
- Drop ``<2`` upper bound on ``opentelemetry-sdk``; replace with
``<3`` as a coarse safety cap. We no longer reach into the
deprecated path that prompted the original cap. Same shape on
``opentelemetry-api`` for parity.
- Remove the Phase 6.0 pending-migration comment block from
``pyproject.toml``.
The migration's new export-path test surfaced a real spec §7
violation in the existing bridge: ``_CorrelationIdFilter`` was
attached to the root logger, but Python's logging propagation
walks ancestor handlers and SKIPS ancestor filters, so child-
logger records (the normal ``logging.getLogger("module")``
pattern) shipped to the OTel exporter without the §7-mandated
``openarmature.correlation_id`` attribute. The existing
``test_log_bridge_filter_injects_correlation_id`` only called
``flt.filter()`` directly, never integration-tested through
``install_log_bridge`` + a child-logger emit + an export, which
is why the bug went unobserved through Phase 6.0 review,
round-7 followups, PR-A merge, and the fixture-031 span tests.
Fix: replace ``_CorrelationIdFilter`` with a process-global
``logging.setLogRecordFactory`` hook. The factory chains over any
prior factory (preserving user-installed factories), reads
``current_correlation_id()`` at record construction, and sets
``openarmature.correlation_id`` on every newly constructed record
— but only when a correlation_id is in scope per §7's "within
an invocation" qualifier. ``_FACTORY_MARKER`` attribute on the
wrapper function turns re-calls into no-ops; no stacked-wrapper
pathology.
Tests:
- ``test_log_bridge_filter_injects_correlation_id`` →
``test_log_record_factory_injects_correlation_id`` (calls the
installed factory directly, asserts null-cid + live-cid paths).
- ``test_install_log_bridge_is_idempotent`` extended to assert
factory identity is preserved across re-calls. Wrapped in
``warnings.catch_warnings("error")`` so the migrated path's
"no DeprecationWarning" guarantee is locked in.
- New ``test_log_bridge_exports_records_with_correlation_id``
emits on a CHILD logger (the load-bearing case) and asserts
the exported OTel ``LogRecord.attributes`` carry
``openarmature.correlation_id``. Wrapped in
``warnings.catch_warnings("error")``.
388 tests pass (was 387; net +1 from the new export-path test).
Pyright clean. The DeprecationWarning emitted by the prior
implementation is gone (warnings count: 4 → 3, the 3 remaining
are pre-existing intentional ``UserWarning``s from fixture
015-observer-error-isolation).1 parent c2c1eda commit 2d9eaed
4 files changed
Lines changed: 313 additions & 88 deletions
File tree
- src/openarmature/observability/otel
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
30 | 57 | | |
31 | | - | |
32 | | - | |
| 58 | + | |
33 | 59 | | |
| 60 | + | |
| 61 | + | |
34 | 62 | | |
35 | 63 | | |
36 | 64 | | |
37 | 65 | | |
38 | 66 | | |
39 | 67 | | |
40 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
41 | 72 | | |
42 | 73 | | |
43 | 74 | | |
| |||
47 | 78 | | |
48 | 79 | | |
49 | 80 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
65 | 95 | | |
66 | 96 | | |
67 | | - | |
68 | | - | |
| 97 | + | |
| 98 | + | |
69 | 99 | | |
70 | 100 | | |
71 | 101 | | |
72 | | - | |
| 102 | + | |
73 | 103 | | |
74 | 104 | | |
75 | | - | |
| 105 | + | |
76 | 106 | | |
77 | 107 | | |
78 | 108 | | |
| |||
87 | 117 | | |
88 | 118 | | |
89 | 119 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 120 | + | |
| 121 | + | |
95 | 122 | | |
96 | 123 | | |
97 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
| 306 | + | |
307 | 307 | | |
308 | | - | |
309 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
310 | 317 | | |
311 | 318 | | |
312 | 319 | | |
313 | 320 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
| 321 | + | |
| 322 | + | |
325 | 323 | | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
| 324 | + | |
| 325 | + | |
341 | 326 | | |
342 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
343 | 358 | | |
344 | | - | |
345 | | - | |
| 359 | + | |
| 360 | + | |
346 | 361 | | |
347 | 362 | | |
348 | 363 | | |
349 | 364 | | |
350 | | - | |
351 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
352 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
353 | 429 | | |
354 | 430 | | |
355 | 431 | | |
356 | 432 | | |
| 433 | + | |
357 | 434 | | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
364 | 470 | | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | 471 | | |
369 | 472 | | |
| 473 | + | |
370 | 474 | | |
371 | 475 | | |
372 | 476 | | |
| |||
0 commit comments