{"record":{"id":"31b5f9f8e6bd58cb","repo":"apache/beam","slug":"unable-to-find-the-job-id-or-job-name-from-envvar","errorCode":null,"errorMessage":"Unable to find the job id or job name from envvar.","messagePattern":"Unable to find the job id or job name from envvar\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"warning","filePath":"sdks/python/apache_beam/runners/worker/sdk_worker_main.py","lineNumber":220,"sourceCode":"      data_sampler=data_sampler,\n      deferred_exception=deferred_exception,\n      runner_capabilities=runner_capabilities,\n      element_processing_timeout_minutes=sdk_pipeline_options.view_as(\n          WorkerOptions).element_processing_timeout_minutes)\n  return fn_log_handler, sdk_harness, sdk_pipeline_options\n\n\ndef _start_profiler(gcp_profiler_service_name, gcp_profiler_service_version):\n  try:\n    import googlecloudprofiler\n    if gcp_profiler_service_name and gcp_profiler_service_version:\n      googlecloudprofiler.start(\n          service=gcp_profiler_service_name,\n          service_version=gcp_profiler_service_version,\n          verbose=1)\n      _LOGGER.info('Turning on Google Cloud Profiler.')\n    else:\n      raise RuntimeError('Unable to find the job id or job name from envvar.')\n  except Exception as e:  # pylint: disable=broad-except\n    _LOGGER.warning(\n        'Unable to start google cloud profiler due to error: %s. For how to '\n        'enable Cloud Profiler with Dataflow see '\n        'https://cloud.google.com/dataflow/docs/guides/profiling-a-pipeline.'\n        'For troubleshooting tips with Cloud Profiler see '\n        'https://cloud.google.com/profiler/docs/troubleshooting.' % e)\n\n\ndef _get_gcp_profiler_name_if_enabled(sdk_pipeline_options):\n  gcp_profiler_service_name = sdk_pipeline_options.view_as(\n      GoogleCloudOptions).get_cloud_profiler_service_name()\n\n  return gcp_profiler_service_name\n\n\ndef main(unused_argv):\n  \"\"\"Main entry point for SDK Fn Harness.\"\"\"","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/worker/sdk_worker_main.py#L202-L238","documentation":"When Google Cloud Profiler is enabled on a Dataflow worker, googlecloudprofiler.start requires a service name and version derived from the job id/job name environment variables. If neither is present, the worker raises 'Unable to find the job id or job name from envvar.'; the surrounding handler logs a warning so profiling is skipped, not fatal.","triggerScenarios":"Enabling cloud profiling (e.g. --dataflow_enable_google_cloud_profiler or setting the profiler flag) on a runner/environments where JOB_ID/JOB_NAME env vars are not exported to the worker.","commonSituations":"Running the harness locally or on non-Dataflow runners with profiling enabled; custom container images that drop Dataflow env vars; older runner versions not exporting job metadata.","solutions":["Disable Google Cloud Profiler unless running on Dataflow (remove --dataflow_enable_google_cloud_profiler)","Ensure JOB_ID/JOB_NAME environment variables are set in the worker environment","Set gcp_profiler_service_name/gcp_profiler_service_version explicitly in sdk_worker_main so envvar lookup is bypassed","Check the worker logs: this error is caught and logged as a warning, profiling is simply skipped"],"exampleFix":"// before\n# harness started with --dataflow_enable_google_cloud_profiler but no JOB_ID\n// after\nexport JOB_ID=my-job-id\nexport JOB_NAME=my-job-name\n# or omit the profiler flag for local runs","handlingStrategy":"validation","validationCode":"import os\nprofiler_ready = os.environ.get('JOB_ID') or os.environ.get('JOB_NAME')\nif not profiler_ready:\n  print('Cloud Profiler disabled: JOB_ID/JOB_NAME not set')","typeGuard":"def can_start_profiler(env): return bool(env.get('JOB_ID') and env.get('JOB_NAME'))","tryCatchPattern":"try:\n  _start_profiler(options)\nexcept RuntimeError as e:\n  log.warning('profiler skipped: %s', e)  # non-fatal, mirroring sdk_worker_main","preventionTips":["Only enable Cloud Profiler on Dataflow where JOB_ID/JOB_NAME are exported","Set service name/version explicitly for non-Dataflow environments","Treat this as a warning, not a startup failure"],"tags":["apache-beam","dataflow","profiling","env-vars"],"backgroundTag":"missing-env-var","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}