このページでは、Service Control API v2 を使用して、Service Infrastructure に統合されたマネージド サービスのテレメトリー レポートを作成する方法について説明します。このチュートリアルは、サービスを Google Cloud に深く統合したいと考えているサービス プロデューサーを対象としています。
Service Infrastructure は、デベロッパーが API とサービスを作成、管理、保護、使用するための基盤となるプラットフォームです。シンプルで一般的なサービス使用モデルを使用し、ユーザーはプロデューサーが管理するサービスを消費します。すべての Google API とGoogle Cloud APIは Service Infrastructure の上に構築されているため、このモデルを使用します。
Service Control API v2 は、Service Infrastructure と統合されたすべてのサービスにテレメトリー レポートを提供するシンプルな services.report メソッドを提供します。このメソッドを使用すると、1 回のメソッド呼び出しで次のことを行うことができます。
分析
監査
課金
ロギング
モニタリング
サービスがテレメトリー データを Service Control API にレポートすると、データはサービスの構成に応じて、消費者、プロデューサーのいずれか、または両方に配信されます。テレメトリーの設定の詳細については、google.api.Service のロギングとモニタリングのセクションをご覧ください。
サービスから Service Control API を呼び出すには、プロデューサーはプロデューサー プロジェクトで Service Control API を有効にして、呼び出し元はサービスに対して適切な権限を持っている必要があります。詳細については、Cloud APIs のスタートガイドと Service Control API のアクセス制御をご覧ください。
リクエストの属性
クライアントがサービスにアクセスするとき、サービスは一連の API リクエストに基づいてアクセスをモデル化し、AttributeContext を使用して各リクエストを記述する必要があります。
Service Control API を使用して API 指標をレポートするには、サービスは次の属性を持つ各リクエストに対して services.report メソッドを呼び出す必要があります。Service Control API は API 指標を生成し、それを Cloud Monitoring に送信します。
属性
説明
例
origin.ip
発信者の IP アドレス。
"1.2.3.4"
api.service
API サービスの名前
"endpointsapis.appspot.com"
api.operation
API メソッドの名前
"google.example.hello.v1.HelloService.GetHello"
api.version
API バージョンの文字列
"v1"
api.protocol
API プロトコルの名前
"https"
request.id
一意のリクエスト ID
"123e4567-e89b-12d3-a456-426655440000"
request.time
リクエストのタイムスタンプ
"2019-07-31T05:20:00Z"
request.method
HTTP メソッドの名前
"POST"
request.scheme
URL スキーム
"https"
request.host
HTTP ホストヘッダー
"endpointsapis.appspot.com"
request.path
URL パス
"/v1/hello"
response.code
レスポンスのステータス コード
200
response.size
レスポンスのサイズ(バイト)
100
response.time
レスポンスのタイムスタンプ
"2019-07-31T05:20:02Z"
response.backend_latency
バックエンドのレイテンシ
"0.007s"
テレメトリー レポートの実行
サービス構成を Service Management API にデプロイし、サービスがクライアントからのリクエストを処理する準備ができたら、デプロイされたサービスの services.report の呼び出しを開始できます。サービスがリクエストを受信した後、services.report を呼び出してテレメトリー レポートを実行する必要があります。
テレメトリー レポートをすばやくテストするには、gcurl コマンドを使用して services.report メソッドを呼び出します。初期設定手順については、Service Control API スタートガイドをご覧ください。
本番環境サービスの場合、Google が提供するクライアントライブラリのいずれかを使用して Service Control API を呼び出す必要があります。このようなライブラリは、優れたユーザビリティを提供し、認証などの一般的な機能を自動的に処理します。詳しくはクライアント ライブラリの説明をご覧ください。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-09 UTC。"],[],[],null,["# Telemetry Reporting\n\n| **Alpha**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nIntroduction\n------------\n\nThis page describes how to use the Service Control API v2 for telemetry\nreporting for [managed services](/service-infrastructure/docs/glossary#managed) that are integrated\nwith Service Infrastructure. It is intended for service producers who want to\ndeeply integrate their services with Google Cloud.\n\nService Infrastructure is a foundational platform for developers to produce, manage,\nsecure and\nconsume APIs and services. It uses a simple, generic service usage model:\na consumer consumes a service managed by a producer. All Google APIs and\n[Google Cloud APIs](/apis) use this model, since they are also\nbuilt on top of Service Infrastructure.\n\nWhen a consumer accesses a service, the service reports relevant telemetry\ndata to the platform, so both the consumer and the producer can observe\nthe access. With Service Infrastructure, this process is called telemetry reporting,\nwhich includes analytics, auditing, billing, logging, and monitoring.\n| **Note:** For terminology used in this page, see [API Glossary](/apis/design/glossary).\n\nService Control API v2\n----------------------\n\nThe Service Control API v2 provides a simple\n[`services.report`](/service-infrastructure/docs/service-control/reference/rest/v2/services/report)\nmethod that provides telemetry reporting to all services integrated with\nService Infrastructure. This method lets you do the following in a single method call:\n\n- Analytics\n- Auditing\n- Billing\n- Logging\n- Monitoring\n\nWhen a service reports telemetry data to the Service Control API, the data\nis distributed to the consumer, or the producer, or both, depending on the\nservice configuration. For more information about configuring telemetry, see\nthe logging and monitoring sections of\n[`google.api.Service`](https://github.com/googleapis/googleapis/blob/master/google/api/service.proto).\n\nIn order for a service to call the Service Control API, the producer must\nenable the Service Control API on the producer project, and the caller\nmust have proper permissions on the service. For more information, see\nCloud APIs [Getting Started](/apis/docs/getting-started) and\n[Service Control API Access Control](/service-infrastructure/docs/service-control/access-control).\n\n### Request attributes\n\nWhen a client accesses a service, the service needs to model the access\nin terms of a set of API requests, and describe each request using an\n[`AttributeContext`](https://github.com/googleapis/googleapis/blob/master/google/rpc/context/attribute_context.proto).\n\nTo report [API metrics](https://cloud.google.com/apis/docs/monitoring) using\nthe Service Control API, the service needs to call the\n[`services.report`](/service-infrastructure/docs/service-control/reference/rest/v2/services/report)\nmethod for each request with the following attributes. The Service Control API\nwill generate the API metrics and send them to [Cloud Monitoring](/monitoring).\n\nPerforming telemetry reporting\n------------------------------\n\nOnce you have deployed your service configuration to the Service Management\nAPI and your service is ready to serve requests from clients, you can\nbegin calling `services.report` for your deployed service. You should\ncall `services.report` to perform telemetry reporting after your\nservice receives a request.\n\nTo quickly experiment with the telemetry reporting, you can use the `gcurl`\ncommand to call the `services.report` method. See\n[Getting Started with the Service Control API](/service-infrastructure/docs/service-control/getting-started)\nfor the initial setup steps.\n\nThe following example shows you how to use `gcurl` command to call\n`services.report` over HTTP. \n\n```\ngcurl -d '{\n \"service_config_id\": \"latest\",\n \"operations\": [{\n \"origin\": {\n \"ip\": \"1.2.3.4\"\n },\n \"api\": {\n \"service\": \"endpointsapis.appspot.com\",\n \"operation\", \"google.example.endpointsapis.v1.Workspaces.GetWorkspace\",\n \"version\": \"v1\",\n \"protocol\": \"https\"\n },\n \"request\": {\n \"id\": \"123e4567-e89b-12d3-a456-426655440000\",\n \"size\": 50,\n \"time\": \"2019-07-31T05:20:00Z\",\n },\n \"response\": {\n \"size\": 100,\n \"code\": 200,\n \"time\": \"2019-07-31T05:20:02Z\",\n \"backend_latency\": \"0.007s\"\n },\n \"destination\": {\n \"region_code\": \"us-central1\"\n }\n \"resource\": {\n \"name\": \"projects/123/locations/us-central1/workspaces/default\"\n }\n }]\n}' https://servicecontrol.googleapis.com/v2/services/endpointsapis.appspot.com:report\n```\n\nIf successful, the response from the `services.report` method should be\nempty. If failed, the API error should contain detailed error information.\nFor more information about error handling, see\n[API Design Guide \\\u003e Errors](/apis/design/errors).\n\nFor production services, you should use one of Google-provided client libraries\nto call the Service Control API. Such libraries provide great usability\nand handle common functionality automatically, such as authentication.\nFor more information, see\n[Client Libraries Explained](/apis/docs/client-libraries-explained)."]]