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
fix(kafka): trace using subclass of producer/consumer, not objectproxy [Backport #5545 to 1.12] (#5661)
Backport #5545 to 1.12.
Fixes#5494.
Previously, we patched `confluent-kafka` by wrapping the
`Producer/Consumer` classes with an ObjectProxy
`TracedProducer/TracedConsumer` class. However, since
`confluent-kafka`'s `Producer/Consumer` classes are implemented in C and
have strictly defined slots, our traced classes break for subclasses
such as `AvroProducer/AvroConsumer`.
This PR fixes the issue by basing our traced classes from
`confluent-kafka`'s base `Producer/Consumer` classes directly instead of
using an ObjectProxy. Local testing shows that the bug from #5494 is
resolved.
Before:
```
>>> from ddtrace import patch_all
>>> patch_all()
>>> from confluent_kafka.avro import AvroConsumer
>>> AvroConsumer({"group.id": 12345}, "http://localhost:8080")
<stdin>:1: DeprecationWarning: AvroConsumer has been deprecated. Use AvroDeserializer instead.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/yun.kim/go/src/github.com/DataDog/dd-trace-py/.riot/venv_py3105_mock_pytest_pytest-mock_coverage_pytest-cov_opentracing_hypothesis6451_confluent-kafka/lib/python3.10/site-packages/confluent_kafka/avro/__init__.py", line 161, in __init__
self._serializer = MessageSerializer(schema_registry, reader_key_schema, reader_value_schema)
AttributeError: 'cimpl.Consumer' object has no attribute '_serializer'
```
After:
```
>>> from ddtrace import patch_all
>>> patch_all()
>>> from confluent_kafka.avro import AvroConsumer
>>> AvroConsumer({"group.id": 12345}, "http://localhost:8080")
<stdin>:1: DeprecationWarning: AvroConsumer has been deprecated. Use AvroDeserializer instead.
<confluent_kafka.avro.AvroConsumer object at 0x10479a680>
```
## Checklist
- [x] Change(s) are motivated and described in the PR description.
- [x] Testing strategy is described if automated tests are not included
in the PR.
- [x] Risk is outlined (performance impact, potential for breakage,
maintainability, etc).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines)
are followed.
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/)).
- [x] PR description includes explicit acknowledgement/acceptance of the
performance implications of this PR as reported in the benchmarks PR
comment.
## Reviewer Checklist
- [x] Title is accurate.
- [x] No unnecessary changes are introduced.
- [x] Description motivates each change.
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes unless absolutely necessary.
- [x] Testing strategy adequately addresses listed risk(s).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] Release note makes sense to a user of the library.
- [x] Reviewer has explicitly acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment.
0 commit comments