C++ アプリケーションをトレースする
始める前に
-
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.-
Google Cloud CLI をインストールします。
-
フェデレーション ID(連携 ID)を使用するように gcloud CLI を構成します。
詳細については、連携 ID を使用して gcloud CLI にログインするをご覧ください。
-
gcloud CLI を初期化するには、次のコマンドを実行します:
gcloud init
設定
ID
my-topicを含むトピックを作成します。gcloud pubsub topics create my-topicC++ のサンプル ソースコードを確認します。
git clone --depth 1 https://github.com/GoogleCloudPlatforms/cpp-samples
メッセージをパブリッシュする
例をコンパイルして実行します。
cd cpp-samples/pubsub-open-telemetry bazel run //:quickstart -- $(gcloud config get project) my-topicこの例を実行すると、次の行がコンソールに出力されます。
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)
トレースを表示
コンソールで、
[Trace エクスプローラ] ページに移動します。 Google Cloud
このページは、検索バーを使用して見つけることもできます。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、 次の手順を実施します。
この例で作成したトピックを削除します。
gcloud pubsub topics delete my-topic
次のステップ
- C++ と OpenTelemetry の詳細を確認する。
- C++ の例を探す。
- Pub/Sub API について学習します。
- C++ Pub/Sub OpenTelemetry のその他の例を試す。