GOOGLE_APPLICATION_CREDENTIALS 환경 변수를 JSON 키가 포함된 파일의 정규화된 이름으로 설정합니다.
이 환경 변수는 프로파일링 에이전트를 실행 중인 프로세스에 표시되어야 하므로 스크립트 또는 Dockerfile을 사용하여 프로세스를 실행할 경우 스크립트 또는 Dockerfile에 환경 변수를 포함합니다.
애플리케이션 기본 사용자 인증 정보 사용
에이전트가 애플리케이션 기본 사용자 인증 정보를 사용하도록 하려면 웹 흐름을 통해 사용자 액세스 인증 정보를 가져와서 애플리케이션 기본 사용자 인증 정보 라이브러리에서 요구하는 위치에 저장합니다.
이러한 사용자 인증 정보는 서비스 계정의 프록시 역할을 합니다.
애플리케이션 기본 사용자 인증 정보를 사용하려면 다음 Google Cloud CLI 명령어를 실행합니다.
gcloud auth application-default login
그리고 이 명령어가 안내하는 단계를 따릅니다.
에이전트를 Google Cloud 프로젝트에 연결
프로파일링 에이전트는 Google Cloud 프로젝트의 ID를 지정하여 프로필을 업로드할 수 있도록 구성되어야 합니다.
이 작업의 메커니즘은 언어별로 다릅니다.
Go
Go 애플리케이션 프로파일링에 설명된 profiler.Config 객체에 추가 매개변수 ProjectID를 지정합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Profiling applications running outside Google Cloud\n===================================================\n\nThis page describes how to profile applications running outside Google Cloud.\n\nIn this scenario, your application and the Cloud Profiler agent\nrun outside Google Cloud, but you use the Cloud Profiler\ninterface to analyze the profiling data.\n\nUsing the Profiler interface to analyze profiling data\nrequires a Google Cloud project. The profiling agent running elsewhere\nmust be able to send the profiles back for analysis. To enable this, you must:\n\n1. Create a Google Cloud project and enable the API.\n2. Obtain credentials for the profiling agent to use when uploading profiles.\n3. Configure the agent to use the credentials and the ID of the Google Cloud project.\n\nCreate a Google Cloud project\n-----------------------------\n\nIn the Google Cloud console, on the project selector page,\nclick **Create project** to begin creating a new\nGoogle Cloud project.\n\n[Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n\nEnable the Profiler API\n-----------------------\n\n1.\n\n\n Enable the required API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudprofiler.googleapis.com)\n2. \u003cbr /\u003e\n\n If **API enabled** is displayed, then the API is already enabled. If not, click the **Enable** button.\n\n \u003cbr /\u003e\n\nObtain credentials for the agent\n--------------------------------\n\nThere are two ways to obtain credentials for the agent to use:\n\n- Let the agent use a service account with private-key authentication\n- Let the agent use application default credentials (ADC).\n\n### Using service accounts\n\nTo enable the agent to use a service account with private-key authentication,\nyou must:\n\n1. Create a service account. For example, using the Google Cloud CLI:\n\n gcloud iam service-accounts create \u003cvar translate=\"no\"\u003eMY_SVC_ACCT_ID\u003c/var\u003e --display-name \"my service account\"\n\n See [Creating a service account](/iam/docs/creating-managing-service-accounts#creating_a_service_account) for more information.\n2. Grant the service account the **roles/cloudprofiler.agent**\n [role](/profiler/docs/iam), so that it can write profiling data. For example, using\n the Google Cloud CLI:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eGCP_PROJECT_ID\u003c/span\u003e\u003c/var\u003e \\\n --member serviceAccount:\u003cvar translate=\"no\"\u003eMY_SVC_ACCT_ID\u003c/var\u003e@\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com \\\n --role roles/cloudprofiler.agent\n\n See [Granting roles to service accounts](/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource) for more\n information.\n3. Create a JSON key for the service account. For example, using the\n Google Cloud CLI:\n\n gcloud iam service-accounts keys create \\\n ~/key.json \\\n --iam-account \u003cvar translate=\"no\"\u003eMY_SVC_ACCT_ID\u003c/var\u003e@\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com\n\n See [Creating service account keys](/iam/docs/creating-managing-service-account-keys) for more\n information.\n4. On the machine where the profiling agent will run:\n\n 1. Put a copy of the file containing the JSON key you just created.\n 2. Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to the fully qualified name of the file containing the JSON key. This environment variable must be visible to the process running the profiling agent, so if you use a script or Dockerfile to run the process, include the environment variable there.\n\n### Using application default credentials\n\nTo enable the agent to use application default credentials,\nyou obtain user-access credentials via a web flow\nand put them where the Application Default Credentials library expects them.\nThese credentials act as a proxy for a service account.\n\nTo use application default credentials, run the following Google Cloud CLI command: \n\n gcloud auth application-default login\n\nand follow the steps this command guides you through.\n\nLinking the agent to a Google Cloud project\n-------------------------------------------\n\nThe profiling agent must be configured to specify the ID of\nyour Google Cloud project so it can upload profiles.\nThe mechanism for doing this depends on the language. \n\n### Go\n\nSpecify an additional parameter, `ProjectID`, in the `profiler.Config`\nobject described in [Profiling Go applications](/profiler/docs/profiling-go#using-profiler): \n\n profiler.Config{ProjectID: \"\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e\", ...}\n\n### Java\n\nSpecify an additional [Java agent configuration](/profiler/docs/profiling-java#agent_configuration) flag,\n`cprof_project_id`, on the Java invocation: \n\n -cprof_project_id=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eGCP_PROJECT_ID\u003c/span\u003e\u003c/var\u003e\n\nWhen your application isn't able to access the Compute Engine metadata\nserver, messages similar to the following are displayed: \n\n```sh\n Error making HTTP request for 169.254.169.254:80/computeMetadata/v1/instance/zone\n```\nTo stop these messages, add `-cprof_zone_name=`\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e to your agent configuration flags and restart your application. For this scenario, replace \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e with a descriptive string such as \"test\".\n\n\u003cbr /\u003e\n\n### Node.js\n\nSpecify an additional parameter, `projectID`, in the `serviceContext`\nobject described in [Profiling Node.js applications](/profiler/docs/profiling-nodejs#using-profiler): \n\n projectId: '\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e',\n serviceContext: {\n ...\n }\n\n### Python\n\nSpecify an additional parameter, `project_id`, in the `start`\nmethod call described in [Profiling Python applications](/profiler/docs/profiling-python#using-profiler): \n\n googlecloudprofiler.start(..., project_id='\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e')\n\nWhat's next\n-----------\n\n- [Select the profiles to analyze](/profiler/docs/selecting-profiles)\n- [Interact with the flame graph](/profiler/docs/interacting-flame-graph)\n- [Filter the flame graph](/profiler/docs/filtering-profiles)\n- [Focus the flame graph](/profiler/docs/focusing-profiles)\n- [Compare profiles](/profiler/docs/comparing-profiles)"]]