Skip to content

Conversation

srprash
Copy link
Contributor

@srprash srprash commented Sep 28, 2023

Issue #, if available: #388
The overridden get_trace_entity() method in lambda also checks the presence of segment in the thread local. This check is done to prevent context leakage across invocations. When the trace context is initialized upon lambda function invocation, the segment 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 the get_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 the segment when setting an entity by overriding the set_trace_entity() method in lambda context. This will ensure that the get_trace_entity() finds the segment 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.

@srprash srprash marked this pull request as ready for review September 28, 2023 16:29
@srprash srprash requested a review from a team as a code owner September 28, 2023 16:29
@srprash srprash changed the title set_trace_entity() in lambda adds segment to thread local BugFix: set_trace_entity() in lambda adds segment to thread local Sep 28, 2023
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.

3 participants