> Source: https://www.ymotongpoo.com/works/otel-specs-ja/semconv/dotnet/dotnet-http-metrics/


# .NETが発行するHTTPクライアント・サーバーメトリクスに関するセマンティック規約

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

この記事では、.NETのコンポーネントとランタイムが発行するHTTPメトリクスに関するセマンティック規約を定義します。

## HTTPクライアント

すべてのHTTPクライアントメトリクスは、`System.Net.Http` Meterによって報告されます。

### メトリクス: `http.client.request.duration`

クライアントのリクエスト時間は、レスポンスヘッダーを受信するまでの時間を計測し、レスポンスボディの読み取り時間は含みません。

このメトリクスは、共通の[http.client.request.duration](/works/otel-specs-ja/semconv/http/http-metrics/#メトリクス-httpclientrequestduration)の定義に従います。

注記:

- Meterの名前は`System.Net.Http`です。
- .NET 8.0で追加されたメトリクスです。
- `error.type`属性が報告される場合、それには[HTTP Request errors](https://learn.microsoft.com/dotnet/api/system.net.http.httprequesterror)のいずれかをsnake_caseにしたもの、完全な例外型、または受信したステータスコードの文字列表現が含まれます。
- `network.protocol.name`は報告されず、常に`http`に一致すると仮定すべきです（should）。
- `server.port`は、提供されたスキームのデフォルトポート（`https`の場合は`443`、`http`の場合は`80`）と一致する場合は報告されません。
- `url.scheme`は常に報告されます。

### メトリクス: `http.client.open_connections`

<!-- Tables in this document are not auto-generated and are intentionally frozen in time. From the .NET perspective this metric and its attributes are stable till the next major version. They are still experimental in the OpenTelemetry. -->
| Name | Instrument Type | Unit (UCUM) | Description |
| ---- | --------------- | ----------- | ----------- |
| `http.client.open_connections` | UpDownCounter | `{connection}` | クライアント上で現在アクティブまたはアイドル状態の、送信方向のHTTP接続数。[1] |

**[1]:** Meterの名前: `System.Net.Http`; 追加されたバージョン: .NET 8.0

| Attribute | Type | Description | Examples | Requirement Level |
| --------- | --- | --- | --- | --- |
| [`http.connection.state`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/http/) | string | HTTP接続プール内のHTTP接続の状態。 | `active`; `idle` | Required |
| [`network.peer.address`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/network/) | string | ソケット接続のリモートIPアドレス。 | `10.1.2.80` | Recommended |
| [`network.protocol.version`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/network/) | string | 接続プール内の接続に関連する、ネゴシエーション済みのプロトコルバージョン。[1] | `1.1`; `2`; `3` | Recommended |
| [`server.address`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/server/) | string | HTTPリクエストの送信先である[「URIオリジン」](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin)のホスト識別子。[2] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Required |
| [`server.port`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/server/) | int | HTTPリクエストの送信先である[「URIオリジン」](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin)のポート識別子。[3] | `80`; `8080`; `443` | Conditionally Required: [4] |
| [`url.scheme`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/url/) | string | 使用されているプロトコルを識別する[URIスキーム](https://www.rfc-editor.org/rfc/rfc3986#section-3.1)の構成要素。 | `http`; `https`; `ftp` | Recommended |

**[1]:** HTTP 1.0と1.1のリクエストは、接続プール内で接続を共有し、いずれもバージョン`1.1`として報告されます。したがって、接続メトリクスで報告される`network.protocol.version`の値は、HTTP 1.0リクエストのリクエストレベルのメトリクスやスパンで報告される値とは異なります。

**[2]:** HTTPクライアントリクエストが、たとえば`http://x.x.x.x:8080`のようにIPアドレスに対して明示的に行われる場合、`server.address`はそのIPアドレス`x.x.x.x`であるべきです（SHOULD）。DNSルックアップは使用すべきではありません（SHOULD NOT）。

**[3]:** クライアント側から観測し、かつ中間サーバーを介して通信している場合、`server.port`は、（利用可能であれば）プロキシなどの中間サーバーの背後にあるサーバーのポートを表すべきです（SHOULD）。

**[4]:** デフォルト値（`http`スキームの場合は`80`、`https`の場合は`443`）でない場合。

`http.connection.state`は、次のいずれかでなければなりません。

| Value | Description |
| --- | --- |
| `active` | active状態。 |
| `idle` | idle状態。 |

### メトリクス: `http.client.connection.duration`

このメトリクスは、`[ 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60, 120, 300 ]` の[`ExplicitBucketBoundaries` advisoryパラメータ](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.59.0/specification/metrics/api.md#instrument-advisory-parameters)を指定すべきです（SHOULD）。

<!-- Tables in this document are not auto-generated and are intentionally frozen in time. From the .NET perspective this metric and its attributes are stable till the next major version. They are still experimental in the OpenTelemetry. -->
| Name | Instrument Type | Unit (UCUM) | Description |
| -------- | --------------- | ----------- | -------------- |
| `http.client.connection.duration` | Histogram | `s` | 正常に確立された送信方向のHTTP接続の持続時間。[1] |

**[1]:** Meterの名前: `System.Net.Http`; 追加されたバージョン: .NET 8.0

| Attribute | Type | Description | Examples | Requirement Level |
| --- | --- | --- | --- | --- |
| [`network.peer.address`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/network/) | string | ネットワーク接続のピアアドレス（IPアドレスまたはUNIXドメインソケット名）。 | `10.1.2.80`; `/tmp/my.sock` | Recommended |
| [`network.protocol.version`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/network/) | string | 接続プール内の接続に関連する、ネゴシエーション済みのプロトコルバージョン。[1] | `1.1`; `2`; `3` | Recommended |
| [`server.address`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/server/) | string | HTTPリクエストの送信先である[「URIオリジン」](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin)のホスト識別子。[2] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Required |
| [`server.port`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/server/) | int | HTTPリクエストの送信先である[「URIオリジン」](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin)のポート識別子。[3] | `80`; `8080`; `443` | Conditionally Required: [4] |
| [`url.scheme`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/url/) | string | 使用されているプロトコルを識別する[URIスキーム](https://www.rfc-editor.org/rfc/rfc3986#section-3.1)の構成要素。 | `http`; `https`; `ftp` | Recommended |

**[1]:** HTTP 1.0と1.1のリクエストは、接続プール内で接続を共有し、いずれもバージョン`1.1`として報告されます。したがって、接続メトリクスで報告される`network.protocol.version`の値は、HTTP 1.0リクエストのリクエストレベルのメトリクスやスパンで報告される値とは異なります。

**[2]:** HTTPクライアントリクエストが、たとえば`http://x.x.x.x:8080`のようにIPアドレスに対して明示的に行われる場合、`server.address`はそのIPアドレス`x.x.x.x`であるべきです（SHOULD）。DNSルックアップは使用すべきではありません（SHOULD NOT）。

**[3]:** クライアント側から観測し、かつ中間サーバーを介して通信している場合、`server.port`は、（利用可能であれば）プロキシなどの中間サーバーの背後にあるサーバーのポートを表すべきです（SHOULD）。

**[4]:** デフォルト値（`http`スキームの場合は`80`、`https`の場合は`443`）でない場合。

### メトリクス: `http.client.request.time_in_queue`

このメトリクスは、`[ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10 ]` の[`ExplicitBucketBoundaries` advisoryパラメータ](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.59.0/specification/metrics/api.md#instrument-advisory-parameters)を指定すべきです（SHOULD）。

<!-- Tables in this document are not auto-generated and are intentionally frozen in time. From the .NET perspective this metric and its attributes are stable till the next major version. They are still experimental in the OpenTelemetry. -->
| Name | Instrument Type | Unit (UCUM) | Description |
| ---- | --------------- | ----------- | ----------- |
| `http.client.request.time_in_queue` | Histogram | `s` | リクエストが、利用可能な接続を待ってキューに滞在した時間。[1] |

**[1]:** Meterの名前: `System.Net.Http`; 追加されたバージョン: .NET 8.0

| Attribute | Type | Description | Examples | Requirement Level |
| --- | --- | --- | --- | --- |
| [`http.request.method`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/http/) | string | HTTPリクエストのメソッド。[1] | `GET`; `POST`; `HEAD` | Recommended |
| [`network.protocol.version`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/network/) | string | 接続プール内の接続に関連する、ネゴシエーション済みのプロトコルバージョン。[2] | `1.1`; `2`; `3` | Recommended |
| [`server.address`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/server/) | string | HTTPリクエストの送信先である[「URIオリジン」](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin)のホスト識別子。[3] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Required |
| [`server.port`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/server/) | int | HTTPリクエストの送信先である[「URIオリジン」](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin)のポート識別子。[4] | `80`; `8080`; `443` | Conditionally Required: [5] |
| [`url.scheme`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/url/) | string | 使用されているプロトコルを識別する[URIスキーム](https://www.rfc-editor.org/rfc/rfc3986#section-3.1)の構成要素。 | `http`; `https`; `ftp` | Recommended |

**[1]:** HTTPリクエストメソッドの値は、[RFC9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-methods)に列挙されている「既知の」メソッドと、[RFC5789](https://www.rfc-editor.org/rfc/rfc5789.html)で定義されているPATCHメソッドのいずれかです。
HTTPリクエストメソッドが不明な場合、`http.request.method`属性は`_OTHER`に設定されます。現時点では、既知のHTTPメソッドの一覧を上書きすることはできません。

**[2]:** HTTP 1.0と1.1のリクエストは、接続プール内で接続を共有し、いずれもバージョン`1.1`として報告されます。したがって、接続メトリクスで報告される`network.protocol.version`の値は、HTTP 1.0リクエストのリクエストレベルのメトリクスやスパンで報告される値とは異なります。

**[3]:** HTTPクライアントリクエストが、たとえば`http://x.x.x.x:8080`のようにIPアドレスに対して明示的に行われる場合、`server.address`はそのIPアドレス`x.x.x.x`であるべきです（SHOULD）。DNSルックアップは使用すべきではありません（SHOULD NOT）。

**[4]:** クライアント側から観測し、かつ中間サーバーを介して通信している場合、`server.port`は、（利用可能であれば）プロキシなどの中間サーバーの背後にあるサーバーのポートを表すべきです（SHOULD）。

**[5]:** デフォルト値（`http`スキームの場合は`80`、`https`の場合は`443`）でない場合。

`http.request.method`には、次のよく知られた値の一覧があります。これらのいずれかが該当する場合は、対応する値を使用しなければならず、そうでない場合は、独自の値を使用してもかまいません。

| Value | Description |
| --- | --- |
| `CONNECT` | CONNECTメソッド。 |
| `DELETE` | DELETEメソッド。 |
| `GET` | GETメソッド。 |
| `HEAD` | HEADメソッド。 |
| `OPTIONS` | OPTIONSメソッド。 |
| `PATCH` | PATCHメソッド。 |
| `POST` | POSTメソッド。 |
| `PUT` | PUTメソッド。 |
| `TRACE` | TRACEメソッド。 |
| `_OTHER` | 計装が事前に知らないHTTPメソッド。 |

### メトリクス: `http.client.active_requests`

<!-- Tables in this document are not auto-generated and are intentionally frozen in time. From the .NET perspective this metric and its attributes are stable till the next major version. They are still experimental in the OpenTelemetry. -->
| Name | Instrument Type | Unit (UCUM) | Description |
| -------- | --------------- | ----------- | -------------- |
| `http.client.active_requests` | UpDownCounter | `{request}` | アクティブなHTTPリクエスト数。[1] |

**[1]:** Meterの名前: `System.Net.Http`; 追加されたバージョン: .NET 8.0

| Attribute | Type | Description | Examples | Requirement Level |
| --- | --- | --- | --- | --- |
| [`http.request.method`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/http/) | string | HTTPリクエストのメソッド。[1] | `GET`; `POST`; `HEAD` | Recommended |
| [`server.address`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/server/) | string | HTTPリクエストの送信先である[「URIオリジン」](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin)のホスト識別子。[2] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Required |
| [`server.port`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/server/) | int | HTTPリクエストの送信先である[「URIオリジン」](https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin)のポート識別子。[3] | `80`; `8080`; `443` | Conditionally Required: [4] |
| [`url.scheme`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/url/) | string | 使用されているプロトコルを識別する[URIスキーム](https://www.rfc-editor.org/rfc/rfc3986#section-3.1)の構成要素。 | `http`; `https`; `ftp` | Recommended |

**[1]:** HTTPリクエストメソッドの値は、[RFC9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-methods)に列挙されている「既知の」メソッドと、[RFC5789](https://www.rfc-editor.org/rfc/rfc5789.html)で定義されているPATCHメソッドのいずれかです。
HTTPリクエストメソッドが不明な場合、`http.request.method`属性は`_OTHER`に設定されます。現時点では、既知のHTTPメソッドの一覧を上書きすることはできません。

**[2]:** HTTPクライアントリクエストが、たとえば`http://x.x.x.x:8080`のようにIPアドレスに対して明示的に行われる場合、`server.address`はそのIPアドレス`x.x.x.x`であるべきです（SHOULD）。DNSルックアップは使用すべきではありません（SHOULD NOT）。

**[3]:** クライアント側から観測し、かつ中間サーバーを介して通信している場合、`server.port`は、（利用可能であれば）プロキシなどの中間サーバーの背後にあるサーバーのポートを表すべきです（SHOULD）。

**[4]:** デフォルト値（`http`スキームの場合は`80`、`https`の場合は`443`）でない場合。

`http.request.method`には、次のよく知られた値の一覧があります。これらのいずれかが該当する場合は、対応する値を使用しなければならず、そうでない場合は、独自の値を使用してもかまいません。

| Value | Description |
| --- | --- |
| `CONNECT` | CONNECTメソッド。 |
| `DELETE` | DELETEメソッド。 |
| `GET` | GETメソッド。 |
| `HEAD` | HEADメソッド。 |
| `OPTIONS` | OPTIONSメソッド。 |
| `PATCH` | PATCHメソッド。 |
| `POST` | POSTメソッド。 |
| `PUT` | PUTメソッド。 |
| `TRACE` | TRACEメソッド。 |
| `_OTHER` | 計装が事前に知らないHTTPメソッド。 |

## HTTPサーバー

すべてのHTTPサーバーメトリクスは、`Microsoft.AspNetCore.Hosting` Meterによって報告されます。

### メトリクス: `http.server.request.duration`

最後のバイトまでの時間を計測します。このメトリクスは、共通の[http.server.request.duration](/works/otel-specs-ja/semconv/http/http-metrics/#メトリクス-httpserverrequestduration)の定義に従います。

注記:

- Meterの名前は`Microsoft.AspNetCore.Hosting`です。
- ASP.NET Core 8.0で追加されたメトリクスです。
- opt-inの`server.address`属性と`server.port`属性は報告されません。
- 追加の属性:

  - `aspnetcore.request.is_unhandled`ブール値属性は、リクエストがアプリケーションのパイプラインによって処理され**なかった**場合に報告されます。それ以外の場合は省略されます。

### メトリクス: `http.server.active_requests`

サーバー上で現在アクティブなHTTPリクエスト数を計測します。このメトリクスは、共通の[http.server.active_requests](/works/otel-specs-ja/semconv/http/http-metrics/#メトリクス-httpserveractive_requests)の定義に従います。

注記:

- Meterの名前は`Microsoft.AspNetCore.Hosting`です。
- opt-inの`server.address`属性と`server.port`属性は報告されません。
- ASP.NET Core 8.0で追加されたメトリクスです。

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

