Skip to content

Add in Surreal DB client spans #1107 #2571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .chloggen/add_Surrealdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use this changelog template to create an entry for release notes.
#
# If your change doesn't affect end users you should instead start
# your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the area of concern in the attributes-registry, (e.g. http, cloud, db)
component: db

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: This adds SurrealDB as a db system.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
# The values here must be integers.
issues: [1107]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
2 changes: 2 additions & 0 deletions docs/database/database-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Parameterized query text SHOULD NOT be sanitized. Even though parameterized quer
| `sap.maxdb` | [SAP MaxDB](https://maxdb.sap.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `softwareag.adabas` | [Adabas (Adaptable Database System)](https://documentation.softwareag.com/?pf=adabas) | ![Development](https://img.shields.io/badge/-development-blue) |
| `sqlite` | [SQLite](https://www.sqlite.org/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `surrealdb` | [SurrealDB](https://surrealdb.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `teradata` | [Teradata](https://www.teradata.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `trino` | [Trino](https://trino.io/) | ![Development](https://img.shields.io/badge/-development-blue) |

Expand Down Expand Up @@ -396,6 +397,7 @@ Parameterized query text SHOULD NOT be sanitized. Even though parameterized quer
| `sap.maxdb` | [SAP MaxDB](https://maxdb.sap.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `softwareag.adabas` | [Adabas (Adaptable Database System)](https://documentation.softwareag.com/?pf=adabas) | ![Development](https://img.shields.io/badge/-development-blue) |
| `sqlite` | [SQLite](https://www.sqlite.org/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `surrealdb` | [SurrealDB](https://surrealdb.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `teradata` | [Teradata](https://www.teradata.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `trino` | [Trino](https://trino.io/) | ![Development](https://img.shields.io/badge/-development-blue) |

Expand Down
1 change: 1 addition & 0 deletions docs/database/database-spans.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ and SHOULD be provided **at span creation time** (if provided at all):
| `sap.maxdb` | [SAP MaxDB](https://maxdb.sap.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `softwareag.adabas` | [Adabas (Adaptable Database System)](https://documentation.softwareag.com/?pf=adabas) | ![Development](https://img.shields.io/badge/-development-blue) |
| `sqlite` | [SQLite](https://www.sqlite.org/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `surrealdb` | [SurrealDB](https://surrealdb.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `teradata` | [Teradata](https://www.teradata.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `trino` | [Trino](https://trino.io/) | ![Development](https://img.shields.io/badge/-development-blue) |

Expand Down
115 changes: 115 additions & 0 deletions docs/database/surrealdb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!--- Hugo front matter used to generate the website version of this page:
linkTitle: SurrealDB
--->

# Semantic conventions for SurrealDB client operations

**Status**: [Development][DocumentStatus]

The Semantic Conventions for SurrealDB extend and override the Database Semantic Conventions.

## Spans

<!-- semconv span.db.surrealdb.client -->
<!-- NOTE: THIS TEXT IS AUTOGENERATED. DO NOT EDIT BY HAND. -->
<!-- see templates/registry/markdown/snippet.md.j2 -->
<!-- prettier-ignore-start -->
<!-- markdownlint-capture -->
<!-- markdownlint-disable -->

**Status:** ![Development](https://img.shields.io/badge/-development-blue)

Spans representing calls to a SurrealDB database adhere to the general [Semantic Conventions for Database Client Spans](database-spans.md).

`db.system.name` MUST be set to `"surrealdb"` and SHOULD be provided **at span creation time**.

**Span kind** SHOULD be `CLIENT`.

**Span status** SHOULD follow the [Recording Errors](/docs/general/recording-errors.md) document.

| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
|---|---|---|---|---|---|
| [`db.namespace`](/docs/registry/attributes/db.md) | string | The database associated with the connection, fully qualified within the server address and port. [1] | `customers`; `webshop\|customers` | `Conditionally Required` If available without an additional network call. | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`db.response.status_code`](/docs/registry/attributes/db.md) | string | Database response code recorded as a string. [2] | `ORA-17027`; `1052`; `2201B` | `Conditionally Required` If response has ended with warning or an error. | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`error.type`](/docs/registry/attributes/error.md) | string | Describes a class of error the operation ended with. [3] | `timeout`; `java.net.UnknownHostException`; `server_certificate_invalid`; `500` | `Conditionally Required` If and only if the operation failed. | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`server.port`](/docs/registry/attributes/server.md) | int | Server port number. [4] | `80`; `8080`; `443` | `Conditionally Required` [5] | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`db.collection.name`](/docs/registry/attributes/db.md) | string | The name of the table within the database. | `public.users`; `customers` | `Recommended` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`db.operation.batch.size`](/docs/registry/attributes/db.md) | int | The number of queries included in a batch operation. [6] | `2`; `3`; `4` | `Recommended` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`db.operation.name`](/docs/registry/attributes/db.md) | string | The name of the operation or command being executed. [7] | `EXECUTE`; `INSERT` | `Recommended` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`db.query.summary`](/docs/registry/attributes/db.md) | string | Low cardinality summary of a database query. [8] | `SELECT wuser_table`; `INSERT shipping_details SELECT orders`; `get user by id` | `Recommended` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`db.query.text`](/docs/registry/attributes/db.md) | string | The database query being executed. [9] | `SELECT * FROM wuser_table where username = ?`; `SET mykey ?` | `Recommended` [10] | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`db.stored_procedure.name`](/docs/registry/attributes/db.md) | string | In SurrealDB this refers to the function being invoked. | `GetCustomer` | `Recommended` [11] | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`network.protocol.name`](/docs/registry/attributes/network.md) | string | [OSI application layer](https://wikipedia.org/wiki/Application_layer) or non-OSI equivalent. [12] | `amqp`; `http`; `mqtt` | `Recommended` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`server.address`](/docs/registry/attributes/server.md) | string | Name of the database host. [13] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | `Recommended` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`db.query.parameter.<key>`](/docs/registry/attributes/db.md) | string | A database query parameter, with `<key>` being the parameter name, and the attribute value being a string representation of the parameter value. [14] | `someval`; `55` | `Opt-In` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`db.response.returned_rows`](/docs/registry/attributes/db.md) | int | Number of rows returned by the operation. | `10`; `30`; `1000` | `Opt-In` | ![Development](https://img.shields.io/badge/-development-blue) |

**[1] `db.namespace`:** SurrealDB has the notion of both namespace & database for each client. As such the structure of this attribute would become `{{Namespace}}|{{Database}}`.

**[2] `db.response.status_code`:** The http response status code is to be used as the database status code.

**[3] `error.type`:** The `error.type` SHOULD match the `db.response.status_code` returned by the database or the client library, or the canonical name of exception that occurred.
When using canonical exception type name, instrumentation SHOULD do the best effort to report the most relevant type. For example, if the original exception is wrapped into a generic one, the original exception SHOULD be preferred.
Instrumentations SHOULD document how `error.type` is populated.

**[4] `server.port`:** When observed from the client side, and when communicating through an intermediary, `server.port` SHOULD represent the server port behind any intermediaries, for example proxies, if it's available.

**[5] `server.port`:** If using a port other than the default port for this DBMS and if `server.address` is set.

**[6] `db.operation.batch.size`:** Operations are only considered batches when they contain two or more operations, and so `db.operation.batch.size` SHOULD never be `1`.

**[7] `db.operation.name`:** The operation name is to reflect the api method being called ie upsert.
Copy link

@Odonno Odonno Aug 5, 2025

Choose a reason for hiding this comment

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

suggestion: I would have expect a list item or table for each operation name, so that every client uses the same name/convention. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have looked at other db provider docs and none of them except for cosmosdb provide table/lists of operation names.


**[8] `db.query.summary`:** The query summary is to be a concatenation of the method and table being acted on.

**[9] `db.query.text`:** For sanitization see [Sanitization of `db.query.text`](/docs/database/database-spans.md#sanitization-of-dbquerytext).
For batch operations, if the individual operations are known to have the same query text then that query text SHOULD be used, otherwise all of the individual query texts SHOULD be concatenated with separator `; ` or some other database system specific separator if more applicable.
Parameterized query text SHOULD NOT be sanitized. Even though parameterized query text can potentially have sensitive data, by using a parameterized query the user is giving a strong signal that any sensitive data will be passed as parameter values, and the benefit to observability of capturing the static part of the query text by default outweighs the risk.

**[10] `db.query.text`:** Non-parameterized query text SHOULD NOT be collected by default unless there is sanitization that excludes sensitive data, e.g. by redacting all literal values present in the query text. See [Sanitization of `db.query.text`](/docs/database/database-spans.md#sanitization-of-dbquerytext).
Parameterized query text SHOULD be collected by default (the query parameter values themselves are opt-in, see [`db.query.parameter.<key>`](/docs/registry/attributes/db.md)).

**[11] `db.stored_procedure.name`:** If operation applies to a specific stored procedure.

**[12] `network.protocol.name`:** The value SHOULD be normalized to lowercase.

**[13] `server.address`:** When observed from the client side, and when communicating through an intermediary, `server.address` SHOULD represent the server address behind any intermediaries, for example proxies, if it's available.

**[14] `db.query.parameter.<key>`:** If a query parameter has no name and instead is referenced only by index,
then `<key>` SHOULD be the 0-based index.

`db.query.parameter.<key>` SHOULD match
up with the parameterized placeholders present in `db.query.text`.

`db.query.parameter.<key>` SHOULD NOT be captured on batch operations.

Examples:

- For a query `SELECT * FROM users where username = %s` with the parameter `"jdoe"`,
the attribute `db.query.parameter.0` SHOULD be set to `"jdoe"`.

- For a query `"SELECT * FROM users WHERE username = %(username)s;` with parameter
`username = "jdoe"`, the attribute `db.query.parameter.username` SHOULD be set to `"jdoe"`.

The following attributes can be important for making sampling decisions
and SHOULD be provided **at span creation time** (if provided at all):

* [`db.query.summary`](/docs/registry/attributes/db.md)
* [`db.query.text`](/docs/registry/attributes/db.md)
* [`server.address`](/docs/registry/attributes/server.md)
* [`server.port`](/docs/registry/attributes/server.md)

---

`error.type` has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

| Value | Description | Stability |
|---|---|---|
| `_OTHER` | A fallback error value to be used when the instrumentation doesn't define a custom value. | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- END AUTOGENERATED TEXT -->
<!-- endsemconv -->

[DocumentStatus]: https://opentelemetry.io/docs/specs/otel/document-status
1 change: 1 addition & 0 deletions docs/registry/attributes/db.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ stored procedure name then that stored procedure name SHOULD be used.
| `sap.maxdb` | [SAP MaxDB](https://maxdb.sap.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `softwareag.adabas` | [Adabas (Adaptable Database System)](https://documentation.softwareag.com/?pf=adabas) | ![Development](https://img.shields.io/badge/-development-blue) |
| `sqlite` | [SQLite](https://www.sqlite.org/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `surrealdb` | [SurrealDB](https://surrealdb.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `teradata` | [Teradata](https://www.teradata.com/) | ![Development](https://img.shields.io/badge/-development-blue) |
| `trino` | [Trino](https://trino.io/) | ![Development](https://img.shields.io/badge/-development-blue) |

Expand Down
4 changes: 4 additions & 0 deletions model/database/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ groups:
value: "trino"
brief: "[Trino](https://trino.io/)"
stability: development
- id: surrealdb
value: "surrealdb"
brief: "[SurrealDB](https://surrealdb.com/)"
stability: development
stability: stable
- id: db.client.connection.state
stability: development
Expand Down
29 changes: 29 additions & 0 deletions model/database/spans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,3 +1016,32 @@ groups:
For batch operations, if the individual operations are known to have the same query text then that query text SHOULD be used,
otherwise all of the individual query texts SHOULD be concatenated with separator `; ` or some other database system specific separator if more applicable.
examples: ["SELECT * FROM wuser_table where username = :mykey"]
- id: span.db.surrealdb.client
type: span
stability: development
extends: span.db.sql.client
span_kind: client
brief: >
Spans representing calls to a SurrealDB database adhere to the general [Semantic Conventions for Database Client Spans](database-spans.md).
note: |
`db.system.name` MUST be set to `"surrealdb"` and SHOULD be provided **at span creation time**.
attributes:
- ref: network.protocol.name
- ref: db.stored_procedure.name
brief: In SurrealDB this refers to the function being invoked.
note: ''
- ref: db.namespace
note: SurrealDB has the notion of both namespace & database for each client. As such the structure of this attribute would become `{{Namespace}}|{{Database}}`.
examples: ['customers', 'webshop\|customers']
- ref: db.operation.name
note: The operation name is to reflect the api method being called ie upsert.
requirement_level: recommended
- ref: db.response.status_code
note: The http response status code is to be used as the database status code.
- ref: db.query.summary
note: The query summary is to be a concatenation of the method and table being acted on.
requirement_level: recommended
- ref: db.collection.name
brief: The name of the table within the database.
note: ''
requirement_level: recommended
Loading