Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JSON Output]: allow to add more json data #297

Closed
roderik opened this issue Oct 23, 2020 · 5 comments
Closed

[JSON Output]: allow to add more json data #297

roderik opened this issue Oct 23, 2020 · 5 comments

Comments

@roderik
Copy link
Contributor

roderik commented Oct 23, 2020

Feature Request

Describe the solution you'd like

In our application, we have a lot of context which is relevant for our logs.

e.g.

  • on which cloud provider did this service execute
  • on which unique identifier did this service work
  • ...

In general, correlation ids and useful metadata you can explorer in a log viewer.

Currently, there is only 1 field that could be used, the requestID, but we need more and do not want to replace the request correlation id.

In Winston, they catalog all these as "meta"

Now, for output, in json mode, it would output {...meta, ...currentfields} while in text mode you either leave them out or print them in a block at the end of thee line.

By adding them to the json output, you can add columns and filter on these fields, see below for an example in datadog (with only the current fields available)

image

Teachability, Documentation, Adoption, Migration Strategy

There is no breaking change, a single optional extra param to 'log' would be all that is required.

What is the motivation / use case for changing the behavior?

see above

@roderik roderik changed the title [JSON Output]: [JSON Output]: allow to add more json data Oct 23, 2020
@jmcdo29
Copy link
Owner

jmcdo29 commented Oct 23, 2020

Thanks for the conversation on GitHub, to recap it here the following changes are probably going to be implemented:

  • log methods' signatures will change from (message: string, context?: string, application?: string, requestId?: string) to (message: string, metaInfo: {context?: string, application?: string, correlationId?: string, [key: string]: unknown }) to allow for adding in extra metadata
  • in JSON mode, the extra metadata will be added as top level keys so that log aggregators can better display logs with column titles
  • text mode will ignore new metadata but will keep the context, application, and correlationId
  • requestId will be renamed to correlationId

Did I miss anything? This will be a breaking change.

@roderik
Copy link
Contributor Author

roderik commented Oct 24, 2020

you could in json mode even keep everything under a "meta" key, that would be just fine in Kibana/Datadog etc

You could add a "debug/verbose" flag to the settings so it prints 2 lines, the second one with the meta data JSON stringified

jmcdo29 added a commit that referenced this issue Oct 25, 2020
The log methods now accept an object instead of multiple parameters to allow for the passing of
extra keys. These keys can be anything, from cloud-provider to anything else you want to add.
There's also a lot of refactoring and making some new interfaces for cleaner passing of parameters

BREAKING CHANGE: log methods now take an object as the second parameter instead of having 3 extra
optional parameters

fix #215 #228 #297
@jmcdo29 jmcdo29 mentioned this issue Oct 25, 2020
jmcdo29 added a commit that referenced this issue Oct 25, 2020
The log methods now accept an object instead of multiple parameters to allow for the passing of
extra keys. These keys can be anything, from cloud-provider to anything else you want to add.
There's also a lot of refactoring and making some new interfaces for cleaner passing of parameters

BREAKING CHANGE: log methods now take an object as the second parameter instead of having 3 extra
optional parameters

fix #215 #228 #297
@jmcdo29
Copy link
Owner

jmcdo29 commented Oct 25, 2020

Added to v0.4.0. This will most likely be the last pre v1 version. Thanks for the idea

@jmcdo29 jmcdo29 closed this as completed Oct 25, 2020
@roderik
Copy link
Contributor Author

roderik commented Oct 25, 2020

As an FYI for people upgrading, this release is breaking for some usage

    this.ogma.debug(`${message}`, component);

Now fails with the following typescript error

src/services/logger.ts(43,59): error TS2345: Argument of type 'string' is not assignable to parameter of type 'OgmaPrintOptions | undefined'.
src/services/logger.ts(47,59): error TS2345: Argument of type 'string' is not assignable to parameter of type 'OgmaPrintOptions | undefined'.
src/services/logger.ts(58,58): error TS2345: Argument of type 'string' is not assignable to parameter of type 'OgmaPrintOptions | undefined'.
src/services/logger.ts(66,59): error TS2345: Argument of type 'string' is not assignable to parameter of type 'OgmaPrintOptions | undefined'.
src/services/logger.ts(70,58): error TS2345: Argument of type 'string' is not assignable to parameter of type 'OgmaPrintOptions | undefined'.
src/services/apu.ts(290,56): error TS2345: Argument of type 'string' is not assignable to parameter of type '"" | "topic" | "direct" | "headers" | "fanout" | "match"'.
src/server.ts(35,17): error TS2345: Argument of type 'OgmaService' is not assignable to parameter of type 'LoggerService'.
  Types of property 'log' are incompatible.
    Type '(message: any, meta?: OgmaServiceMeta | undefined) => void' is not assignable to type '(message: any, context?: string | undefined) => any'.
      Types of parameters 'meta' and 'context' are incompatible.
        Type 'string | undefined' is not assignable to type 'OgmaServiceMeta | undefined'.
          Type 'string' is not assignable to type 'OgmaServiceMeta | undefined'.

Fixed by changing it to

    this.ogma.debug(`${message}`, {
      context: component,
    });

@jmcdo29
Copy link
Owner

jmcdo29 commented Oct 25, 2020

Yep. That was part of the original breaking change of 0.4.0, but now should be fixed on 0.4.1

jmcdo29 added a commit that referenced this issue Jun 20, 2021
The log methods now accept an object instead of multiple parameters to allow for the passing of
extra keys. These keys can be anything, from cloud-provider to anything else you want to add.
There's also a lot of refactoring and making some new interfaces for cleaner passing of parameters

BREAKING CHANGE: log methods now take an object as the second parameter instead of having 3 extra
optional parameters

fix #215 #228 #297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants