BugFix: set_trace_entity() in lambda adds segment to thread local #409
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available: #388
The overridden
get_trace_entity()
method in lambda also checks the presence ofsegment
in the thread local. This check is done to prevent context leakage across invocations. When the trace context is initialized upon lambda function invocation, thesegment
is placed in the main thread's local. But if a child thread is spawned, the thread local state is not inherited, which is expected due to thread local design for isolation. Due to this whenever theget_trace_entity()
is called (which would be every time a subsegment is to be created), the thread local is reset causing unexpected parenting of subsegments as mentioned in the above issue.Description of changes:
Since we are checking for
segment
when getting the trace entity, we must also set thesegment
when setting an entity by overriding theset_trace_entity()
method in lambda context. This will ensure that theget_trace_entity()
finds thesegment
in the thread local and won't reset the context.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.