-
Notifications
You must be signed in to change notification settings - Fork 143
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
Exception thrown when Lambda is not initialized in begin_subsegment #129
Comments
sdk_config_module to global_sdk_config
sdk_config_module to global_sdk_config Added unit test to test non-initialized lambda context.
Renamed config module name to the global name (#129)
sdk_config_module to global_sdk_config Added unit test to test non-initialized lambda context.
@chanchiem running a flask application
/app.py
/docker-compose.yml
/Pipfile
response when I call my api locally
the full application is inside of docker. When I run any idea? |
Hey, this issue is different from the issue that you're experiencing. This issue is specific to an exception thrown as a result of the misnamed global configuration. It looks like the issue you're having could be happening due to two things:
Some follow up questions:
|
Hey, yes I'm running the API locally on my machine. It is occurring every time. Also not I am not running the docker inside lambda. If I push up my code, I can see the traces/segments working, just unable to test it locally. |
So are you running it locally through a tool like AWS SAM or your local machine? If completely local, it confuses me why you would see this log error because this only happens if your recorder is using the Lambda Context. Are you explicitly setting the context somewhere to use the Lambda Context?
|
no, I am not. It's completely local. If I follow the steps of Running the X-Ray Daemon in a Docker Container, the following occurs
It seems to just stay at can that be part of the issue? |
Hmm it shouldn't be the issue because the SDK doesn't actually get information back from the Daemon. It sends the trace information through UDP, so it's sort of send it and forget it. Can you try explicitly setting the context on your local build with a configuration that explicitly uses the default Context and report to me the results?
|
okay do I did this:
/app.py
this is returning
|
Okay cool, it looks like we found the root of the problem. It looks like when you are running it locally, your application is using the Lambda Context when it's not supposed to. I would investigate to see if any of your code modifies the recorder's Context property manually. This would make sense why it think the segment is still being initialized--because it never will actually finish. Now, you mention that you're using Flask as your web framework, but I don't see how you are invoking it. Please make sure to run X-Ray's middleware patcher on it for it to instrument requests: As for the following error:
This happens because your middleware isn't being instrumented. The capture annotation automatically generates subsegments whenever the method is called. You need to create a segment prior to calling that. Normally, the middleware would do this automatically. |
Perfect, I was missing the X-Ray middleware. Even though I'm now getting no error, I also see nothing happening... /init.py
/app.py
Im running the xray in a seprate docker.
Is there a way to see whats going on? I tried adding
I get
|
@chanchiem hey sorry, do you have any suggestions on this, I'm still stuck here. I don't see how my code is modifying the recorder's Context property manually. |
Are you running this in Lambda? Configuring the recorder to explicitly use Context() would only work if you are running it on your local build. I would recommend removing it if you are running it on Lambda, as it is not designed to work with it. Although this is probably not the root cause of your issue, but setting the sampling decision explicitly to False would ensure that traces won't be sent to the Daemon. If you set it to True, all traces will be sent to the Daemon. If you want to invoke the default sampling rules, not setting it would do that. I think the root of your problem is that the method isn't being invoked using the middleware. As you could see from your log, whenever the method attempts to begin a subsegment, there isn't a segment to store the subsegment in, and since your context_missing strategy is to log, it won't throw an exception and therefore also not generate a segment if an error occured. Usually, with a Middleware like Flask, the way to invoke the X-Ray middleware to instrument the segment, you would do something like:
Is this precisely what you are doing? If your form_submit() method call is not invoked by a the middleware, then what I would recommend doing is surrounding the call with a segment like below:
Also, I've noticed that you have submitted a forum post: My apologies for not responding to it sooner. I must have missed it. It would be much better if we can move this conversation to that forum post for the sake of public exposure so that others who may encounter this kind of issue may also benefit as opposed to seeing it on a closed Github issue. |
Great, I updated the question, thank you |
Update in case any one is having similar issues: Turns out that the middleware being used was Connexion, a web framework built on top of Flask. The Flask middleware patcher even for Connexion's underlying Flask App cannot be patched to work with X-Ray because it uses different mechanisms to handle the endpoint requests. We don't currently have support for this framework yet, but an issue has been opened up requesting for support. (#133) |
When Lambda is not initialized in begin_subsegment(), an exception is thrown because the global SDK config module was improperly named.
The text was updated successfully, but these errors were encountered: