Code Monkey home page Code Monkey logo

Comments (12)

haotianw465 avatar haotianw465 commented on July 18, 2024 3

The long term solution is to have the middleware directly add all http metadata to the root segment generated by Lambda worker. The SDK currently doesn't have access to this segment right now and we don't have an ETA yet.

The workaround is to have middleware to only generate subsegments when running on Lambda. This causes a problem in the service graph. The color of the Lambda function node in the service graph is decided by status code in lambda segments. And this status code only indicates if the lambda function runs or not. It doesn't respect the actual status code returned by your web application running within that lambda function. If you have correct IAM role setup and no syntax error on your application code, most likely you will always see an all green service graph node despite a lot of 4xx returned by your web app.

This workaround makes it difficult to discover issues and we cannot call this workaround "support for serverless". But we are open to here any suggestions. If such workaround is acceptable we can make it an opt-in so that at least FacadeSegmentMutationException is avoided.

from aws-xray-sdk-python.

Sniedes722 avatar Sniedes722 commented on July 18, 2024 2

patching the libraries seemed to solve this issue for me, also using lambda, flask, & zappa.

from aws_xray_sdk.core import xray_recorder, patch_all
from aws_xray_sdk.core.context import Context
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware

patch_all()

and then this was how i wrapped it inside the flask application:

xray_recorder.configure(service='Your Service Name', sampling=False, context=Context())
XRayMiddleware(app, xray_recorder)

from aws-xray-sdk-python.

chanchiem avatar chanchiem commented on July 18, 2024 1

Good news! Serverless support has been merged into the master branch!
#127

from aws-xray-sdk-python.

haotianw465 avatar haotianw465 commented on July 18, 2024

Hi, which serverless framework are you using?

from aws-xray-sdk-python.

datar-ai avatar datar-ai commented on July 18, 2024

I use zappa , and python flask framework.

from aws-xray-sdk-python.

Sniedes722 avatar Sniedes722 commented on July 18, 2024

also enabled in zappa config checkout: https://github.com/Miserlou/Zappa#aws-x-ray

from aws-xray-sdk-python.

iandees avatar iandees commented on July 18, 2024

For others running into this issue, @Sniedes722's combination of patching and enabling x-ray in Zappa worked for me. I'm not sure why, but it didn't work until I added the sampling=False, context=Context() stuff.

from aws-xray-sdk-python.

Sniedes722 avatar Sniedes722 commented on July 18, 2024

@iandees I can also confirm that @haotianw465 is completely correct about getting green OK status codes in x-ray when the API is returning 400 statuses with this workaround

from aws-xray-sdk-python.

xplorld avatar xplorld commented on July 18, 2024

@haotianw465 What are the consequences if we use our own Context() instead of using SDK-provided Lambda context?

from aws-xray-sdk-python.

haotianw465 avatar haotianw465 commented on July 18, 2024

@xplorld the recorder class intentionally exposes an API to allow users to configure their own context management https://github.com/aws/aws-xray-sdk-python/blob/master/aws_xray_sdk/core/recorder.py#L75.

You can have your own implementation of the context() used in Lambda container which creates another type of facadesegment which can be modified freely and replicate everything it has to a child subsegment.

Please let me know if you need any help on implementing a customized context management that specifically fits your use case.

from aws-xray-sdk-python.

haotianw465 avatar haotianw465 commented on July 18, 2024

Hi all, API Gateway with active X-Ray integration is launched. You can see more details here: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-xray.html.

Feel free to leave any feedback on the new customer experience and we are happy to discuss a workaround based on those new feedback. We will also be working with Lambda team based on those new feedback to better improve the overall experience. Thank you for your patience.

from aws-xray-sdk-python.

 avatar commented on July 18, 2024

I see the a dangling subsegment even when calling configure before patching third party libraries.

from`aws_xray_sdk.core import xray_recorder, patch_all
from aws_xray_sdk.core.context import Context
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware

app = connexion.App(__name__, specification_dir='./swagger/')
app.app.json_encoder = encoder.JSONEncoder
app.add_api('swagger.yaml', arguments={'title': 'Swagger Petstore'})

xray_recorder.configure(service=' python-flask-se-development', sampling=False, context=Context())
XRayMiddleware(app.app, xray_recorder)

patch_all()

from aws-xray-sdk-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.