OpenTelemetry Aerospike instrumentation
Project description
OpenTelemetry Aerospike Instrumentation
OpenTelemetry instrumentation for the Aerospike Python Client.
This library enables automatic tracing of Aerospike database operations, providing visibility into your application's database interactions.
Installation
pip install opentelemetry-instrumentation-aerospike
ㅣ
Requirements
- Python >= 3.9
- aerospike >= 17.2.0
- opentelemetry-api >= 1.12
- opentelemetry-instrumentation >= 0.40b0
Usage
Basic Usage
import aerospike
from opentelemetry.instrumentation.aerospike import AerospikeInstrumentor
# Instrument Aerospike BEFORE creating any clients
AerospikeInstrumentor().instrument()
# Create and use client as normal - all operations will be traced
config = {'hosts': [('127.0.0.1', 3000)]}
client = aerospike.client(config)
client.connect()
# Operations are now automatically traced
client.put(('test', 'demo', 'key1'), {'name': 'John', 'age': 30})
key, meta, bins = client.get(('test', 'demo', 'key1'))
client.close()
With Custom Tracer Provider
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
# Setup tracer provider
provider = TracerProvider()
processor = BatchSpanProcessor(OTLPSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
# Instrument with custom tracer provider
AerospikeInstrumentor().instrument(tracer_provider=provider)
Using Hooks
You can use hooks to customize span attributes or add custom logic:
def request_hook(span, operation, args, kwargs):
"""Called before each database operation."""
span.set_attribute("custom.request.id", get_request_id())
def response_hook(span, operation, result):
"""Called after a successful operation."""
if isinstance(result, tuple) and len(result) >= 3:
span.set_attribute("custom.record.bins", len(result[2]))
def error_hook(span, operation, exception):
"""Called when an operation fails."""
span.set_attribute("custom.error.code", getattr(exception, 'code', -1))
AerospikeInstrumentor().instrument(
request_hook=request_hook,
response_hook=response_hook,
error_hook=error_hook
)
Capturing Record Keys
By default, record keys are not captured for security reasons. To enable:
AerospikeInstrumentor().instrument(capture_key=True)
⚠️ Security Warning: Only enable key capture in development or when keys don't contain sensitive information.
Uninstrumenting
instrumentor = AerospikeInstrumentor()
instrumentor.instrument()
# ... use client ...
# Remove instrumentation
instrumentor.uninstrument()
Span Attributes
The instrumentation follows OpenTelemetry Semantic Conventions for Database.
Standard Attributes
| Attribute | Description | Example |
|---|---|---|
db.system |
Database system identifier | aerospike |
db.namespace |
Aerospike namespace | test |
db.collection.name |
Aerospike set name | users |
db.operation.name |
Operation name | PUT, GET, QUERY |
db.operation.batch.size |
Batch operation size | 100 |
server.address |
Server hostname/IP | 127.0.0.1 |
server.port |
Server port | 3000 |
Error Attributes
| Attribute | Description | Example |
|---|---|---|
error.type |
Exception class name | RecordNotFound |
db.response.status_code |
Aerospike error code | 2 |
Aerospike-Specific Attributes
| Attribute | Description | Example |
|---|---|---|
db.aerospike.key |
Record key (if enabled) | user123 |
db.aerospike.generation |
Record generation | 5 |
db.aerospike.ttl |
Record TTL in seconds | 86400 |
db.aerospike.udf.module |
UDF module name | mymodule |
db.aerospike.udf.function |
UDF function name | myfunction |
Span Naming
Spans are named following the convention: {OPERATION} {namespace}.{set}
Examples:
PUT test.usersGET production.ordersBATCH GET test.demoQUERY test.eventsSCAN production.logs
Supported Operations
Single Record Operations
put,get,select,exists,remove,touchoperate,append,prepend,increment
Batch Operations
batch_read,batch_write,batch_operate,batch_remove,batch_apply
Query/Scan Operations
query,scan
UDF Operations
apply,scan_apply,query_apply
Admin Operations
truncate,info_all
Async Pattern Support
The instrumentation works with async wrapper patterns commonly used in production:
import asyncio
import functools
from concurrent.futures import ThreadPoolExecutor
class AsyncAerospikeClient:
def __init__(self, client):
self._client = client
self._executor = ThreadPoolExecutor(max_workers=10)
def __getattr__(self, attr):
async def method(*args, **kwargs):
loop = asyncio.get_running_loop()
return await loop.run_in_executor(
self._executor,
functools.partial(getattr(self._client, attr), *args, **kwargs)
)
return method
# Instrument before creating clients
AerospikeInstrumentor().instrument()
# Create sync client (instrumented)
config = {'hosts': [('127.0.0.1', 3000)]}
sync_client = aerospike.client(config)
sync_client.connect()
# Wrap with async pattern
async_client = AsyncAerospikeClient(sync_client)
# Async operations are traced!
async def main():
await async_client.put(('test', 'demo', 'key1'), {'data': 'value'})
result = await async_client.get(('test', 'demo', 'key1'))
Development
Setup
# Clone repository
git clone https://github.com/your-repo/opentelemetry-instrumentation-aerospike.git
cd opentelemetry-instrumentation-aerospike
# Create virtual environment
uv venv
source .venv/bin/activate
# Install with dev dependencies
uv pip install -e ".[dev]"
Running Tests
# Start Aerospike (Docker)
docker run -d --name aerospike-test -p 3000:3000 aerospike/aerospike-server:latest
# Run integration tests
pytest tests/test_aerospike_integration.py -v
# Run with coverage
pytest --cov=opentelemetry.instrumentation.aerospike --cov-report=html
Code Quality
# Format code
black src tests
isort src tests
# Lint
ruff check src tests
# Type check
mypy src
License
Apache License 2.0
Contributing
Contributions are welcome! Please read our Contributing Guide for details.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opentelemetry_instrumentation_aerospike-0.2.3.tar.gz.
File metadata
- Download URL: opentelemetry_instrumentation_aerospike-0.2.3.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e71aa21c6d03020e4b51b52e9020f7463e254b096e9a365f884cfd854196848
|
|
| MD5 |
bdabaef3ac8a44983a400eb5cf508792
|
|
| BLAKE2b-256 |
f8e652336c1eff84ee3ea8d770020210b16a2763d409bc6b117d74b7592d21ff
|
Provenance
The following attestation bundles were made for opentelemetry_instrumentation_aerospike-0.2.3.tar.gz:
Publisher:
publish.yml on KimSoungRyoul/opentelemetry-instrumentation-aerospike
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opentelemetry_instrumentation_aerospike-0.2.3.tar.gz -
Subject digest:
9e71aa21c6d03020e4b51b52e9020f7463e254b096e9a365f884cfd854196848 - Sigstore transparency entry: 745795420
- Sigstore integration time:
-
Permalink:
KimSoungRyoul/opentelemetry-instrumentation-aerospike@fb797289d9d8a44e6c9c8462aaf3752cb2a8fbd3 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/KimSoungRyoul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb797289d9d8a44e6c9c8462aaf3752cb2a8fbd3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file opentelemetry_instrumentation_aerospike-0.2.3-py3-none-any.whl.
File metadata
- Download URL: opentelemetry_instrumentation_aerospike-0.2.3-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee890c7f02b8180547a62733494e345f1e50ac1c6b520495c0b51bc4e1db45fe
|
|
| MD5 |
2f852ae3927ab77d3197515d1af8cce8
|
|
| BLAKE2b-256 |
7b9c611fe7a6f52a1353d525b1e0a1e42e19e8f11fbe0797a59f8dd2d19cd4cb
|
Provenance
The following attestation bundles were made for opentelemetry_instrumentation_aerospike-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on KimSoungRyoul/opentelemetry-instrumentation-aerospike
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opentelemetry_instrumentation_aerospike-0.2.3-py3-none-any.whl -
Subject digest:
ee890c7f02b8180547a62733494e345f1e50ac1c6b520495c0b51bc4e1db45fe - Sigstore transparency entry: 745795445
- Sigstore integration time:
-
Permalink:
KimSoungRyoul/opentelemetry-instrumentation-aerospike@fb797289d9d8a44e6c9c8462aaf3752cb2a8fbd3 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/KimSoungRyoul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb797289d9d8a44e6c9c8462aaf3752cb2a8fbd3 -
Trigger Event:
release
-
Statement type: