C++-Anwendung analysieren
Hier erfahren Sie, wie Sie das C++-Beispiel mit OpenTelemetry kompilieren und ausführen und die Traces in Cloud Trace exportieren. In diesem Beispiel wird der Google Cloud Pub/Sub-C++-Client verwendet, um fünf Nachrichten zu veröffentlichen und die Traces in Cloud Trace zu exportieren.
Hinweis
-
In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance 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 Cloud de Confiance project.
Enable the Pub/Sub and Trace APIs, if any are not already enabled.
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.-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
Einrichten
Erstellen Sie ein Thema mit der ID
my-topic:gcloud pubsub topics create my-topicSehen Sie sich den C++-Beispielquellcode an:
git clone --depth 1 https://github.com/GoogleCloudPlatforms/cpp-samples
Nachrichten veröffentlichen
Kompilieren Sie das Beispiel und führen Sie es aus:
cd cpp-samples/pubsub-open-telemetry bazel run //:quickstart -- $(gcloud config get project) my-topicNachdem Sie dieses Beispiel ausgeführt haben, werden die folgenden Zeilen in der Konsole ausgegeben.
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)
Traces ansehen
Rufen Sie in der Cloud de Confiance Console die Seite
Trace Explorer auf:
Sie können diese Seite auch über die Suchleiste finden.
Bereinigen
Mit den folgenden Schritten vermeiden Sie, dass Ihrem Cloud de Confiance -Konto die auf dieser Seite verwendeten Ressourcen in Rechnung gestellt werden:
Löschen Sie das durch das Beispiel erstellte Thema:
gcloud pubsub topics delete my-topic