elastic / elastic/apm-agent-python
Celery integration's trace_parent_string header injection corrupts AMQP message on publish, crashes RabbitMQ
- 主要言語
- Python
- スター
- 431
- フォーク
- 239
- 平均マージ
- 5日 10時間
- マージ済み PR(30日)
- 7
説明
### Summary
`elasticapm.contrib.celery.set_celery_headers` (connected to celery's `before_task_publish` signal by `register_instrumentation`) injects `headers["elasticapm"]["trace_parent_string"]` into every task published during an active APM transaction. When celery merges this custom header with its own built-in protocol headers (kwargsrepr, origin, etc.) into the AMQP wire format, the resulting header table is corrupted and RabbitMQ's broker cannot decode it — crashes the channel, then the whole connection (amqp.exceptions.InternalError 541 on the client).
### Environment
- elastic-apm 6.25.0 (checked 6.26.0/6.26.1/6.26.2 changelogs — no related fix)
- celery 5.6.1, kombu 5.6.2, amqp (py-amqp) 5.3.1
- RabbitMQ broker, AMQPS/TLS, Python 3.13
### Evidence
549 broker-side crashes over a 14h production window, 100% on tasks published from an active APM HTTP transaction (i.e. wherever a view calls `.delay()`), across 9+ different task types. Byte-exact reimplementation of RabbitMQ's parse_table confirms 549/549 fail at the identical byte — an invalid type tag right before the literal "kwargsrepr" header key, whose name-length prefix (should be 0x0A) is corrupted to 0x00. Only reproduces when the "elasticapm" header key from `set_celery_headers` is present.
Full technical writeup / sample bytes: see companion issue celery/celery#10412 (root mechanism looks like it's on celery's side, in how it merges custom `headers=` with its own protocol headers — but filing here too since `set_celery_headers`'s use of a nested dict-under-a-custom-key is what triggers celery's merge path).
### Ask
Is `set_celery_headers`'s header shape (a dict value under a single custom top-level key) known to interact badly with celery's own header-stamping/merge? Workaround note: elastic/apm-agent-python#1370 mentions a prior "Celery bug concerning its headers field" with a `{"headers": {...}}` double-nesting workaround — wondering if that's still needed / whether this is the same underlying issue resurfacing.
Happy to share the full 549-sample dataset and parse simulator.
コントリビューションガイド
調査の方向性
elasticapm.contrib.celery.set_celery_headers と register_instrumentation を介したその登録から始め、次に、記載されている Celery、Kombu、AMQP、RabbitMQ のバージョンでパブリッシングを再現します。ネストされた elasticapm ヘッダーの動作を celery/celery#10412 および elastic/apm-agent-python#1370 の workaround と比較します。原因と、互換性のあるヘッダー形式または workaround が確立されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python, rabbitmq
- 領域
- backend, distributed-systems
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100