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
171 stars 62 forks source link

LogSeverity not exported from @google-cloud/logging. #1402

Open RastogiAbhijeet opened 1 year ago

RastogiAbhijeet commented 1 year ago

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

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

2) Did someone already solve this? No.

3) Do you have a support contract? It's client-lib related issue.

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

Environment details

Steps to reproduce

  1. Import { LogSeverity } from "@google-cloud/logging" not exported

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

image

Thanks!

losalex commented 1 year ago

Thanks @RastogiAbhijeet for opening this issue! Can you please clarify why you need a direct reference for LogSeverity? What are you plans for using it?

RastogiAbhijeet commented 1 year ago

Hey @losalex ,

My use case is pretty straightforward, I want to enforce a strict type on the severity argument passed to the wrapper function I have written for the writing logs to Cloud Run stdout.

Currently the Severity enum exported by the @gooogle-cloud@logging node-module is mapping to numbers.

# Referred from the node modules
export declare enum Severity {
    emergency = 0,
    alert = 1,
    critical = 2,
    error = 3,
    warning = 4,
    notice = 5,
    info = 6,
    debug = 7
}

I can maybe also use SeverityName which can help me to get the severity names ( as I would expect ) but it does so in the lower case.

But the issue with both cases is that the severity is not properly reflected in the Cloud Log Explorer in the GCP console.

So for eg: I pass -> 2 for critical severity, the cloud log shows it as Severity "Default".

Now if you look at this link, it will show the correct number that should be used for the severity. https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity.


Another reason why I started to chase LogSeverity is because as I digged into the LogEntry Type in the node-module, you'd see that the severity in the metadata says -> LogSeverity and not Severity.

export type LogEntry = Omit<google.logging.v2.ILogEntry, 'timestamp' | 'severity' | 'httpRequest'> & {
    timestamp?: Timestamp | null;
    severity?: LogSeverity | null;
    httpRequest?: HttpRequest | null;
};

Ofcourse, I might be looking at the wrong place but how the types are being managed so of didn't make a lot of sense.

Honestly, I would label this as a bug and hope it gets fixed.


Hope it helps. Happy to chat through it if anything above didn't make sense.

Abhi347 commented 1 year ago

If you are interested in just the enum type, you can try something like

import { Entry } from '@google-cloud/logging';

export type LogSeverityType = Exclude<
  NonNullable<Entry['metadata']['severity']>,
  string
>;

But if you want the enum values, I am not sure if that's possible without explicit export. I asked this SO question in case it's possible.