Skip to content

Conversation

@jmorrell-cloudflare
Copy link
Contributor

No description provided.

Comment on lines 666 to 681
name: 'd1_batch',
'db.system.name': 'cloudflare-d1',
'db.operation.name': 'batch',
'db.query.text':
'SELECT * FROM users WHERE user_id = ?;\n' +
'SELECT * FROM users WHERE user_id = ?;',
'db.operation.batch.size': 2,
'cloudflare.binding.type': 'D1',
'cloudflare.d1.response.size_after': 8192,
'cloudflare.d1.response.rows_read': 2,
'cloudflare.d1.response.rows_written': 0,
'cloudflare.d1.response.last_row_id': 2,
'cloudflare.d1.response.changed_db': false,
'cloudflare.d1.response.changes': 0,
'cloudflare.d1.response.queries_count': 2,
closed: true,
Copy link
Contributor Author

@jmorrell-cloudflare jmorrell-cloudflare Oct 22, 2025

Choose a reason for hiding this comment

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

@lambrospetrou This is an example of a batch span. All of the queries are visible here, and I've added a count.

My understanding based on #5218 (comment) is that what you would like to see is more like:

{
    name: 'd1_batch',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'batch',
    'db.query.text':
      'SELECT * FROM users WHERE user_id = ?;\n' +
      'SELECT * FROM users WHERE user_id = ?;',
    'db.operation.batch.size': 2,
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    'cloudflare.d1.response.queries_count': 2,
    'cloudflare.d1.response.meta':
      '[{"duration":0.0014168027188820064,"served_by":"d1-mock","changes":0,"last_row_id":2,"changed_db":false,"size_after":8192,"rows_read":1,"rows_written":0},{"duration":0.005165785717162432,"served_by":"d1-mock","changes":0,"last_row_id":2,"changed_db":false,"size_after":8192,"rows_read":1,"rows_written":0}]',
    closed: true,
}

or that but broken out into more fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lambrospetrou After thinking about it, I think the answer here is likely attaching these as span events. For each query in the batch emit a span event with the query, and all the meta data. That would keep it all queryable and clear.

However we don't yet have the ability to emit span events 😅 Mind if I file a ticket and come back to this?

function addAggregatedD1MetaToSpan(span: Span, metas: D1Meta[]): void {
const aggregatedMeta = aggregateD1Meta(metas);
addD1MetaToSpan(span, aggregatedMeta);
span.setAttribute('cloudflare.d1.response.queries_count', metas.length);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't necessary since we already had this data available under the semantic convention name: db.operation.batch.size: https://github.com/cloudflare/workerd/blob/main/src/cloudflare/internal/d1-api.ts#L207

@github-actions
Copy link

The generated output of @cloudflare/workers-types has been changed by this PR. If this is intentional, run just generate-types to update the snapshot. Alternatively, you can download the full generated types:

Full Type Diff

@jmorrell-cloudflare
Copy link
Contributor Author

I've tried a couple of things, but haven't been able to find a way to import the D1Meta type. Given that I'm not creating new duplication of types, but rather copying the pattern that was already present in the code, I think this is likely out-of-scope for my changes and will leave this up to the D1 team to resolve if they wish.

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.

1 participant