C++ アプリケーションをトレースする
始める前に
- アカウントにログインします。 Google Cloud を初めて使用する場合は、 アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。 Google Cloud新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
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 Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Google Cloud CLI をインストールします。
-
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
-
gcloud CLI を初期化するには、次のコマンドを実行します:
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 Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Google Cloud CLI をインストールします。
-
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 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 のその他の例を試す。