本页面介绍了如何使用 Service Control API v2 对与 Service Infrastructure 集成的托管式服务进行遥测报告。适用于想要将其服务与 Google Cloud 深度集成的服务提供商。
Service Infrastructure 是一个基础平台,可供开发者生成、管理、保护和使用 API 和服务。它使用一个简单的通用性服务使用模型:使用者使用由生产者管理的服务。所有 Google API 和 Google Cloud API都使用此模型,因为它们也是基于 Service Infrastructure 构建的。
当使用方访问服务时,服务会向平台报告相关遥测数据,因此使用方和提供方都可以观察该访问。使用 Service Infrastructure,此过程被称为遥测报告,其中包括分析、审核、结算、日志记录和监控。
Service Control API v2
Service Control API v2 提供了一种简单的 services.report 方法,该方法为与 Service Infrastructure 集成的所有服务提供遥测报告。此方法使您可以在单个方法调用中执行以下操作:
分析
审核
结算
日志记录
监控
当服务向 Service Control API 报告遥测数据时,数据会被分发给使用方和/或提供方,具体取决于服务配置。如需详细了解如何配置遥测,请参阅 google.api.Service 的日志记录和监控部分。
为了使用调用 Service Control API 的服务,生产者必须在生产者项目上启用 Service Control API,而调用者必须对该服务具有适当的权限。如需了解详情,请参阅 Cloud API 使用入门和 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"]],["最后更新时间 (UTC):2025-09-04。"],[],[],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)."]]