Skip to content

Conversation

injectives
Copy link
Contributor

BREAKING CHANGE: the experimental driver Metrics and ConnectionPoolMetrics have been replaced with ObservationProvider.

Observation SPI

NOTE: This is a feature preview.

The Observation SPI is used by the driver to instrument points of interest in its implementation. For instance, an observation is created around connection acquisition - it starts when acquisition begins and stops when acquisition ends. These observations may be used by SPI implementations to produce some useful output, like: metrics, traces, etc. Importantly, this resposibility is outside the instrumentation itself.

Driver configuration example:

var config = Config.builder()
        .withObservationProvider(implementation) // null by default, meaning no-op implementation
        .build()

At present, the SPI is not expected to be implemented by users directly. Instead, 2 new implementation modules are introduced alongside the driver. Their versions will be managed by the driver BOM (neo4j-java-driver-bom). Both are described below.

Neo4j Java Driver (Metrics)

NOTE: This is a feature preview.

Artifact ID: neo4j-java-driver-observation-metrics

A basic in-memory implementation with dedicated API - Metrics and ConnectionPoolMetrics, the effectively relocated interfaces from the driver.

Driver configuration example:

var provider = MetricsObservationProvider.newInstance();
var config = Config.builder()
        .withObservationProvider(provider) // enable by registering the provider
        .build();
var metrics = provider.metrics();

Neo4j Java Driver (Micrometer Observation)

NOTE: This is a feature preview.

Artifact ID: neo4j-java-driver-observation-micrometer

An implementation based Micrometer Observation API.

Driver observations are represented as dedicated Micrometer types:

  • Observation.Context
    • For example, SessionRunContext.
  • ObservationConvention
    • For example, SessionRunConvention.
  • Default ObservationConvention
    • For example, DefaultSessionRunConvention.

The dedicated types enable users to benefit from Micrometer features, including high level of customisation of handling, naming and tagging.

While the naming used in this module was guided by the OpenTelemetry semantic conventions 1.36.0, it was also adapted to Micrometer naming convention.

Driver configuration example:

var provider = MicrometerObservationProvider.builder(observationRegistry) // requires Micrometer ObservationRegistry instance
        .build(); // extra options are omitted for brevity
var config = Config.builder()
        .withObservationProvider(provider) // enable by registering the provider
        .build();

In addition, it includes ConnectionPoolMetricsHandler that implements Micrometer ObservationHandler. It manages several additional Micrometer metrics and may be optionally instantiated and registered by users.

@injectives injectives force-pushed the feature/observability branch 30 times, most recently from ab24ad9 to 8f8a462 Compare August 6, 2025 21:03
@injectives injectives force-pushed the feature/observability branch 15 times, most recently from c50590e to a1e7b06 Compare August 8, 2025 19:08
BREAKING CHANGE: the experimental driver `Metrics` and `ConnectionPoolMetrics` have been replaced with `ObservationProvider`.

 ## Observation SPI

NOTE: This is a feature preview.

The Observation SPI is used by the driver to instrument points of interest in its implementation. For instance, an observation is created around connection acquisition - it starts when acquisition begins and stops when acquisition ends. These observations may be used by SPI implementations to produce some useful output, like: metrics, traces, etc. Importantly, this resposibility is outside the instrumentation itself.

Driver configuration example:

```java
var config = Config.builder()
        .withObservationProvider(implementation) // null by default, meaning no-op implementation
        .build()
```

At present, the SPI is not expected to be implemented by users directly. Instead, 2 new implementation modules are introduced alongside the driver. Their versions will be managed by the driver BOM (`neo4j-java-driver-bom`). Both are described below.

 ### Neo4j Java Driver (Metrics)

NOTE: This is a feature preview.

Artifact ID: `neo4j-java-driver-observation-metrics`

A basic in-memory implementation with dedicated API - `Metrics` and `ConnectionPoolMetrics`, the effectively relocated interfaces from the driver.

Driver configuration example:

```java
var provider = MetricsObservationProvider.newInstance();
var config = Config.builder()
        .withObservationProvider(provider) // enable by registering the provider
        .build();
var metrics = provider.metrics();
```

 ### Neo4j Java Driver (Micrometer Observation)

NOTE: This is a feature preview.

Artifact ID: `neo4j-java-driver-observation-micrometer`

An implementation based Micrometer Observation API.

Driver observations are represented as dedicated Micrometer types:
- `Observation.Context`
    - For example, `SessionRunContext`.
- `ObservationConvention`
    - For example, `SessionRunConvention`.
- Default `ObservationConvention`
    - For example, `DefaultSessionRunConvention`.

The dedicated types enable users to benefit from Micrometer features, including high level of customisation of handling, naming and tagging.

While the naming used in this module was guided by the OpenTelemetry semantic conventions 1.36.0, it was also adapted to Micrometer naming convention.

Driver configuration example:

```java
var provider = MicrometerObservationProvider.builder(observationRegistry) // requires Micrometer ObservationRegistry instance
        .build(); // extra options are omitted for brevity
var config = Config.builder()
        .withObservationProvider(provider) // enable by registering the provider
        .build();
```

In addition, it includes `ConnectionPoolMetricsHandler` that implements Micrometer `ObservationHandler`. It manages several additional Micrometer metrics and may be optionally instantiated and registered by users.
@injectives injectives force-pushed the feature/observability branch from a1e7b06 to c278558 Compare August 12, 2025 13:56
Copy link

@MaxAake MaxAake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@injectives injectives requested a review from MaxAake August 13, 2025 09:32
Copy link

@MaxAake MaxAake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@injectives injectives requested a review from MaxAake August 13, 2025 09:50
Copy link

@MaxAake MaxAake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@injectives injectives merged commit 2c66e06 into neo4j:6.x Aug 13, 2025
14 of 20 checks passed
@injectives injectives deleted the feature/observability branch August 13, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants