Skip to content

Commit e212f77

Browse files
committed
Add default lambda handler, for zero-code change instrumentation
1 parent 1c9f86c commit e212f77

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

datadog_lambda/handler.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from __future__ import absolute_import
2+
from importlib import import_module
3+
import os
4+
from datadog_lambda.wrapper import datadog_lambda_wrapper
5+
6+
7+
class HandlerError(Exception):
8+
pass
9+
10+
11+
path = os.environ.get("DATADOG_USER_HANDLER", None)
12+
if path is None:
13+
raise HandlerError(
14+
"DATADOG_USER_HANDLER is not defined. Can't use prebuilt datadog handler"
15+
)
16+
parts = path.rsplit(".", 1)
17+
if len(parts) != 2:
18+
raise HandlerError("Value %s for DATADOG_USER_HANDLER has invalid format." % path)
19+
20+
(mod_name, handler_name) = parts
21+
handler_module = import_module(mod_name)
22+
handler = datadog_lambda_wrapper(getattr(handler_module, handler_name))

0 commit comments

Comments
 (0)