open-telemetry / open-telemetry/opentelemetry-java-instrumentation
influxdb-2.4: capture db.operation.batch.size for BatchPoints writes
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, "write")<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:
- Add a nullable
batchSizefield toInfluxDbOperation(the@AutoValuerequest object). - In
InfluxDbImplInstrumentation.InfluxDbModifyAdvice#onEnter, whenarg0 instanceof BatchPoints, read((BatchPoints) arg0).getPoints().size()and pass it intoInfluxDbOperation.create(...). It staysnullfor the UDP/createDatabase/deleteDatabasepaths, where there is no batch. - Override
getDbOperationBatchSizeinInfluxDbAttributesGetterto 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 standarddb.operation.batch.sizeis 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.javainstrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbOperation.javainstrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbImplInstrumentation.javainstrumentation/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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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