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

Add useWinstonMetaAsLabels option #155

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

MasterIO02
Copy link
Contributor

When enabled, this option pushes the "rest" of Winston's log info to Loki labels.

This is useful to pass dynamic labels to Loki from the Winston log method directly, for example APIs HTTP methods or status codes.

This PR seems to contradict PR #103 that is still open, but since then, Grafana Loki devs are using dynamic labels in their docs for storing status codes or HTTP methods so it seems fair to use Winston's metadata to pass to Loki's labels, as long as they're not totally dynamic (e.g. different IDs for every log).

This option is disabled by default and overrides the "labels" option, because imo the fixed labels should be defined in Winston directly with the "defaultMeta" option when initializing a new Logger, but other ways might be better.

I named the option useWinstonMetaAsLabels because Winston considers anything other than "level" and "message" to be "meta" in their docs, though it could be shorter.

It should probably be paired with some sort of whitelist/blacklist to be able to only use some Winston meta as Loki labels, but I'm not sure which is best to implement.

Copy link
Contributor

sweep-ai bot commented Apr 17, 2024

Apply Sweep Rules to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.

This is an automated message generated by Sweep AI.

@MasterIO02
Copy link
Contributor Author

After some reflexion, I've added an "ignoredMeta" option that will make the useWinstonMetaAsLabels option ignore the meta tags provided in that array.

This is useful when we want to have Winston handle the logging of non-string values (like errors) to the console, but not have them as labels in Loki.

Copy link
Owner

@JaniAnttonen JaniAnttonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this succinct and well described PR! I'll draft a new release from this ASAP, and probably will simplify the config further defaulting on this logic in a future release.

@JaniAnttonen JaniAnttonen merged commit a45ead9 into JaniAnttonen:development Apr 24, 2024
@JaniAnttonen JaniAnttonen mentioned this pull request Apr 24, 2024
mattgodbolt referenced this pull request in compiler-explorer/compiler-explorer Apr 30, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [winston-loki](https://togithub.com/JaniAnttonen/winston-loki) |
[`^6.1.1` ->
`^6.1.2`](https://renovatebot.com/diffs/npm/winston-loki/6.1.1/6.1.2) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/winston-loki/6.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/winston-loki/6.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/winston-loki/6.1.1/6.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/winston-loki/6.1.1/6.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>JaniAnttonen/winston-loki (winston-loki)</summary>

###
[`v6.1.2`](https://togithub.com/JaniAnttonen/winston-loki/releases/tag/v6.1.2):
Enable usage of Winston meta tags as labels

[Compare
Source](https://togithub.com/JaniAnttonen/winston-loki/compare/v6.1.1...v6.1.2)

#### What's Changed

- Add useWinstonMetaAsLabels option by
[@&#8203;MasterIO02](https://togithub.com/MasterIO02) in
[https://github.com/JaniAnttonen/winston-loki/pull/155](https://togithub.com/JaniAnttonen/winston-loki/pull/155)

#### New Contributors

- [@&#8203;MasterIO02](https://togithub.com/MasterIO02) made their first
contribution in
[https://github.com/JaniAnttonen/winston-loki/pull/155](https://togithub.com/JaniAnttonen/winston-loki/pull/155)

**Full Changelog**:
JaniAnttonen/winston-loki@v6.1.1...v6.1.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 8pm on monday" in timezone
America/Chicago, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/compiler-explorer/compiler-explorer).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yOTMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjMxMy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

2 participants