Skip to content

Commit 2de5650

Browse files
committed
Add service.
1 parent 2ac6b95 commit 2de5650

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

datadog_lambda/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def as_bool(val):
2727

2828
class Config:
2929

30+
service = _get_env("DD_SERVICE")
3031
add_span_pointers = _get_env("DD_BOTOCORE_ADD_SPAN_POINTERS", "true", as_bool)
3132
cold_start_tracing = _get_env("DD_COLD_START_TRACING", "true", as_bool)
3233
enhanced_metrics_enabled = _get_env("DD_ENHANCED_METRICS", "true", as_bool)

datadog_lambda/wrapper.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ def __init__(self, func):
155155
"""Executes when the wrapped function gets wrapped"""
156156
try:
157157
self.func = func
158-
self.service = os.environ.get(DD_SERVICE, None)
159158
self.extractor_env = os.environ.get(DD_TRACE_EXTRACTOR, None)
160159
self.trace_extractor = None
161160
self.span = None
@@ -194,7 +193,7 @@ def __init__(self, func):
194193
logger.debug(f"Malformatted for env {DD_COLD_START_TRACE_SKIP_LIB}")
195194
self.response = None
196195
if profiling_env_var:
197-
self.prof = profiler.Profiler(env=env_env_var, service=self.service)
196+
self.prof = profiler.Profiler(env=env_env_var, service=config.service)
198197
if self.extractor_env:
199198
extractor_parts = self.extractor_env.rsplit(".", 1)
200199
if len(extractor_parts) == 2:
@@ -359,8 +358,8 @@ def _after(self, event, context):
359358
if status_code:
360359
self.inferred_span.set_tag("http.status_code", status_code)
361360

362-
if self.service:
363-
self.inferred_span.set_tag("peer.service", self.service)
361+
if config.service:
362+
self.inferred_span.set_tag("peer.service", config.service)
364363

365364
if InferredSpanInfo.is_async(self.inferred_span) and self.span:
366365
self.inferred_span.finish(finish_time=self.span.start)

tests/test_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def set_env(key, value):
1515

1616

1717
_test_config_from_environ = (
18+
("DD_SERVICE", "service", None, None),
19+
("DD_SERVICE", "service", "", ""),
20+
("DD_SERVICE", "service", "my_service", "my_service"),
1821
("AWS_LAMBDA_FUNCTION_NAME", "function_name", None, "function"),
1922
("AWS_LAMBDA_FUNCTION_NAME", "function_name", "", ""),
2023
("AWS_LAMBDA_FUNCTION_NAME", "function_name", "my_function", "my_function"),

0 commit comments

Comments
 (0)