Structured logging in stackdriver from gcloud function

Hello! First post in this forum, and new to golang.

I’ve developed a simple function in golang and implemented it in a google cloud function. It works fine.
When I print to the standard output, I see a line in the logs viewer in the stackdriver.

So, I decided to log a json with all the execution (parameters received, data, etc) and print to the standard output a simple json containing all the relevant information.
When I print that json to the standard output in my local environment, works fine. But when I print the same json in the cloud function, the stackdriver loggin logs a strange json.

This is my json, printed to the standard output in my console:

When I print the same json in the google cloud function, what I see in the log viewer is a different json, with lot of strange fields:

this is part of my code. Any help is welcome!!

type Pair struct {
Key string json:key
Value string json:value

type DataToLog struct {
ReceivedData []Pair json:DataFromGet
ServerResponse string json:ServerResponse
ServerData string json:ServerData
RemoteIP string json:RemoteIP
DataToQMT DataToSend

func RequestHandler(w http.ResponseWriter, r *http.Request) {

var log DataToLog

(.. code that fills the struct...)

byteArrayLog, _ := json.Marshal(log)



Hey, i encountered the same issue. Did you find a solution?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.