By kprichard
I get no activation records or log messages when I run serverless functions via doctl. I have a working python 3.11 serverless function that does what I expect, except that logging doesn’t appear anywhere, and there are no activation records-
$ doctl serverless activations list hello-world/mainy
Datetime Status Kind Version Activation ID Start Wait Duration Function
(no records, just headers)
$ doctl serverless activations list
Datetime Status Kind Version Activation ID Start Wait Duration Function
(no records, just headers)
$ doctl serverless activations logs -f hello-world/mainy
(no output)
$ doctl serverless activations logs
(no output)
I’ve run the function successfully a handful of times, and still nothing. Is there a latency period for logs to appear? I started yesterday, still seeing nothing today.
Here is the function def-
import json
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def main(args):
try:
logger.warning("Starting hello-world function")
logger.warning(str(args))
logger.info("This is an info log")
logger.debug("This is a debug log")
name = args.get("name", "")
if not name:
name = "world"
retval = {
"statusCode": 200,
"headers": {
'Content-Type': 'text/html',
},
"body": f"""<html><body>Hello, {name}<br><br><pre>
Type: "{type(args)}"
Class: "{args.__class__.__name__}"
{json.dumps(args, indent=4, sort_keys=True)}</pre></body></html>""",
}
logger.warning(f"Returning: {retval}")
logger.error(f"Returning: {json.dumps(retval)}")
return retval
except Exception as e:
logger.exception(e)
return {"error": str(e)}
project.yml:
packages:
- name: hello-world
functions:
- name: mainy
parameters:
runtime: "python:3.11"
web: true
limits:
timeout: 10000 # 10 seconds
memory: 512
DM me for URL / function UUID.
Regarding third-party logging / log forwarding, I’d rather not use or pay for external logging while I’m just trying out Functions, you know what I mean? I’m want to get something working, to learn whether DO Functions meets my needs. If it looks production-worthy and I continue development, then I’ll sign up for external logging.
At this point, I’m having to embed log type info into my response object, which isn’t ideal but it’s getting me by for now.
Also fyi-
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
If you’re calling the function via its public web: true
URL, that might be why you’re not seeing any activation records or logs, I think that those only show up when you invoke the function using doctl
.
Also, sometimes the logging
module doesn’t behave as expected in these lightweight runtimes. I’ve got logs working with log forwarding, but if you don’t want to try those aout, not 100% sure if there’s another issue here, so it might be worth reaching out to support for a closer look: https://do.co/support
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.