Cómo hacer un seguimiento de una aplicación de C++
Aprende a compilar y ejecutar el ejemplo de C++ con OpenTelemetry y exportar los seguimientos a Cloud Trace. En este ejemplo, se usa el cliente de Google Cloud Pub/Sub C++ para publicar 5 mensajes y exportar los seguimientos a Cloud Trace.
Antes de comenzar
- Accede a tu cuenta de Google Cloud . Si eres nuevo en Google Cloud, crea una cuenta para evaluar el rendimiento de nuestros productos en situaciones reales. Los clientes nuevos también obtienen $300 en créditos gratuitos para ejecutar, probar y, además, implementar cargas de trabajo.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Pub/Sub and Trace APIs.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Instala Google Cloud CLI.
-
Si usas un proveedor de identidad externo (IdP), primero debes acceder a la gcloud CLI con tu identidad federada.
-
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Pub/Sub and Trace APIs.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Instala Google Cloud CLI.
-
Si usas un proveedor de identidad externo (IdP), primero debes acceder a la gcloud CLI con tu identidad federada.
-
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloud init
Configurar
Crea un tema con el ID
my-topic:gcloud pubsub topics create my-topicExtrae el código fuente de muestra de C++:
git clone --depth 1 https://github.com/GoogleCloudPlatforms/cpp-samples
Publica mensajes
Compila y ejecuta el ejemplo:
cd cpp-samples/pubsub-open-telemetry bazel run //:quickstart -- $(gcloud config get project) my-topicDespués de ejecutar este ejemplo, verás las siguientes líneas impresas en la consola.
Sent message with id: (9095112996778043) Sent message with id: (9095112996778044) Sent message with id: (9095112996778045) Sent message with id: (9095112996778046) Sent message with id: (9095112996778047)
Ver seguimientos
En la consola de Google Cloud , ve a la página
Explorador de seguimiento:
Ve al Explorador de seguimiento
También puedes usar la barra de búsqueda para encontrar esta página.
Realiza una limpieza
Sigue estos pasos para evitar que se apliquen cargos a tu cuenta de Google Cloud por los recursos que usaste en esta página.
Borra el tema que creó el ejemplo:
gcloud pubsub topics delete my-topic
¿Qué sigue?
- Obtén más información sobre C++ y OpenTelemetry.
- Encuentra más ejemplos de C++.
- Obtén más información sobre las APIs de Pub/Sub.
- Prueba más ejemplos de OpenTelemetry de Pub/Sub en C++.