googleapis / nodejs-logging

Node.js client for Stackdriver Logging: Store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services (AWS).
https://cloud.google.com/logging/
Apache License 2.0
172 stars 62 forks source link

Inconsistent/Incorrect Typing of LogEntry.HttpRequest.Latency #1417

Closed mantism closed 1 year ago

mantism commented 1 year ago

I want to log http requests to LogExplorer by printing LogEntry objects to stdout. This works for the most part, but I've noticed latency doesn't get automatically parsed in Log Explorer from the HttpRequest object.

The LogEntry.HttpRequest documentation lists the JSON representation as having latency by of type string, but the proto and other types for HttpRequest have latency as a Duration with seconds and nano.

As a result, when logged to stdout, Log Explorer leaves the latency object in the jsonPayload field as opposed to the httpRequest field of the LogEntry.

1) Is this a client library issue or a product issue?

2) Did someone already solve this?

3) Do you have a support contract? N/A

Environment details

Steps to reproduce

  1. Create an object of type LogEntry with an httpRequest
  2. console.log() the LogEntry
  3. Check LogExplorer and see that the LogEntry has latency in jsonPayload instead of httpRequest i.e.
{
  "logName": "example-logName",
  "timestamp": "1234",
  "severity":  "INFO"
  "insertId":  "..1234",
  "httpRequest": {
      "requestMethod": "GET",
      "requestUrl": "example.com/api/example",
      "protocol": "http",
      // Expected latency here
   }
  "jsonPayload": {
      // Expected to see this in httpRequest
      "latency": {
         "seconds": 1
         "nanos": 2
      }
  }
}

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

losalex commented 1 year ago

@mantism , thank you very much for opening the issue and sorry for late response! Indeed, documentation is confusing with respect of latency being a string type. Thats said, if I execute following code:

log.write(logging.entry({
  httpRequest: {
    requestMethod: 'GET',
    requestUrl: 'http://some-url.com',
    status: 200,
    latency: {
      seconds: 1,
      nanos: 2,
   },
  }}, {message: "This is an info 1"}));

I see that latency generated properly in Logs Explorer:

image

Would you be able to share the code snippet you used to repro a problem? Thanks!

losalex commented 1 year ago

Closing this due to no response - please feel free to reactivate if there are any questions or new findings.