-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
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.
Note that PR also includes pulled env-tests-logging submodule. |
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.
Good job! Lets just touch base about some issues I mentioned in PR
google-cloud-logging/src/main/java/com/google/cloud/logging/context/Context.java
Outdated
Show resolved
Hide resolved
google-cloud-logging/src/main/java/com/google/cloud/logging/context/Context.java
Outdated
Show resolved
Hide resolved
google-cloud-logging/src/main/java/com/google/cloud/logging/context/Context.java
Outdated
Show resolved
Hide resolved
google-cloud-logging/src/main/java/com/google/cloud/logging/context/Context.java
Outdated
Show resolved
Hide resolved
google-cloud-logging/src/main/java/com/google/cloud/logging/context/Context.java
Outdated
Show resolved
Hide resolved
google-cloud-logging/src/main/java/com/google/cloud/logging/context/Context.java
Outdated
Show resolved
Hide resolved
google-cloud-logging/src/main/java/com/google/cloud/logging/context/RequestContextScope.java
Outdated
Show resolved
Hide resolved
google-cloud-logging/src/main/java/com/google/cloud/logging/context/ContextHandler.java
Outdated
Show resolved
Hide resolved
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.
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.
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
google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingConfig.java
Show resolved
Hide resolved
google-cloud-logging/src/main/java/com/google/cloud/logging/TraceLoggingEnhancer.java
Show resolved
Hide resolved
} | ||
} | ||
|
||
public Context getCurrentContext() { |
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 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
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 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.
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
andtraceparent
Http header values.Fixes #750