C++ 애플리케이션 추적
OpenTelemetry를 사용하여 C++ 예시를 컴파일하고 실행하는 방법을 알아보고 trace를 Cloud Trace로 내보내는 방법을 보여줍니다. 이 예시에서는 Google Cloud Pub/Sub C++ 클라이언트를 사용하여 메시지 5개를 게시하고 Cloud Trace로 trace를 내보냅니다.
시작하기 전에
- Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $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 콘솔에서
Trace 탐색기 페이지로 이동합니다.
검색창을 사용하여 이 페이지를 찾을 수도 있습니다.
삭제
이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 수행합니다.
예시에서 만든 주제를 삭제합니다.
gcloud pubsub topics delete my-topic
다음 단계
- C++ 및 OpenTelemetry에 대해 자세히 알아보세요.
- 더 많은 C++ 예시를 찾아봅니다.
- Pub/Sub API 자세히 알아보기
- 더 많은 C++ Pub/Sub OpenTelemetry 예시를 사용해 보세요.