@@ -51,9 +51,21 @@ func NewCloudExporter(opts CloudOptions) (Exporter, error) {
5151 sdOpts .ProjectID = os .Getenv (envVarStackDriverProjectID )
5252 }
5353
54- // For Cloud Run applications use
54+ // For Cloud Run Services applications use
5555 // See: https://cloud.google.com/run/docs/container-contract#env-vars
56- if os .Getenv ("K_SERVICE" ) != "" {
56+ // Cloud Run Worker Pools do NOT have those env variable automatically injected
57+ // We manually add our own
58+ module := os .Getenv ("K_SERVICE" )
59+ if module == "" {
60+ // Check fallback env variable for Cloud Run Worker Pool
61+ module = os .Getenv ("GAE_SERVICE" )
62+ }
63+ version := os .Getenv ("K_REVISION" )
64+ if version == "" {
65+ // Check fallback env variable for Cloud Run Worker Pool
66+ version = os .Getenv ("CRWP_VERSION" )
67+ }
68+ if module != "" {
5769 // Allow for local testing with GCP_COMPUTE_ZONE
5870 var err error
5971 zone := os .Getenv ("GCP_COMPUTE_ZONE" )
@@ -84,8 +96,8 @@ func NewCloudExporter(opts CloudOptions) (Exporter, error) {
8496 // See: https://cloud.google.com/monitoring/custom-metrics/creating-metrics#create-metric-desc
8597 sdOpts .MonitoredResource = & gaeResource {
8698 projectID : os .Getenv (envVarStackDriverProjectID ),
87- module : os . Getenv ( "K_SERVICE" ) ,
88- version : os . Getenv ( "K_REVISION" ) ,
99+ module : module ,
100+ version : version ,
89101 instanceID : instanceID ,
90102 location : zone ,
91103 }
0 commit comments