Skip to content

Commit d0f88d9

Browse files
Merge pull request #61 from DataDog/darcy.rayner/premade-handler-support
Add default lambda handler, for zero-code change instrumentation
2 parents 1c9f86c + 8c5a458 commit d0f88d9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

datadog_lambda/handler.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed
2+
# under the Apache License Version 2.0.
3+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
# Copyright 2020 Datadog, Inc.
5+
6+
from __future__ import absolute_import
7+
from importlib import import_module
8+
9+
import os
10+
from datadog_lambda.wrapper import datadog_lambda_wrapper
11+
12+
13+
class HandlerError(Exception):
14+
pass
15+
16+
17+
path = os.environ.get("DD_LAMBDA_HANDLER", None)
18+
if path is None:
19+
raise HandlerError(
20+
"DD_LAMBDA_HANDLER is not defined. Can't use prebuilt datadog handler"
21+
)
22+
parts = path.rsplit(".", 1)
23+
if len(parts) != 2:
24+
raise HandlerError("Value %s for DD_LAMBDA_HANDLER has invalid format." % path)
25+
26+
(mod_name, handler_name) = parts
27+
handler_module = import_module(mod_name)
28+
handler = datadog_lambda_wrapper(getattr(handler_module, handler_name))

0 commit comments

Comments
 (0)