DataDog / datadog-for-intellij-platform

Datadog for IntelliJ IDEA
https://docs.datadoghq.com/developers/ide_integrations/idea/
Other
5 stars 0 forks source link

[FEATURE] Node.js log insight support #31

Open seagullmouse opened 2 months ago

seagullmouse commented 2 months ago

Can't see log insights in my Node.js (Typescript) code

jfree commented 2 months ago

Thanks for your request! We have it on our roadmap to add WebStorm support for the plugin, and part of that work will involve adding the log framework detection required to show log insights for TypeScript. Which log framework do you use?

seagullmouse commented 2 months ago

Using winston. Thanks

jfree commented 3 weeks ago

The latest plugin release (v1.5.4) includes log detection for Winston, please give it a try!

seagullmouse commented 3 weeks ago

Just testing this now and I can't see the logs in IntelliJ, but I can see them in the Datadog webapp itself. FYI my code is Typescript.

I have the Datadog inlay hints turned on for both TypeScript and JavaScript.

Let me know what else I can give you to debug.

bric3 commented 2 weeks ago

@seagullmouse Could the code you are working on use the global winston methods rather than those on a logger object?

E.g.

import {warn} from "winston";

function hello() {
    warn("foo")
}
seagullmouse commented 2 weeks ago

Hi, we are in a large monorepo that has a shared logging package, that adds a bunch of stuff to the logger (e.g. log levels, container names etc, tags). Maybe this won't work for us after all then?

bric3 commented 2 weeks ago

Indeed that may not work depending on the changes, the detection used the winston.Logger type, and the next release will instead detect if the function is a LeveledLogMethod rather than use the qualifier type (winston.Logger), maybe that will help your project's customizations.

bric3 commented 1 week ago

@seagullmouse Hello, we released 1.5.5 last week, did it help in your case ?

seagullmouse commented 1 week ago

@bric3 unfortunately not.

Some pseudocode might help

// central-logger package
function createLogger(name: string){
// set up formats
// set log levels based on environment variables
// set transports
// Add to winston container or get the existing logger if it's already there

logger.debug("Creating logger, I can see the usage hint here!")
}

export const logger = createLogger("name");

// In a microservice
import { logger } from "central-logger";
logger.info("this log shows in Datadog UI but the usage hint doesn't show in IntelliJ")
bric3 commented 1 week ago

@seagullmouse In the log facade, does the log methods themselves have a different type than winston.LeveledLogMethod ?

image

I could probably add support for this kind of declarations, but the method type has to come from a union/intersection with either winston.LeveledLogMethod or winston.LogMethod.

declare namespace custom {
    type CustomLeveledLogMethod = {
        foo: string;
    } & LeveledLogMethod

    type CustomLogger = {
        info: CustomLeveledLogMethod;
    }

    let createLogger: (name: string) => CustomLogger;
}

export = custom;
seagullmouse commented 1 week ago

Just looking at our code, we abstract away from Winston types to a simple Logger type Image

Again, I appreciate there may be a mismatch between your work and our code here. It's Winston under the hood but you can't see that in the calling code.

bric3 commented 1 week ago

Again, I appreciate there may be a mismatch between your work and our code here. It's Winston under the hood but you can't see that in the calling code.

Indeed, and I'm not sure we should try to support Log* types that are not "derived" from winston types.