-
Notifications
You must be signed in to change notification settings - Fork 810
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
Introduce internal Console API to encapsulate console related calls to manage them from a single point #4950
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think I don't fully understand. If a user explicitly configures the console exporter (or the console diag logger), it stands to reason that the user would also expect their output to also show up in the exported logs, no?
Or is this about resolving a potential footgun that we provide to users with the SimpleLogRecordProcesor
ending up in an infinite loop when having diag logging/console exporter exporters enabled?
@@ -90,7 +90,7 @@ | |||
"webpack": "5.89.0" | |||
}, | |||
"peerDependencies": { | |||
"@opentelemetry/api": ">=1.0.0 <1.10.0" | |||
"@opentelemetry/api": ">=1.9.0 <1.10.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a breaking change that we cannot do in a minor version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea to not to make this breaking change or if these changes make sense, do we need to wait for v2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pichlermarc Maybe this should not be in the API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make sense?
- Move this internal
Console
API to@opentelemetry/core
- Keep
diag/consoleLogger
as is (will still access console directly), because@opentelemetry/api
can't have a dependency to@opentelemetry/core
soConsole
API is not visible to the@opentelemetry/api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pichlermarc Moved to @opentelemetry/core
, so no breaking change over @opentelemetry/api
.
Hi @pichlermarc, Actually, this introduced API is intended to be internal, not for the users. We will not expect users to log over The motivation is that (in the future) when/if we patch the console log methods (log, trace, debug, info, warn, error, dir) to capture console logs and export them as OTEL log records automatically, we will not want to capture console logs printed by console exporters of trace, metrics and logs. So the solution over this API might be that
For example: const origConsoleLogFunction = console.log;
const origConsoleErrorFunction = console.error;
const origConsoleWarnFunction = console.warn;
const origConsoleInfoFunction = console.info;
const origConsoleDebugFunction = console.debug;
const origConsoleTraceFunction = console.trace;
const origConsoleDirFunction = console.dir;
// Patch/wrap console log methods
Console.configure({
log: origConsoleLogFunction,
error: origConsoleErrorFunction,
warn: origConsoleWarnFunction,
info: origConsoleInfoFunction,
debug: origConsoleDebugFunction,
trace: origConsoleTraceFunction,
dir: origConsoleDirFunction,
}, console); Hope that this explains the motivation in more clear way. So does these changes make sense? |
…o manage them from a single point
1ddddfb
to
bc85e50
Compare
Hi @pichlermarc, any update on this? |
I think there's a typo in here but i can't figure out what you were trying to say @pichlermarc I think this is trying to prevent a loop if we capture logs from console and also export to console. Right now we are calling |
I think the same thing can be achieved by setting a context property when logging that suppresses capture. We do the same thing to suppress tracing our http/grpc exporters. |
| 'dir'; | ||
|
||
let activeConfig: ConsoleConfig = {}; | ||
let scopeObj: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not clear what this is for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is the configured object to be used while calling console function with the apply
export class Console { | ||
private constructor() {} | ||
|
||
static configure(config: ConsoleConfig, obj: any): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid any when possible. Also not clear what obj
is for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is the object to be used while calling console function with apply
above
Yes, preventing the loop is the original motivation of these changes. |
@dyladan actually, I also thought the same thing, but I think, even to set context property to suppress just before internal logging, we will still need to have some sort of internal API or module to do that and check whether it is set to decide suppress or not in the patched console methods. So, instead of doing this, always using this internal console API for internal logs made more sense to me. |
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
Which problem is this PR solving?
This PR neither adds new functionality or fixes a bug, but refactors the code base to use console methods over internal
Console
API instead of calling console methods directly.This can be helpful for us in the future (open-telemetry/opentelemetry-js-contrib#1560) once we add patching console methods to automatically exporting them as logs. The point is that, we may not want to capture our own console exports for traces, metrics and logs to the console and export them as log again. So, when we patch the console methods, we can configure
Console
API (overConsole.configure()
) with the original unpatched console methods, so they will not be intercepted.Short description of the changes
All the direct console calls are refactored to be done over internal
Console
API. So, when needed, console log behaviors can be managed from this single point.Type of change
Neither fix, nor new feature, but refactor for further new features.
How Has This Been Tested?
Existing tests of the following files test the changes in this PR:
ConsoleTraceExporter
ConsoleMetricExporter
ConsoleLogRecordExporter
Checklist: