Can the “initialData” property be used to write App Script parameters to a Stackdriver message?

别等时光非礼了梦想. 提交于 2021-02-10 03:31:17

问题


Summary

Google suggests that App Script parameters (among other data) can be written to Stackdriver using a JSON object with a "initialData" property. But it doesn't seem to work.

Issue Example

This Google page contains an example function that illustrates the different ways information can be written to Stackdriver.

An extract from their own code is below:

var parameters = {
  isValid: true,
  content: 'some string',
  timestamp: new Date()
};
console.log({message: 'Function Input', initialData: parameters});

When their App Script function is run it should write these parameter values into the Stackdriver log message.

But after it's run and Stackdriver is examined the message (example below) doesn't contain the parameter anywhere in it:

{
 insertId:  "s14ubwdkw81"  
 jsonPayload: {
  message:  "Function Input"   
  serviceContext: {
   service:  "AKfycbwcG7JGj9z-yomue0m_bOVdIVyFgDasdsasdsadngdCkk_l"
  }
 }
 labels: {
  script.googleapis.com/deployment_id:  "AKfycbwcG7JGj9z-yomue0m_bOVdsadsad7x7pHYngdCkk_l"   
  script.googleapis.com/process_id:  "EAEA1GOzkIp_aAfasdsadsadsazTnDWNA_ureP83_A8Agfr4IQ9pzSfRzfj1wnw8U_lCUUA4O9afoxyZuCCHYlB5ryBpu0LxfcibIITaoFqdbiVjprxDC5sVIXUAdpnQX3ud0-Xp8t9awJPH484YyeQRsassadZzksNSXYxl4VwcOw"   
  script.googleapis.com/project_key:  "MtcDasfdsfsfsfsfsaduYD4VaIEGs0Nwta"   
  script.googleapis.com/user_key:  "ANbVsadsadasdadashbqPEennz6PO1tasdsadasdfsddg+PjGhPshrkLV1SGwofeIcgpw0"   
 }
 logName:  "projects/project-id-416855555555555555559030426/logs/script.googleapis.com%2Fconsole_logs"  
 receiveTimestamp:  "2019-05-22T15:14:53.355673423Z"  
 resource: {
  labels: {
   function_name:  "measuringExecutionTime"
   invocation_type:  "editor"
   project_id:  "project-id-416855555555555530426"
  }
  type:  "app_script_function"   
 }
 severity:  "DEBUG"  
 timestamp:  "2019-05-22T15:14:52.844Z"  
}

I think this is a Stackdriver or App Script bug, but I wanted to make sure I hadn't made a mistake or missed something. Any ideas?

Update

Further investigation suggests it probably is a bug, because the same code in a Cloud Function does work as expected, Stackdriver extract below:

{
 insertId:  "000000-7e143986-76f1-5555-b167-8186214f7739"
 labels: {
  execution_id:  "o8r9555cli0j"   
 }
 logName:  "projects/my-project/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
 receiveTimestamp:  "2019-05-16T10:34:26.503211511Z"  
 resource: {
  labels: {
   function_name:  "gcf_htp_function_name"    
   project_id:  "my-project"    
   region:  "us-central1"    
  }
  type:  "cloud_function"   
 }
 severity:  "INFO"  
 textPayload:  "{ message: 'Function Input',
  initialData: 
   { isValid: true,
     content: 'some string'}"  
 timestamp:  "2019-05-23T10:34:21.084Z"  
 trace:  "projects/my-project/traces/a4df23072bfef15269947eaecf3a8f44"  
}

回答1:


It was a bug.

Google fixed it.

https://issuetracker.google.com/issues/133278375



来源:https://stackoverflow.com/questions/56260955/can-the-initialdata-property-be-used-to-write-app-script-parameters-to-a-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!