Elasticsearch (tracing)
Elasticsearch (tracing)
Elasticsearch is a distributed search and analytics engine. Respan’s instrumentation wraps the official Python client’s shared transport boundary, so the synchronous Elasticsearch client and asynchronous AsyncElasticsearch client receive the same tracing coverage.
Each request emits a canonical Respan task span with its operation, sanitized target, status, timing, and optional request and response content.
Set up Respan
Create an account at platform.respan.ai and grab an API key.
Run npx @respan/cli setup to set up with your coding agent.
Example projects
Tracing
Setup
Set environment variables
Your Elasticsearch connection can point to a local cluster, Elastic Cloud, or another compatible deployment.
Initialize and run
Passing ElasticsearchInstrumentor() to Respan activates and later deactivates the transport patches for you.
View your trace
Open the Traces page and search for workflow name elasticsearch_search_workflow. The workflow contains nested elasticsearch.index and elasticsearch.search task spans.
Asynchronous client
AsyncElasticsearch is covered by the same instrumentor; no additional setup is required.
Covered operations
The transport-level integration covers every request made by the official clients. Common operation names include:
Content capture
Request and response bodies are captured by default. Disable content capture when documents, queries, or results may contain sensitive data:
With capture disabled, spans retain the operation, sanitized target, HTTP status, timing, and exception type while omitting request and response bodies. Document and task identifiers in targets are sanitized, and request headers are never captured.
Errors
Transport exceptions are re-raised after the span records OpenTelemetry error status, status_code, and error.message. HTTP error responses are marked the same way. When content capture is disabled, backend response details and exception messages are replaced with a generic status or exception type.
Configuration
Add request metadata
Use propagate_attributes to group Elasticsearch activity by user, thread, or application metadata.
Lifecycle
Activation and deactivation are idempotent and shared safely across multiple instrumentor instances. When you pass the instrumentor to Respan, call respan.shutdown() when the process exits so spans are flushed and the final shared transport patches are removed.