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

feat(sdk-logs): added colors option to ConsoleLogRecordExporter #4524

Conversation

10xLaCroixDrinker
Copy link
Contributor

Which problem is this PR solving?

I'm running this exporter in a worker thread (using a pino logger), and since in that context process.stdout is not a TTY, the logs are not colorized. I'd like the option to force the colorization.

Short description of the changes

Added an optional config for the ConsoleLogRecordExporter that has a single option colors which can override the automatic color support detection to turn colorization on or off.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added new unit tests that cover the change
  • Installed into another project and validated manually

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@10xLaCroixDrinker 10xLaCroixDrinker requested a review from a team March 4, 2024 15:40
@10xLaCroixDrinker
Copy link
Contributor Author

👋 @open-telemetry/javascript-approvers

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Merging #4524 (885cc15) into main (f6a075b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4524   +/-   ##
=======================================
  Coverage   92.84%   92.85%           
=======================================
  Files         328      328           
  Lines        9494     9498    +4     
  Branches     2040     2042    +2     
=======================================
+ Hits         8815     8819    +4     
  Misses        679      679           
Files Coverage Δ
...es/sdk-logs/src/export/ConsoleLogRecordExporter.ts 90.00% <100.00%> (+2.50%) ⬆️

@10xLaCroixDrinker 10xLaCroixDrinker force-pushed the feature/console-log-record-exporter-options branch from 24a025c to 773750a Compare March 11, 2024 20:13
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Hi, thanks for opening this PR 🙂

I think I might be missing some context: Is this change intended for production use or is that something that you're intending to use for local debugging? 🤔

@10xLaCroixDrinker
Copy link
Contributor Author

I only use the ConsoleLogRecordExporter in NODE_ENV=development

@10xLaCroixDrinker
Copy link
Contributor Author

10xLaCroixDrinker commented Mar 12, 2024

I'm using pino for logging with pino-opentelemetry-transport. Since its running in a worker thread there is never colorization. Currently, I'm conditionally setting process.env.FORCE_COLORS="1" when I create the exporter to provide this. What I'd like to do is pass my options as { colors: process.stdout.isTTY } from the main thread.

@10xLaCroixDrinker
Copy link
Contributor Author

@pichlermarc what do you think?

@pichlermarc
Copy link
Member

@10xLaCroixDrinker would it help to have colorized output be the default behavior (also for metric and trace console exporters)? 🤔

I'm thinking something like: if process is defined (may not be defined in the browser) and output is TTY, then automatically set the option. This way we would not add to the API surface of the ConsoleExporter 🙂

@10xLaCroixDrinker
Copy link
Contributor Author

@pichlermarc that is already the default behavior when process.stdout is a TTY. I'm running into this because the exporter is in a worker thread where it is not a TTY. When I say that I'd set the config to { colors: process.stdout.isTTY }, that would just be when I'm setting the config in the main thread. When the exporter is created in the worker thread, it will just receive { colors: true }

@pichlermarc
Copy link
Member

Sorry for leaving you waiting for so long.

@pichlermarc that is already the default behavior when process.stdout is a TTY. I'm running into this because the exporter is in a worker thread where it is not a TTY. When I say that I'd set the config to { colors: process.stdout.isTTY }, that would just be when I'm setting the config in the main thread. When the exporter is created in the worker thread, it will just receive { colors: true }

I see.

I'd like to avoid having to increase the API surface for the console exporters. A reason why we have not added any features/config options to any of the other console exporters in the past was that the exporter interface is reasonably easy to implement on one's own. We therefore usually recommend users to implement a custom exporter for use-cases like this.

While I see that the feature can be useful we'd still want to apply the same principle for this exporter.

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