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: implement context handler to store HTTP request and tracing information #752

Merged
merged 12 commits into from Nov 23, 2021

Conversation

minherz
Copy link
Contributor

@minherz minherz commented Nov 18, 2021

Implement support for setting current context to capture Http request and tracing information of the current context.
It provides per-thread context handling and supports enter/exit scope to avoid re-setting the context multiple time in event of re-entering the scope.
The context supports setting trace and span ids directly and parsing the ids from X-CLOUD-TRACE and traceparent Http header values.

Fixes #750

removing warnings related to serialVersionUID and unused objects
provide context abstraction to instantiate a context with info about
HttpRequest and tracing (trace id and span id).
provide handler that is able to store context per-thread to support
Web servers that handle each request in a dedicated thread.
provide support for ServletContainerInititializer by introducing
request context scope that can be "entered" and "leaved".
the empty instance of HttpRequest is used as a reference for empty object.
refactor Context constructor to set null instead of empty HttpRequest.
update traceparent context load method name and comments.
fix string comparison bug in traceparent context load method.
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 18, 2021
@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/java-logging API. label Nov 18, 2021
@minherz minherz changed the title Minherz/feat 687 feat: implement context handler to store HTTP request and tracing information Nov 18, 2021
@minherz minherz marked this pull request as ready for review November 18, 2021 10:14
@minherz minherz requested review from a team as code owners November 18, 2021 10:14
@minherz
Copy link
Contributor Author

minherz commented Nov 18, 2021

Note that PR also includes pulled env-tests-logging submodule.

@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 18, 2021
@yoshi-kokoro yoshi-kokoro removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Nov 18, 2021
Copy link
Contributor

@losalex losalex left a comment

Choose a reason for hiding this comment

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

Good job! Lets just touch base about some issues I mentioned in PR

@minherz minherz requested a review from losalex November 19, 2021 14:55
minherz and others added 7 commits November 19, 2021 15:04
replace String.length() > 0 with !String.isEmpty().
strict W3C trace parent format validation
RequestContextScope is removed to avoid ambiguous use
move Context and ContextHolder to the root library package.
initialize ContextHolder to InheritableThreadLocal if configuration property is provided.
Add support for additional configuration property into LoggingConfig.
Copy link
Contributor

@losalex losalex left a comment

Choose a reason for hiding this comment

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

Overall looks good.
The only thing I wondered if we can turn ContextHandler to be a template class to hold any context and config class name could be transferred as parameter to initContextHolder() - let me know WDYT

}
}

public Context getCurrentContext() {
Copy link
Contributor

@losalex losalex Nov 23, 2021

Choose a reason for hiding this comment

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

I wonder if we should make it generic by turning this into template to be reused with other objects (not only Context). Seems that TraceLoggingEnhancer below also used ThreadLocal and might benefit from it as well

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 think we should focus on supporting "our" context since this is what this feature is designed to be. Providing template means we include a generic-purpose implementation into logging library code.
If there will be a need for additional information for the context, the Context class can be extended to include additional data fields.

@minherz minherz merged commit 86223ff into main Nov 23, 2021
@minherz minherz deleted the minherz/feat-687 branch November 23, 2021 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/java-logging API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

structured logging: Implement request context holder
4 participants