-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Issue with passing trace_entity when using ThreadPoolExecutor in lambda #342
Comments
Hey there! I had some follow up questions:
Can you explain this more please? Do you mean that when you follow our documentation on using ThreadPoolExecutor the call to
Hm this is curious. Can you please add screenshots of what you're seeing? Especially before and after screenshots and an explanation of what you expect to see versus what you actually see? When our documentation says
Which changes are missing to make it compatible with the other changes? Just curious in case you already know. Also please feel free to open a PR to add a fix if you have one and we'll be happy to answer!
That's awesome that you have a workaround! Is there a chance you missed the Perhaps your segment isn't already available when your The best way to help you would be to have you share your code so we can see when the trace that Please let me know if you have any questions! |
I can try and get a sample together in the next week or so but it should be doable with what is posted in the readme . In the console the first segments recorded by a thread in the pool show up under the invoke of the lambda not the segment from the trace entity if it should be redording under another subsegment. It looks like the issue coming from here. It seems like the |
Thanks for your deep dive!
Why does it work on subsequent calls then? Is it because This is where a picture of what you see versus what you expect would be useful to clarify, but I think this is what you mean and would explain why it works on the 2nd time onward.
So are you saying we could fix the issue by overriding the def set_trace_entity(self, trace_entity):
"""
Refresh the context before setting the trace entity so
that the correct parent is set.
"""
self._refresh_context()
super.set_trace_entity(trace_entity) That case would make sense to me, and we could move to a PR for this? By the way, we are also recommending users to use the OpenTelemetry Python SDK. It has tons of features and I found an example with ThreadPoolExecutor to ensure spans are parented correctly. You'll find lots of support there and AWS announced GA support for its traces 1 year ago. |
We are using this library becasue it is what AWS lambda powertools is using under the covers. The only spot we are directly using this library is to make things work properly in the threadpool. |
I followed the instructions in the readme for passing the trace entity in a ThreadPoolExecutor but this does not appear to work properly in a lambda. The first time a thread does some work the trace_entity does not stick and the subsegment gets put under the root node not the one it should be assiciated with. The next time a thread picks up a job everything seems to operate fine.
I dug into the code a bit and it seems like there is a custome context class for lambdas but it does not override
set_trace_entity
to work properly with the other changes in the class. To workaround the issue I have found callingget_trace_entity
before setting sets the internal state up properly.example workaround from readme
The text was updated successfully, but these errors were encountered: