OpenTelemetry Instrumentation for kafka-python

Automatic OpenTelemetry tracing for the synchronous kafka-python producer and consumer

Library
PyPI
v0.66b1
1,119 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
95 /100 Excellent
Development Activity 100
Maintenance 100
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 78
Code Quality 80
Innovation 58
Learning Curve 82

opentelemetry-instrumentation-kafka-python wraps the widely-used synchronous kafka-python (and kafka-python-ng) client so every message produced or consumed automatically generates an OpenTelemetry span, without changes at each call site. It registers via the standard opentelemetry_instrumentor entry point and exposes produce and consume hooks so applications can attach custom span attributes, part of the broader OpenTelemetry Python contrib instrumentation suite maintained in the opentelemetry-python-contrib monorepo.

What You Get

  • One-line KafkaInstrumentor().instrument() call that patches KafkaProducer and KafkaConsumer to emit spans automatically
  • Produce and consume hooks (produce_hook, consume_hook) for attaching custom span attributes at send/receive time
  • Standard OpenTelemetry semantic-convention attributes for Kafka messaging spans, compatible with any OTel-configured exporter/backend
  • Automatic entry-point registration (opentelemetry_instrumentor) so the instrumentor can be discovered by the OpenTelemetry auto-instrumentation agent

Common Use Cases

  • Tracing message flow through synchronous Kafka producers and consumers in a threaded or WSGI-style application
  • Correlating Kafka produce/consume spans with upstream HTTP or RPC spans in a distributed trace
  • Attaching custom business attributes (e.g. order ID, tenant ID) to Kafka spans via the produce/consume hooks
  • Feeding Kafka messaging telemetry into an existing OpenTelemetry Collector / observability backend with zero manual span code

Under The Hood

Architecture - The instrumentor lives at instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py and follows the standard OpenTelemetry Python instrumentor pattern: a KafkaInstrumentor class (subclassing BaseInstrumentor) monkey-patches KafkaProducer.send and the consumer’s iteration/poll methods to wrap calls in spans, with utils.py housing shared span-attribute-building logic reused across both the sync and async (aiokafka) instrumentors. Tech Stack - Pure Python (requires-python >=3.10), built with hatchling, depending on opentelemetry-api, opentelemetry-instrumentation, and opentelemetry-semantic-conventions (pinned to the monorepo’s synchronized release version), with kafka-python or kafka-python-ng as optional instruments-any extras so the base package installs without pulling in either client variant. Code Quality - Tests live under tests/, covering both kafka-python and kafka-python-ng variants via separate requirements files (test-requirements.txt, test-requirements-ng.txt), following the same conventions used across the ~70 other instrumentation packages in the opentelemetry-python-contrib monorepo, with shared CI, linting, and release tooling. API Design - The API mirrors every other OpenTelemetry Python instrumentor: instrument()/uninstrument() lifecycle methods, an optional tracer_provider kwarg, and hook callables with a fixed (span, args, kwargs) (or (span, record, args, kwargs) for consume) signature — this consistency across the whole instrumentation family lowers the learning curve for anyone who has used another OTel Python instrumentor before.

Used by 91 apps in this directory

Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 6 days ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 6 days ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 6 days ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 6 days ago
Python
71%
MIT

Langflow

AI Agents · AI Development

155,973

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
64
Dependency
Built with
Python 71%
TypeScript 21%
Updated 6 days ago
Python
71%
MIT

Langflow

AI Agents · AI Development

155,973

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
64
Dependency
Built with
Python 71%
TypeScript 21%
Updated 6 days ago
TypeScript
78%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,733

Open-source AI agent monitoring that catches what will break next before your users do.

View details
87
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 78%
Python 11%
Rust 11%
Updated 1 weeks ago
Python
84%
MIT

LiteLLM

AI Development · Developer Tools

61,933

Open source AI gateway and Python SDK that gives you one OpenAI-compatible interface to call 100+ LLM providers, with built-in routing, cost tracking, guardrails, and virtual keys.

View details
93
Repo Health
81
Technical
69
Dependency
Built with
Python 84%
TypeScript 11%
Updated 6 days ago
Python
66%
Other

Morphik

AI Development · Databases · Search

3,717

Morphik is an AI-native ingestion and retrieval engine that lets developers store, search, and reason over visually rich documents — scanned PDFs, manuals, slides, and video — without duct-taping together OCR, an embedding model, and a vector database.

View details
64
Repo Health
71
Technical
67
Dependency
Built with
Python 66%
TypeScript 23%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers