Manually capturing database statement

The Elastic Java agent is able to automatically capture "database" statement e.g. when firing a request to Elastic Search:

This happens in the Elastic Java agent instrumentation using the span.db.statement field. The main benefit over context fields is that this is nicely highlighted and more visible.

We're using our own GraphQL server implementation so no automatic instrumentation. While manually instrumenting our application I can only access transaction and span labels and context fields.

Is there any way I can set the span.db.statement field when manually instrumenting?

Hi,

I see two ways to implement that:

  • with Elastic agent API: create a span and store it as a context field, then use an ingest pipeline to modify the stored document with the appropriate span.db.statement field value.

  • with OpenTelemetry API: create a span and follow the semantic conventions for databases, use the db.statement attribute to store the query.

Disclamer: I haven't tried it myself, and some experimentation might be needed here.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.