Registry / observability / opentelemetry-instrumentation-pymemcache

opentelemetry-instrumentation-pymemcache

JSON →
library0.65b0pypypi✓ verified 24d ago

This library provides OpenTelemetry instrumentation for `pymemcache`, enabling automatic tracing of Memcached client operations. It is part of the `opentelemetry-python-contrib` project, which generally follows a monthly release cadence. As of version 0.62b0, the instrumentation libraries within `opentelemetry-python-contrib` are considered beta and may undergo breaking changes.

pip install opentelemetry-instrumentation-pymemcache pymemcache opentelemetry-sdk opentelemetry-exporter-otlp
INSTALL
IMPORT
SIG · OPENTELEMETRY-INST
O
opentelemetry-instrumentation-pymemcache
observabilitypythonv0.65b0
Install
5.2s avg
Import
405ms
Disk
50MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.65b0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.430s · 52.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.2s · import 0.380s · 51MB
50MB installed
● package 50MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PymemcacheInstrumentor
from opentelemetry.instrumentation.pymemcache import PymemcacheInstrumentor

This example sets up a basic OpenTelemetry tracing environment with an OTLP exporter, instruments the `pymemcache` library, and then demonstrates typical `pymemcache` client operations. Spans for `set`, `get`, and `delete` operations will be generated and sent to the configured OTLP endpoint (e.g., an OpenTelemetry Collector).

import os from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter from opentelemetry.instrumentation.pymemcache import PymemcacheInstrumentor from pymemcache.client.base import Client # Configure OpenTelemetry Tracer Provider provider = TracerProvider() processor = BatchSpanProcessor(OTLPSpanExporter(endpoint=os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', 'localhost:4317'))) provider.add_span_processor(processor) trace.set_tracer_provider(provider) # Instrument pymemcache PymemcacheInstrumentor().instrument() # Use pymemcache as usual # Ensure a memcached server is running at localhost:11211 try: client = Client(('localhost', 11211)) client.set('my_key', 'my_value') value = client.get('my_key') print(f"Retrieved value: {value.decode('utf-8') if value else None}") client.delete('my_key') except Exception as e: print(f"Error connecting to Memcached or during operation: {e}") print("Please ensure a memcached server is running at localhost:11211") # Flush spans before exiting provider.shutdown()
Debug
Known issues
gotchaOpenTelemetry Python Contrib instrumentations are currently in beta, which means they are not recommended for production environments. Breaking changes to APIs or telemetry output may occur in future releases without major version bumps.
fix
Monitor release notes for breaking changes. Exercise caution when deploying to production and consider locking dependency versions.
affects: All versions < 1.0.0
gotchaWhen using pre-forking web servers (e.g., Gunicorn with `workers > 1`), auto-instrumentation, particularly for metrics, can lead to inconsistent or broken telemetry due to issues with background threads and locks being duplicated or not properly initialized in child processes after forking.
fix
For Gunicorn, consider using a single worker (`--workers 1`), or implement programmatic instrumentation where you initialize the OpenTelemetry SDK in each worker process after forking. For metrics, using a `PeriodicExportingMetricReader` with one OTLP worker per process to push to a Prometheus server is also recommended.
affects: All versions
gotchaRunning applications with Flask's debug mode enabled (which uses a reloader) can interfere with OpenTelemetry's instrumentation, causing it to break or not function as expected.
fix
Disable Flask's debug mode when using OpenTelemetry instrumentation, especially in environments where robust tracing is critical.
affects: All versions
gotchaThe OpenTelemetry semantic conventions, which define the names and attributes of telemetry data, are still evolving. This means that the attributes recorded by `opentelemetry-instrumentation-pymemcache` might change in future versions, potentially breaking dashboards, alerts, or analysis tools configured against current attribute names.
fix
Stay informed about semantic convention updates from the OpenTelemetry project. Be prepared to update monitoring configurations as semantic conventions stabilize and are adopted by the instrumentation.
affects: All versions < stable semantic conventions
Upgrade
Version history
0.65b0latest on PyPI · released Jul 16, 2026
Audit
Dependencies
pymemcacherequiredThe underlying library being instrumented.
opentelemetry-apirequiredCore OpenTelemetry API for defining telemetry signals.
opentelemetry-sdkrequiredOpenTelemetry Python SDK for processing and exporting telemetry. Applications should depend on this or another SDK.
opentelemetry-exporter-otlpoptionalRequired for exporting telemetry data via OTLP, as shown in the quickstart example.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
opentelemetry-instrumentation-pymemcache — pip install opentelemetry-instrumentation-pymemcache · libregistry