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 support to custom log level through command line flag and environment variable #842

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

vitorhugoro1
Copy link

@vitorhugoro1 vitorhugoro1 commented May 13, 2024

  • 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 of Level value, which can be see on level.go ex. otel-go-instrumentation -log-level error, the default value is info.

  • Added support to OTEL_LOG_LEVEL which implements log.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

@vitorhugoro1 vitorhugoro1 requested a review from a team as a code owner May 13, 2024 17:49
Copy link

linux-foundation-easycla bot commented May 13, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

instrumentation.go Show resolved Hide resolved
@@ -172,6 +172,14 @@ func TestWithResourceAttributes(t *testing.T) {
})
}

func TestWithLogLevel(t *testing.T) {
c, err := newInstConfig(context.Background(), []InstrumentationOption{WithLogLevel("error")})
Copy link
Contributor

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.

Copy link
Author

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

@MrAlias MrAlias added this to the v0.12.0-alpha milestone May 14, 2024

// WithLogLevel returns an [InstrumentationOption] that will configure
// an [Instrumentation] with the logger level visibility defined as inputed.
func WithLogLevel(level string) InstrumentationOption {
Copy link
Contributor

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

Copy link
Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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).

Copy link
Author

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.

Copy link
Author

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?

Copy link
Contributor

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.

Suggested change
func WithLogLevel(level string) InstrumentationOption {
func WithLogLevel(level Level) InstrumentationOption {

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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

@RonFed
Copy link
Contributor

RonFed commented May 15, 2024

@vitorhugoro1 Do you plan on changing the level of the log line I mentioned in the issue?
In addition, we can use debug level in our tests at

command: ["/otel-go-instrumentation", "-global-impl"]

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

@MrAlias
Copy link
Contributor

MrAlias commented May 15, 2024

Shouldn't we support setting via OTEL_LOG_LEVEL env var?

Reference: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration

That is tracked in #691. It is out of scope for this PR.

@pellared
Copy link
Member

Shouldn't we support setting via OTEL_LOG_LEVEL env var?
Reference: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration

That is tracked in #691. It is out of scope for this PR.

This PR says

Closes #691

@vitorhugoro1
Copy link
Author

Shouldn't we support setting via OTEL_LOG_LEVEL env var?
Reference: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration

That is tracked in #691. It is out of scope for this PR.

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

@vitorhugoro1
Copy link
Author

@vitorhugoro1 Do you plan on changing the level of the log line I mentioned in the issue? In addition, we can use debug level in our tests at

command: ["/otel-go-instrumentation", "-global-impl"]

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

@vitorhugoro1
Copy link
Author

Shouldn't we support setting via OTEL_LOG_LEVEL env var?

Reference: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration

Added the supporting via environment with the name you suggest

@vitorhugoro1 vitorhugoro1 changed the title Add log level through command line flag Add support to custom log level through command line flag and environment variable May 15, 2024
instrumentation.go Show resolved Hide resolved
internal/pkg/instrumentation/manager.go Outdated Show resolved Hide resolved
internal/pkg/process/allocate.go Outdated Show resolved Hide resolved
internal/pkg/process/discover.go Outdated Show resolved Hide resolved
instrumentation.go Show resolved Hide resolved
cli/main.go Outdated Show resolved Hide resolved
cli/main.go Outdated Show resolved Hide resolved
@vitorhugoro1 vitorhugoro1 requested a review from RonFed May 17, 2024 13:45
@vitorhugoro1
Copy link
Author

@pellared @MrAlias @grcevski it's okay now for you guys?

Copy link
Contributor

@grcevski grcevski left a comment

Choose a reason for hiding this comment

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

LGTM!

@edeNFed
Copy link
Contributor

edeNFed commented May 27, 2024

Can we merge this?
@MrAlias @pellared

Comment on lines 34 to 35
// Log Level [dpanic].
LevelDPanic Level = "dpanic"
Copy link
Contributor

Choose a reason for hiding this comment

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

What is dpanic?

Copy link
Author

Choose a reason for hiding this comment

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

Same as here

#842 (comment)

Copy link
Author

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

Copy link
Author

Choose a reason for hiding this comment

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

I removed these options

// Log Level [panic].
LevelPanic Level = "panic"
// Log Level [fatal].
LevelFatal Level = "fatal"
Copy link
Contributor

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?

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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

Copy link
Author

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


// WithLogLevel returns an [InstrumentationOption] that will configure
// an [Instrumentation] with the logger level visibility defined as inputed.
func WithLogLevel(level string) InstrumentationOption {
Copy link
Contributor

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.

Suggested change
func WithLogLevel(level string) InstrumentationOption {
func WithLogLevel(level Level) InstrumentationOption {

"fmt"
)

type Level string
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing comment.

Copy link
Author

Choose a reason for hiding this comment

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

Added comment

Comment on lines 26 to 38
// 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].
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

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

Added comments to levels

"fmt"
)

type Level string
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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.

Copy link
Author

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

@vitorhugoro1 vitorhugoro1 requested a review from MrAlias May 29, 2024 14:06
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.

Add log verbosity configuration and move the log in controller.go to debug level
6 participants