1616import static com .google .cloud .opentelemetry .detection .AttributeKeys .GCE_INSTANCE_ID ;
1717import static com .google .cloud .opentelemetry .detection .AttributeKeys .GCE_INSTANCE_NAME ;
1818import static com .google .cloud .opentelemetry .detection .AttributeKeys .GCE_MACHINE_TYPE ;
19+ import static com .google .cloud .opentelemetry .detection .AttributeKeys .GCR_JOB_EXECUTION_KEY ;
20+ import static com .google .cloud .opentelemetry .detection .AttributeKeys .GCR_JOB_TASK_INDEX ;
1921import static com .google .cloud .opentelemetry .detection .AttributeKeys .GKE_CLUSTER_LOCATION ;
2022import static com .google .cloud .opentelemetry .detection .AttributeKeys .GKE_CLUSTER_LOCATION_TYPE ;
2123import static com .google .cloud .opentelemetry .detection .AttributeKeys .GKE_CLUSTER_NAME ;
@@ -106,6 +108,9 @@ public Attributes getAttributes() {
106108 case GOOGLE_CLOUD_FUNCTIONS :
107109 addGcfAttributes (attrBuilder , detectedPlatform .getAttributes ());
108110 break ;
111+ case GOOGLE_CLOUD_RUN_JOB :
112+ addGcrJobAttributes (attrBuilder , detectedPlatform .getAttributes ());
113+ break ;
109114 case GOOGLE_APP_ENGINE :
110115 addGaeAttributes (attrBuilder , detectedPlatform .getAttributes ());
111116 break ;
@@ -192,8 +197,8 @@ private static void addGkeAttributes(
192197 }
193198
194199 /**
195- * Updates the attributes with the required keys for a GCR (Google Cloud Run) environment. The
196- * attributes are not updated in case the environment is not deemed to be GCR.
200+ * Updates the attributes with the required keys for a GCR (Google Cloud Run) Service environment.
201+ * The attributes are not updated in case the environment is not deemed to be GCR.
197202 *
198203 * @param attrBuilder The {@link AttributesBuilder} object that needs to be updated with the
199204 * necessary keys.
@@ -217,6 +222,34 @@ private static void addGcfAttributes(
217222 addCommonAttributesForServerlessCompute (attrBuilder , attributesMap );
218223 }
219224
225+ /**
226+ * Update the attributes with the required keys for a GCR (Google Cloud Run) Jobs environment. The
227+ * attributes are not updated in case the environment is not deemed to be GCR jobs environment.
228+ *
229+ * @param attrBuilder The {@link AttributesBuilder} object that needs to be updated with the
230+ * necessary keys.
231+ */
232+ private static void addGcrJobAttributes (
233+ AttributesBuilder attrBuilder , Map <String , String > attributesMap ) {
234+ attrBuilder .put (CLOUD_PLATFORM , GCP_CLOUD_RUN );
235+ Optional .ofNullable (attributesMap .get (SERVERLESS_COMPUTE_NAME ))
236+ .ifPresent (name -> attrBuilder .put (FAAS_NAME , name ));
237+ Optional .ofNullable (attributesMap .get (SERVERLESS_COMPUTE_INSTANCE_ID ))
238+ .ifPresent (instanceId -> attrBuilder .put (FAAS_INSTANCE , instanceId ));
239+ Optional .ofNullable (attributesMap .get (SERVERLESS_COMPUTE_CLOUD_REGION ))
240+ .ifPresent (cloudRegion -> attrBuilder .put (CLOUD_REGION , cloudRegion ));
241+ Optional .ofNullable (attributesMap .get (GCR_JOB_EXECUTION_KEY ))
242+ .ifPresent (
243+ jobExecutionKey ->
244+ attrBuilder .put (IncubatingAttributes .GCP_CLOUD_RUN_JOB_EXECUTION , jobExecutionKey ));
245+ Optional .ofNullable (attributesMap .get (GCR_JOB_TASK_INDEX ))
246+ .ifPresent (
247+ jobTaskIndex ->
248+ attrBuilder .put (
249+ IncubatingAttributes .GCP_CLOUD_RUN_JOB_TASK_INDEX ,
250+ Integer .parseInt (jobTaskIndex )));
251+ }
252+
220253 /**
221254 * Updates the attributes with the required keys for a GAE (Google App Engine) environment. The
222255 * attributes are not updated in case the environment is not deemed to be GAE.
0 commit comments