Skip to content

Setup otel log handler and context#5510

Open
tung2744 wants to merge 10 commits intoauthgear:mainfrom
tung2744:dev-3341
Open

Setup otel log handler and context#5510
tung2744 wants to merge 10 commits intoauthgear:mainfrom
tung2744:dev-3341

Conversation

@tung2744
Copy link
Contributor

ref DEV-3341
ref DEV-3345

@sonarqubecloud
Copy link

// LogLevel sets the global log level
LogLevel string `envconfig:"LOG_LEVEL" default:"warn"`
// Log configures the logging
Log LogEnvironmentConfig `envconfig:"LOG"`
Copy link
Contributor

Choose a reason for hiding this comment

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

The logger read the environment variable separately. It seems nowhere is referencing it, should we remove it to avoid confusion.

https://github.com/authgear/authgear-server/pull/5510/changes#diff-d2d4e93d25fdb9af8e6156be6f568ca5e978bfc2214602658dc790eee0134f00R75

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to have a centralized place for all environment variables, therefore I still define it here, so we can know what environment variables exist by looking at just one package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finally I removed this field, because I found it difficult to ensure the LOG prefix is always used to load the config.
I also moved the struct to api package to solve import cycles.


shutdownFuncs = append(shutdownFuncs, traceProvider.Shutdown)

otlpEndpoint := os.Getenv("LOG_HANDLER_OTLP_ENDPOINT")
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 is defined in LogEnvironmentConfig, so it’s better to use it there to process it. Otherwise, it may cause problems if we need to update the name in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I put it here is because importing slogutil here will cause import cycle.
Maybe I should move the environment config struct to another independent package.

logcli query --addr="http://localhost:3102" \
'{service_name="authgear"} | app="YOUR_APP"' \
--since=1h \
-o jsonl -q
Copy link
Contributor

Choose a reason for hiding this comment

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

It works great :)

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