googleapis / nodejs-logging-winston

Node.js client integration between Stackdriver Logging and Winston.
https://cloud.google.com/logging/
Apache License 2.0
105 stars 50 forks source link

Latency of httpRequest not tracked when using library with redirectToStdout #799

Closed ktaekwon000 closed 10 months ago

ktaekwon000 commented 1 year ago

1) Is this a client library issue or a product issue? This seems to be a client library issue.

2) Did someone already solve this? I have searched through issues in the listed repositories but I have been unable to find the issue I am facing.

3) Do you have a support contract? No.

If the support paths suggested above still do not result in a resolution, please provide the following details.

Environment details

Steps to reproduce

  1. Log requests with the following code:
import * as gcpLogging from "@google-cloud/logging-winston";

const logger = createLogger({
  transports: [
    new gcpLogging.LoggingWinston({
      redirectToStdout: true,
    }),
  ],
  exitOnError: false,
});

const app = express();

app.use(await gcpLogging.express.makeMiddleware(logger));
  1. In an environment with Cloud Logging Agent, make requests to this service. When browsing the logs in Log Explorer, it can be seen that httpRequest data such as status, size and user agent is tracked properly, but the latency (Duration object) is not tracked.

I believe this bug is due to a difference in schema where the cloud logging agent expects an output in the JSON format, but the library prints the output in the protobuf format, causing the logging agent to miss this value. (Related issue: https://github.com/googleapis/nodejs-logging-winston/issues/93)

cindy-peng commented 10 months ago

Thanks @ktaekwon000 for opening the issue. By design Logging client libraries call the gRPC Logging API, and the latency in HttpMessage is expected to be protobuf.

We cannot use latency as a single string (e.g. 3.5s) in our code since Duration is a protobuf structure expected by Cloud Logging service. I believe that the issue needs to be fixed in stackdriver-logging-agent.

The documentation with correct links will be fixed here: https://github.com/googleapis/nodejs-logging-winston/pull/828.