-
Notifications
You must be signed in to change notification settings - Fork 62
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 support to custom log level through command line flag and environment variable #842
base: main
Are you sure you want to change the base?
Conversation
instrumentation_test.go
Outdated
@@ -172,6 +172,14 @@ func TestWithResourceAttributes(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestWithLogLevel(t *testing.T) { | |||
c, err := newInstConfig(context.Background(), []InstrumentationOption{WithLogLevel("error")}) |
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.
Thanks for adding these tests! Do you mind extending the testing to cover what happens if invalid options are specified or the configuration doesn't contain logging level?
This is related to my earlier comment that parsing of the log level should be done here, so that invalid command line input is detected.
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.
Created the test to cover the validation of a wrong logging level
instrumentation.go
Outdated
|
||
// WithLogLevel returns an [InstrumentationOption] that will configure | ||
// an [Instrumentation] with the logger level visibility defined as inputed. | ||
func WithLogLevel(level string) InstrumentationOption { |
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.
Instead of accepting a string with special values, we should introduce a LogLevel
type with enum
values. We might want to use the OTel levels. For example:
https://github.com/open-telemetry/opentelemetry-go/blob/main/log/severity.go
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.
Do you think we need to create something which uses numbers as reference like the one you linked?
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.
That seems reasonable to me.
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 already do something like this for offsetgen:
flag.IntVar(&verbosity, "v", 0, "log verbosity") |
We could provided human readable flags for the CLI though (i.e. --log-level info
).
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.
Yeah, I usually prefer something human readable to CLI because is more quick to identify.
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.
@MrAlias I have create a simple Level Enum for logs, what do you think?
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.
@MrAlias I have create a simple Level Enum for logs, what do you think?
This still accepts a string
.
func WithLogLevel(level string) InstrumentationOption { | |
func WithLogLevel(level Level) InstrumentationOption { |
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.
@MrAlias This case here expect an string because is the input when use flag or from env, so for properly work is these scenarios this need to be string
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.
The environment variable needs to be parsed before it is passed to this function then.
We need to use syntax here to ensure the best possible chance values passed will be valid. Using an arbitrary string with magic values is not appropriate.
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.
@MrAlias changed WithLogLevel
to work on the behaviour you said
@vitorhugoro1 Do you plan on changing the level of the log line I mentioned in the issue?
|
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.
Shouldn't we support setting via OTEL_LOG_LEVEL
env var?
That is tracked in #691. It is out of scope for this PR. |
This PR says
|
Yeah this PR will implement this change too, I take the approach just with flags because is the way I usually use log levels on container |
I changed some log level, not just in the line you mentioned but in another which is more suitable to debugging not exactly on a production setup. Changed the sample job too to use debug level by default |
Added the supporting via environment with the name you suggest |
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.
LGTM!
internal/pkg/log/level.go
Outdated
// Log Level [dpanic]. | ||
LevelDPanic Level = "dpanic" |
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.
What is dpanic?
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.
Same as here
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.
I will remove this cases
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.
I removed these options
internal/pkg/log/level.go
Outdated
// Log Level [panic]. | ||
LevelPanic Level = "panic" | ||
// Log Level [fatal]. | ||
LevelFatal Level = "fatal" |
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.
What is the difference between panic and fatal? Shouldn't these both be terminations of the application?
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.
These two is to replicate what we see on zapcore.levels which is our base config
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.
I would replicate OTel logging levels if we are going to model this on a preexisting structure.
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.
I will remove these too
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.
I removed these options because they don't seem to make sense for the project
instrumentation.go
Outdated
|
||
// WithLogLevel returns an [InstrumentationOption] that will configure | ||
// an [Instrumentation] with the logger level visibility defined as inputed. | ||
func WithLogLevel(level string) InstrumentationOption { |
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.
@MrAlias I have create a simple Level Enum for logs, what do you think?
This still accepts a string
.
func WithLogLevel(level string) InstrumentationOption { | |
func WithLogLevel(level Level) InstrumentationOption { |
internal/pkg/log/level.go
Outdated
"fmt" | ||
) | ||
|
||
type Level string |
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.
Missing comment.
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.
Added comment
internal/pkg/log/level.go
Outdated
// Log Level [debug]. | ||
LevelDebug Level = "debug" | ||
// Log Level [info]. | ||
LevelInfo Level = "info" | ||
// Log Level [warn]. | ||
LevelWarn Level = "warn" | ||
// Log Level [error]. | ||
LevelError Level = "error" | ||
// Log Level [dpanic]. | ||
LevelDPanic Level = "dpanic" | ||
// Log Level [panic]. | ||
LevelPanic Level = "panic" | ||
// Log Level [fatal]. |
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.
These comments do not explain the levels. Please update so they communicate the logging strata they intend to enable.
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.
Added comments to levels
internal/pkg/log/level.go
Outdated
"fmt" | ||
) | ||
|
||
type Level string |
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 needs to be in the exported auto
package so users can reference it.
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.
I did not found where I could make this, can you explain to me?
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 lives in an internal package currently. It needs to be moved to the user accessible go.opentelemetry.io/auto
package instead.
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.
@MrAlias nice, changed to auto
package the level
Added on
InstrumentationOption
the option to define log level.Implemented a custom severity enum, called level.go, with options to set log levels based on text using
zap.Level
as reference.Added on CLI the flag
-log-level
that accept one ofLevel
value, which can be see on level.go ex.otel-go-instrumentation -log-level error
, the default value isinfo
.Added support to
OTEL_LOG_LEVEL
which implementslog.Level
to set visibility level through environment variable.Changed multiples logs level to Debug to improve setup when using in production environment.
Closes Add log verbosity configuration and move the log in controller.go to debug level #691