AppDynamics switched from Semantic Versioning to Calendar Versioning starting in February 2020 for some agents and March 2020 for the entire product suite.


    Skip to end of metadata
    Go to start of metadata

    This page describes how to use the Python Serverless Tracer API to modify the behavior of the tracer within your AWS Lambda function.

    Create Exit Calls

    Exit calls are automatically instrumented for HTTP, Amazon DynamoDB, and inter-AWS Lambda calls. All other protocols need to manually create an exit call. 

    To create an exit call, use the ExitCallContextManager method in a with statement to wrap the exit call. The method takes the following required parameters:

    • exit_point_type: Type of the exit call
    • exit_point_sub_type: Subtype of the exit call

    • identifying_properties: Properties defining the exit call

    The ExitCallContextManager method automatically reports any runtime exceptions that occur within the method's scope as exit call errors.

    The code sample below demonstrates how to use the exit call method for a MySQL database:

    import appdynamics # Add AppDynamics libraries. Must be the first line of code
    
    @appdynamics.tracer
    def handler(event, context):
        with appdynamics.ExitCallContextManager(exit_point_type="DB", exit_point_sub_type="DB", identifying_properties={"VENDOR": "MYSQL"}) as ec:
            data = fetch_from_db()

    Exit Call Types and Identifying Properties

    In the Controller, each exit call has a distinct type, determined by a set of identifying properties. Include at least one identifying property for each exit call type. 

     The exitCall types, subtypes, and identifying properties are listed below. For exit call subtypes, you can use the examples listed in the table or use an empty string.  

    Exit Call Type

    Exit Call Subtype

    Identifying Properties

    HTTPHTTP

    HOST

    PORT

    URL

    QUERY STRING

    DB

    DB


    URL

    HOST

    PORT

    DATABASE

    VERSION

    VENDOR

    CACHE

    CACHE


    VENDOR

    SERVER POOL 

    CUSTOM

    Cassandra CQL

    Couchbase

    Amazon Web Services

    Mongo DB


    Any user-defined set of properties

    Create Exit Call Error Reports

    The ExitCallContextManager method automatically reports errors. If you want to add custom error reports, use the report_exit_call_error method. The method takes the following parameters:

    • error_name: Name of the error
    • error_message (Optional): Descriptive error message
    • http_status_code (Optional): The HTTP status code if available.

    The code sample below demonstrates how you can use the exit call error report method:

    import appdynamics 
    @appdynamics.tracer 
    def handler(event, context): 
    	#Create an exit call 
        with appdynamics.ExitCallContextManager("DB", "DB", {"HOST": "ec2-12-123-123-12.us-west-2.compute.amazonaws.com", "PORT": "3306", "DATABASE": "movies", "VENDOR": "MYSQL"}) as ec:
            movies = fetch_movies_from_mysql_db()
            if movies == None:
    			#Create an exit call error report 
                ec.report_exit_call_error(error_name="DBError", error_message="Item not found") #ec is the object returned by ExitCallContextManager above

    Create Transaction Error Reports

    By default, the Python Tracer automatically detects transaction error reports. You can customize these error reports using the appdynamics.report_error(error_name: str, error_message: str) method to report transaction errors. The method takes the following parameters:

    • error_name: Name of the error

    • error_message (Optional): Descriptive error message

    The code sample below demonstrates how you can use the transaction error report method:

    import appdynamics # Add AppDynamics libraries. Must be the first line of code
    import requests #Add request library 
    
    @appdynamics.tracer # Must come before the handler function
    def my_handler(event, context):
    	try:
            r = requests.get('https://api.github.com/events')
        except Exception as e:
            appdynamics.report_error(error_name=type(e).__name__, error_message=str(e)) # Reports a transaction error
    
    • No labels