Stackdriver JsonPayload not showing data for non null values.

15 views
Skip to first unread message

Smitha Malur

unread,
May 20, 2020, 1:01:43 PM5/20/20
to Google Stackdriver Discussion Forum
I am are using cloud logging APIs to publish stackdriver logs. I'm trying to log a java object . I'm using an enhancer to convert a textpayload to jsonPayload. I don't see any errors while I convert the payload. However, I see that only the values which are null are being logged. Non null values are not logged as part of the jsonPayload. 

converting the object to a JsonString
logger.info(mapper.writeValueAsString(pd));
 
code in the logging enhancer
@Override
  public void enhanceLogEntry(LogEntry.Builder logEntry) {
    logEntry.addLabel("project", "test");

    // Transform textPayload to JSONPayload
    ObjectMapper mapper = new ObjectMapper();
    Builder structBuilder = Struct.newBuilder();
    String textPayload = logEntry.build().getPayload().getData().toString();
    try {
      mapper.readTree(textPayload);
      JsonFormat.parser().merge(textPayload, structBuilder);
      logEntry.setPayload(JsonPayload.of(structBuilder.build()));
    } catch (InvalidProtocolBufferException e) {
      System.err.println(e.getMessage());
    } catch (IOException e) {
      // Do nothing (there is not a JSON Payload)
    }

  }

Screen Shot 2020-05-20 at 9.04.12 AM.png
Reply all
Reply to author
Forward
0 new messages