> Source: https://www.ymotongpoo.com/works/otel-specs-ja/semconv/resource/faas/


# Function as a Service

参考:

- [FaaSのトレースセマンティック規約](/works/otel-specs-ja/semconv/faas/faas-spans/)
- [Cloudリソースの規約](/works/otel-specs-ja/semconv/resource/cloud/)

## FaaSのリソース属性

<!-- semconv entity.faas -->
<!-- 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)

**type:** `faas`

**Description:** サーバーレスインスタンス。

> [!warning]
> このEntity定義には、roleを持たない属性が含まれています。
> 安定版のEntityは、roleが定義されていない属性を持ってはなりません（MUST NOT）。

**Attributes:**

| Role | Key | Stability | [Requirement Level](/works/otel-specs-ja/semconv/general/attribute-requirement-level/) | Value Type | Description | Example Values |
| --- | --- | --- | --- | --- | --- | --- |
| Other | [`faas.name`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/faas/) | ![Development](https://img.shields.io/badge/-development-blue) | `Required` | string | このランタイムインスタンスが実行する単一の関数の名前。[1] | `my-function`; `myazurefunctionapp/some-function-name` |
| Other | [`cloud.resource_id`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/cloud/) | ![Development](https://img.shields.io/badge/-development-blue) | `Recommended` | string | 監視対象のクラウドリソースに対する、クラウドプロバイダー固有のネイティブ識別子（AWSの[ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)、Azureの[完全修飾リソースID](https://learn.microsoft.com/rest/api/resources/resources/get-by-id)、GCPの[完全なリソース名](https://google.aip.dev/122#full-resource-names)など）。[2] | `arn:aws:lambda:REGION:ACCOUNT_ID:function:my-function`; `//run.googleapis.com/projects/PROJECT_ID/locations/LOCATION_ID/services/SERVICE_ID`; `/subscriptions/<SUBSCRIPTION_GUID>/resourceGroups/<RG>/providers/Microsoft.Web/sites/<FUNCAPP>/functions/<FUNC>` |
| Other | [`faas.instance`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/faas/) | ![Development](https://img.shields.io/badge/-development-blue) | `Recommended` | string | 文字列としての実行環境ID。同じ関数・関数バージョンへの他の呼び出しで再利用される可能性があります。[3] | `2021/06/28/[$LATEST]2f399eb14537447da05ab2a2e39309de` |
| Other | [`faas.max_memory`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/faas/) | ![Development](https://img.shields.io/badge/-development-blue) | `Recommended` | int | サーバーレス関数が利用できるメモリ量をバイトに変換した値。[4] | `134217728` |
| Other | [`faas.version`](https://opentelemetry.io/docs/specs/semconv/registry/attributes/faas/) | ![Development](https://img.shields.io/badge/-development-blue) | `Recommended` | string | 実行されている関数の不変のバージョン。[5] | `26`; `pinkfroid-00002` |

**[1] `faas.name`:** これは、FaaSプラットフォーム上で設定・デプロイされた関数の名前であり、通常はコールバック関数の名前（[`code.namespace`/`code.function.name`](/works/otel-specs-ja/semconv/general/attributes/#ソースコード属性)スパン属性に格納されている場合があります）とは異なります。

一部のクラウドプロバイダーでは、上記の定義は曖昧です。次に挙げるクラウドプロバイダー・製品については、この属性（およびその結果としてスパン名）に、次の関数名の定義を使用しなければなりません（MUST）。

- **Azure:** 完全な名前`<FUNCAPP>/<FUNC>`、つまりfunction app名の後にスラッシュと関数名を続けたもの（この形式は、その関数のリソースJSONでも見られます）。
  これは、Azureのfunction appが通常TracerProviderを共有する複数の関数をホストできるため、スパン属性を使用しなければならないことを意味します（MUST。`cloud.resource_id`属性も参照してください）。

**[2] `cloud.resource_id`:** 一部のクラウドプロバイダーでは、起動時に完全なIDを決定できない場合があるため、代わりに`cloud.resource_id`をスパン属性として設定する必要があるかもしれません。

`cloud.resource_id`に使用する正確な値は、クラウドプロバイダーによって異なります。
この属性を設定する場合、当てはまるのであれば次のよく知られた定義を使用しなければなりません（MUST）。

- **AWS Lambda:** 関数の[ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)。
  同じランタイムインスタンスが複数の異なるエイリアスから呼び出し可能である場合があるため、「呼び出されたARN」を直接使用せず、[エイリアスのサフィックス](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html)を、解決済みの関数バージョンに置き換えるように注意してください。
- **GCP:** [リソースのURI](https://cloud.google.com/iam/docs/full-resource-names)
- **Azure:** 呼び出された関数（function app *ではなく*）の[完全修飾リソースID](https://learn.microsoft.com/rest/api/resources/resources/get-by-id)で、次の形式を持ちます。
  `/subscriptions/<SUBSCRIPTION_GUID>/resourceGroups/<RG>/providers/Microsoft.Web/sites/<FUNCAPP>/functions/<FUNC>`。
  これは、Azureのfunction appが通常TracerProviderを共有する複数の関数をホストできるため、スパン属性を使用しなければならないことを意味します（MUST）。

**[3] `faas.instance`:** - **AWS Lambda:** （完全な）ログストリーム名を使用します。

**[4] `faas.max_memory`:** この属性は設定することが推奨されます。例えば、メモリが少なすぎると、Java版のAWS Lambda関数が正しく動作しなくなることがあります。AWS Lambdaでは、環境変数`AWS_LAMBDA_FUNCTION_MEMORY_SIZE`がこの情報を提供します（1,048,576を掛ける必要があります）。

**[5] `faas.version`:** クラウドプロバイダーとプラットフォームに応じて、次を使用してください。

- **AWS Lambda:** [関数バージョン](https://docs.aws.amazon.com/lambda/latest/dg/configuration-versions.html)（10進数の文字列として表される整数）。
- **Google Cloud Run（Services）:** [リビジョン](https://cloud.google.com/run/docs/managing/revisions)（関数名にリビジョンのサフィックスを付けたもの）。
- **Google Cloud Functions:** [`K_REVISION`環境変数](https://cloud.google.com/run/docs/container-contract#services-env-vars)の値。
- **Azure Functions:** 該当しません。この属性は設定しないでください。
<!-- prettier-ignore-end -->
<!-- END AUTOGENERATED TEXT -->
<!-- endsemconv -->

注: リソース属性`faas.instance`は、スパン属性`faas.invocation_id`とは異なります。詳細は[FaaSスパンのセマンティック規約](/works/otel-specs-ja/semconv/faas/faas-spans/#呼び出しinvocationとインスタンスinstanceの違い)を参照してください。

## リソース属性の代わりにスパン属性を使う

FaaSのリソース属性を、代わりにスパン属性として適用したほうがよい場合があります。
詳細は[FaaSのトレース規約](/works/otel-specs-ja/semconv/faas/faas-spans/)を参照してください。

