open-telemetry / open-telemetry/opentelemetry-java-instrumentation

influxdb-2.4: capture db.operation.batch.size for BatchPoints writes

Open Beginner friendly
#19,264 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
2.6k
Forks
1.2k
Avg merge
2d 16h
Merged PRs (30d)
214

Description

Is your feature request related to a problem? Please describe.

The influxdb-2.4 instrumentation records db.operation.name for writes, but it never records db.operation.batch.size, even though a write through InfluxDB.write(BatchPoints) sends a whole batch of points in a single request.

db.operation.batch.size is a stable database semantic-convention attribute, and the point count is readily available on the BatchPoints object the instrumentation already has in hand (BatchPoints.getPoints()). As a result a batch write of, say, 500 points looks identical on the span to a write of a single point, so there is no way to tell how much data a write span actually moved.

Other database instrumentations already capture this. For example, HBase records the batch size for its multi-action operations:

Instrumentation Batch operation db.operation.batch.size captured?
hbase-client HTable.batch(List<Row>) Yes (HbaseRequest.getOperationBatchSize())
influxdb-2.4 InfluxDB.write(BatchPoints) No

The information is dropped even though the client hands it straight to the advice:

flowchart LR
  A["influxDb.write(batchPoints)<br/>batchPoints has N points"] --> B["InfluxDbModifyAdvice.onEnter<br/>arg0 = BatchPoints"]
  B --> C["InfluxDbOperation.create(host, port, database, &quot;write&quot;)<br/>point count is dropped here"]
  C --> D["InfluxDbAttributesGetter"]
  D -->|"db.operation.name = write"| E["write span"]
  D -. "getDbOperationBatchSize() not overridden, returns null" .-> E
  E --> F["db.operation.batch.size is never set"]
Describe the solution you'd like

Capture the number of points of a BatchPoints write and expose it as db.operation.batch.size, following the pattern already used by HBase.

Concretely, in instrumentation/influxdb-2.4:

  1. Add a nullable batchSize field to InfluxDbOperation (the @AutoValue request object).
  2. In InfluxDbImplInstrumentation.InfluxDbModifyAdvice#onEnter, when arg0 instanceof BatchPoints, read ((BatchPoints) arg0).getPoints().size() and pass it into InfluxDbOperation.create(...). It stays null for the UDP/createDatabase/deleteDatabase paths, where there is no batch.
  3. Override getDbOperationBatchSize in InfluxDbAttributesGetter to return that value.

No new configuration is needed. The shared DbClientAttributesExtractor already emits db.operation.batch.size under stable semconv and treats a size of 1 as a non-batch operation, so single-point writes are unaffected and only multi-point writes gain the attribute:

flowchart TB
  subgraph before["write span today"]
    B1["db.system.name = influxdb"]
    B2["db.namespace = mydb"]
    B3["db.operation.name = write"]
  end
  subgraph after["write span after the change"]
    A1["db.system.name = influxdb"]
    A2["db.namespace = mydb"]
    A3["db.operation.name = write"]
    A4["db.operation.batch.size = 2 (new)"]
  end
  before --> after

Expected result for the existing two-point write in InfluxDbClientTest#testQueryAndModifyWithOneArgument (which writes point1 and point2 in one BatchPoints): the write span gains db.operation.batch.size = 2.

Describe alternatives you've considered
  • Leave it as is. Writes remain indistinguishable regardless of how many points they carry, which loses useful signal that the client already exposes.
  • Emit the count as an experimental span attribute (e.g. influxdb.points.count) instead of the semconv attribute. This would duplicate an existing stable convention for no benefit, so the standard db.operation.batch.size is preferred.
  • Record every point as db.query.text. Rejected: point data is user data (line protocol values) and is not a query, so it should not be captured. Only the count is proposed here.
Additional context

Relevant files:

  • instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java
  • instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbOperation.java
  • instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbImplInstrumentation.java
  • instrumentation/influxdb-2.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbClientTest.java

Reference implementation for batch size in another database client: instrumentation/hbase/hbase-client-common-1.4/javaagent/.../HbaseAttributesGetter.java and HbaseRequest.java.

I would like to work on this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with InfluxDbImplInstrumentation.InfluxDbModifyAdvice#onEnter and the request model in instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbOperation.java. Review InfluxDbAttributesGetter.java and the HBase batch-size implementation, then run InfluxDbClientTest#testQueryAndModifyWithOneArgument. Done means the existing two-point write exposes db.operation.batch.size as 2 while non-batch paths remain unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases, observability
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.