-
Notifications
You must be signed in to change notification settings - Fork 219
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
Python apm agent doesn't captured spans in aws lambda functions #1711
Comments
The The problem is, that we don't instrument We may be able to improve this -- you'll note in the comment that we're trying not to create multiple client instances. But now that we have For now, I think you would need to do something like this (untested): import sys
import json
import pymysql
import logging
from elasticapm import capture_serverless
rds_host = "******"
name = "admin"
password = "***"
db_name = "***"
port = 3306
logger = logging.getLogger()
logger.setLevel(logging.INFO)
conn = None
@capture_serverless()
def lambda_handler(event, context):
global conn
if not conn:
try:
conn = pymysql.connect(host=rds_host, user=name, passwd=password, db=db_name, connect_timeout=5)
except pymysql.MySQLError as e:
logger.error("ERROR: Unexpected error: Could not connect to MySql instance.")
logger.error(e)
sys.exit()
logger.info("SUCCESS: Connection to RDS mysql instance succeeded")
sql = "INSERT INTO `user` (`firstName`, `lastName`, `gender`, `birthday`,`email`, `phone`, `shippingAddress`, `billingAddress`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s)"
val = (event["firstName"], event["lastName"], event["gender"], event["birthday"], event["email"], event["phone"], event["shipping_address_id"], event["billing_address_id"])
with conn.cursor() as cur:
cur.execute(sql, val)
conn.commit()
return {
'statusCode': 200,
'body': json.dumps('Data has been inserted successfully')
} Even if we fixed the issue where we don't instrument until the function is called, you would still need to move your connection code below the |
Actually I just remembered why we can't move it out of the decorator: We allow config via the I will note, we're currently working on a no-code-changes instrumentation system, which will eventually include support for lambda. This will mean you will just add our lambda layer (which will include both the python agent and the extension) and environment variables and everything should just work. We don't have an ETA on that feature, but it should solve your use case much more cleanly. |
Hi, I added an elastic APM agent in my lambda function transaction are captured perfectly, I don't see any database calls in my dashboard
The text was updated successfully, but these errors were encountered: