| Crates.io | otel-instrumentation-neo4jrs |
| lib.rs | otel-instrumentation-neo4jrs |
| version | 0.2.1 |
| created_at | 2025-09-03 21:33:01.285439+00 |
| updated_at | 2025-09-10 08:46:27.608787+00 |
| description | OpenTelemetry instrumentation for neo4rs Neo4j driver |
| homepage | |
| repository | https://github.com/Executioner1939/otel-instrumentation-neo4jrs |
| max_upload_size | |
| id | 1823307 |
| size | 114,788 |
OpenTelemetry instrumentation for the neo4rs Neo4j driver, providing basic tracing for Neo4j database operations.
execute, run, start_txn)neo4rs::GraphDue to the neo4rs API design, this instrumentation has several limitations:
Query objectsexecute, run, etc.)Add this to your Cargo.toml:
[dependencies]
otel-instrumentation-neo4jrs = "0.1"
neo4rs = "0.8"
opentelemetry = "0.30"
tracing = "0.1"
# For metrics support
otel-instrumentation-neo4jrs = { version = "0.1", features = ["metrics"] }
use otel_instrumentation_neo4jrs::InstrumentedGraph;
use neo4rs::{ConfigBuilder, query};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize tracing
tracing_subscriber::fmt::init();
let config = ConfigBuilder::default()
.uri("bolt://localhost:7687")
.user("neo4j")
.password("password")
.build()?;
let graph = InstrumentedGraph::connect(config).await?;
// Execute queries - basic tracing is automatic
graph.execute(query("CREATE (n:Person {name: 'Alice'})")).await?;
graph.run(query("MATCH (n:Person) RETURN count(n)")).await?;
Ok(())
}
use neo4rs::Graph;
use otel_instrumentation_neo4jrs::GraphExt;
let graph = Graph::new("bolt://localhost:7687", "neo4j", "password").await?;
// Add basic tracing
let instrumented = graph.with_telemetry().await?;
// Or trace individual queries
graph.execute_traced(query("MATCH (n) RETURN count(n)")).await?;
use otel_instrumentation_neo4jrs::InstrumentedGraphBuilder;
use opentelemetry_sdk::metrics::SdkMeterProvider;
let meter_provider = SdkMeterProvider::builder().build();
let meter = meter_provider.meter("neo4j");
let graph = InstrumentedGraphBuilder::new(config)
.with_metrics(meter)
.build()
.await?;
let txn = graph.start_txn().await?; // Creates a transaction span
// Operations within transaction create child spans
txn.run(query("CREATE (n:Order {id: 1})")).await?;
txn.commit().await?; // Records completion
Spans include basic OpenTelemetry semantic convention attributes:
db.system = "neo4j"otel.kind = "client"db.name - Database name (retrieved from server)server.address - Server address (from NEO4J_SERVER_ADDRESS env var, defaults to "localhost")server.port - Server port (from NEO4J_SERVER_PORT env var, defaults to 7687)db.version - Neo4j server version (queried from server)Note: Due to neo4rs limitations, query text, operation types, and parameters are not available as span attributes.
metrics feature)When metrics are enabled:
| Metric | Type | Description |
|---|---|---|
neo4j.queries.total |
Counter | Total queries executed |
neo4j.query.duration |
Histogram | Query execution time (ms) |
neo4j.transactions.total |
Counter | Transactions started |
neo4j.transaction.duration |
Histogram | Transaction duration (ms) |
neo4j.connections.active |
UpDownCounter | Active connections |
neo4j.errors.total |
Counter | Total errors |
NEO4J_SERVER_ADDRESS - Server address for telemetry (default: "localhost")NEO4J_SERVER_PORT - Server port for telemetry (default: 7687)SERVICE_NAME - Service name for spansThis library provides:
This library does NOT provide:
This project is licensed under the MIT License - see the LICENSE file for details.