> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 時間範囲ブループリント

> コンピュート、サーバーレス関数、コンテナ、およびランタイム請求に基づいて経過時間に基づくリソース消費を追跡します。

## ユースケース

時間範囲ブループリントでサポートされている一般的なシナリオを探ります：

<CardGroup cols={2}>
  <Card title="Serverless Functions" icon="function">
    関数の実行時間とメモリ使用量に基づいて請求します。
  </Card>

  <Card title="Container Runtime" icon="container-storage">
    使用ベースの請求のためにコンテナの稼働時間を追跡します。
  </Card>

  <Card title="Compute Instances" icon="server">
    VM のランタイムを監視し、分単位または時間単位で課金します。
  </Card>

  <Card title="Background Jobs" icon="briefcase">
    データのエクスポート、レポート、バッチジョブの処理時間を追跡します。
  </Card>
</CardGroup>

<Info>
  コンピューティング時間、関数の実行時間、コンテナの稼働時間、またはその他の時間ベースの使用状況に応じた請求に最適です。
</Info>

## クイックスタート

時間の経過に基づいてリソース使用量を追跡します：

<Steps>
  <Step title="Install the SDK">
    ```bash theme={null}
    npm install @dodopayments/ingestion-blueprints
    ```
  </Step>

  <Step title="Get Your API Keys">
    * **Dodo Payments API Key**: Get it from [Dodo Payments Dashboard](https://app.dodopayments.com/developer/api-keys)
  </Step>

  <Step title="Create a Meter">
    Create a meter in your [Dodo Payments Dashboard](https://app.dodopayments.com/):

    * **Event Name**: `time_range_usage` (or your preferred name)
    * **Aggregation Type**: `sum` to track total duration
    * **Over Property**: `durationSeconds`, `durationMinutes`, or `durationMs`
  </Step>

  <Step title="Track Time Usage">
    <CodeGroup>
      ```javascript Serverless Functions theme={null}
      import { Ingestion, trackTimeRange } from '@dodopayments/ingestion-blueprints';

      const ingestion = new Ingestion({
        apiKey: process.env.DODO_PAYMENTS_API_KEY,
        environment: 'test_mode',
        eventName: 'function_execution'
      });

      // Track function execution time
      const startTime = Date.now();

      // Execute your function (example: image processing)
      const result = await yourImageProcessingLogic();

      const durationMs = Date.now() - startTime;

      await trackTimeRange(ingestion, {
        customerId: 'customer_123',
        durationMs: durationMs
      });
      ```

      ```javascript Container Runtime theme={null}
      import { Ingestion, trackTimeRange } from '@dodopayments/ingestion-blueprints';

      const ingestion = new Ingestion({
        apiKey: process.env.DODO_PAYMENTS_API_KEY,
        environment: 'test_mode',
        eventName: 'container_runtime'
      });

      // Track container runtime in seconds
      await trackTimeRange(ingestion, {
        customerId: 'customer_456',
        durationSeconds: 120
      });
      ```

      ```javascript VM Instance Runtime theme={null}
      import { Ingestion, trackTimeRange } from '@dodopayments/ingestion-blueprints';

      const ingestion = new Ingestion({
        apiKey: process.env.DODO_PAYMENTS_API_KEY,
        environment: 'test_mode',
        eventName: 'vm_runtime'
      });

      // Track VM runtime in minutes
      await trackTimeRange(ingestion, {
        customerId: 'customer_789',
        durationMinutes: 60
      });
      ```
    </CodeGroup>
  </Step>
</Steps>

## 設定

### 取り込み設定

<ParamField path="apiKey" type="string" required>
  ダッシュボードから取得した Dodo Payments API キー。
</ParamField>

<ParamField path="environment" type="string" required>
  環境モード: `test_mode` または `live_mode`。
</ParamField>

<ParamField path="eventName" type="string" required>
  メーター構成に一致するイベント名。
</ParamField>

### 時間範囲オプションの追跡

<ParamField path="customerId" type="string" required>
  課金帰属のためのカスタマー ID。
</ParamField>

<ParamField path="durationMs" type="number">
  ミリ秒単位の期間。サブ秒精度に使用します。
</ParamField>

<ParamField path="durationSeconds" type="number">
  秒単位の期間。関数の実行や短いタスクで最も一般的に使用されます。
</ParamField>

<ParamField path="durationMinutes" type="number">
  分単位の期間。VM などの長時間稼働するリソースに便利です。
</ParamField>

<ParamField path="metadata" type="object">
  CPU、メモリ、リージョンなどのリソースに関する任意のメタデータ。
</ParamField>

## ベストプラクティス

<Tip>
  **適切な単位を選択**: 短時間の処理にはミリ秒、関数には秒、長時間稼働するリソースには分を使用してください。
</Tip>

<Warning>
  **正確なタイミング**: 特にサーバーレス関数では、正確な時間追跡のために `Date.now()` または `performance.now()` を使用してください。
</Warning>
