> Source: https://www.ymotongpoo.com/works/otel-specs-ja/semconv/db/database-exceptions/


# データベース例外に関するセマンティック規約

**ステータス**: [Development][DocumentStatus]

この文書では、データベースクライアント操作で発生した例外を記録するためのセマンティック規約を定義します。

## データベースクライアント操作の例外

<!-- semconv event.db.client.operation.exception -->
<!-- NOTE: THIS TEXT IS AUTOGENERATED. DO NOT EDIT BY HAND. -->
<!-- see templates/registry/markdown/snippet.md.j2 -->
<!-- prettier-ignore-start -->

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

イベント名は `db.client.operation.exception` でなければなりません（MUST）。

このイベントは、データベースクライアント操作中に発生した例外（接続の失敗、クエリエラー、タイムアウトなど、操作の正常な完了を妨げるその他のエラー）を表します。

このイベントは、データベースクライアント操作中に例外が発生した場合に記録すべきです（SHOULD）。
計装は、このイベントを記録する際に重要度をWARN（重要度番号13）に設定すべきです（SHOULD）。
計装は、対応するデータベースクライアントスパンに取得された属性を例外イベントに設定するための設定オプションを提供してもかまいません（MAY）。

**Attributes:**

| Key | Stability | [Requirement Level](/works/otel-specs-ja/semconv/general/attribute-requirement-level/) | Value Type | Description | Example Values |
| --- | --- | --- | --- | --- | --- |
| [`exception.message`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/exception/) | ![Stable](https://img.shields.io/badge/-stable-lightgreen) | `Conditionally Required` [1] | string | 例外メッセージ。 [2] | `Division by zero`; `Can't convert 'int' object to str implicitly` |
| [`exception.type`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/exception/) | ![Stable](https://img.shields.io/badge/-stable-lightgreen) | `Conditionally Required` [3] | string | 例外の型（該当する場合は完全修飾クラス名）。この型をサポートする言語では、例外の静的な型よりも動的な型を優先すべきです。 [4] | `java.net.ConnectException`; `OSError` |
| [`exception.stacktrace`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/exception/) | ![Stable](https://img.shields.io/badge/-stable-lightgreen) | `Recommended` | string | 言語ランタイムにおける自然な表現形式で表した、文字列としてのスタックトレース。表現形式は各言語SIGが決定し、文書化するものとします。 | `Exception in thread "main" java.lang.RuntimeException: Test exception\n at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\n at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\n at com.example.GenerateTrace.main(GenerateTrace.java:5)` |

**[1] `exception.message`:** `exception.type` が設定されていない場合は必須（Required）であり、それ以外の場合は推奨（Recommended）です。

**[2] `exception.message`:**

> [!WARNING]
>
> この属性には機密情報が含まれる可能性があります。

**[3] `exception.type`:** `exception.message` が設定されていない場合は必須（Required）であり、それ以外の場合は推奨（Recommended）です。

**[4] `exception.type`:** 記録された例外の型が、失敗の分類にとって意味を持たないラッパーである場合、計装は代わりに内部の例外の型を使用してもかまいません（MAY）。たとえばGoでは、`%w` を使って `fmt.Errorf` で作成されたエラーは、ラッパー型が失敗の分類の助けにならない場合、アンラップしてもかまいません（MAY）。

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

[DocumentStatus]: https://opentelemetry.io/docs/specs/otel/document-status

