Skip to content

Commit a392d47

Browse files
authored
Lambda error log fix (#334)
* added logging of the lambda error including the traceback * fix for sqlalchemy, context can be None, we should avoid firing an exception
1 parent daeffd9 commit a392d47

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

instana/instrumentation/aws/lambda_inst.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ... import get_lambda_handler_or_default
1313
from ...singletons import get_agent, get_tracer
1414
from .triggers import enrich_lambda_span, get_context
15+
import traceback
1516

1617

1718
def lambda_handler_with_instana(wrapped, instance, args, kwargs):
@@ -36,6 +37,7 @@ def lambda_handler_with_instana(wrapped, instance, args, kwargs):
3637
result['multiValueHeaders']['Server-Timing'] = [server_timing_value]
3738
except Exception as exc:
3839
if scope.span:
40+
exc = traceback.format_exc()
3941
scope.span.log_exception(exc)
4042
raise
4143
finally:

instana/instrumentation/sqlalchemy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def receive_before_cursor_execute(**kw):
2828

2929
scope = active_tracer.start_active_span("sqlalchemy", child_of=active_tracer.active_span)
3030
context = kw['context']
31-
context._stan_scope = scope
31+
if context:
32+
context._stan_scope = scope
3233

3334
conn = kw['conn']
3435
url = str(conn.engine.url)

instana/span.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def log_exception(self, exc):
6464
try:
6565
message = ""
6666
self.mark_as_errored()
67-
6867
if hasattr(exc, '__str__') and len(str(exc)) > 0:
6968
message = str(exc)
7069
elif hasattr(exc, 'message') and exc.message is not None:
@@ -84,6 +83,8 @@ def log_exception(self, exc):
8483
self.set_tag('error', message)
8584
elif self.operation_name == "sqlalchemy":
8685
self.set_tag('sqlalchemy.err', message)
86+
elif self.operation_name == "aws.lambda.entry":
87+
self.set_tag('lambda.error', message)
8788
else:
8889
self.log_kv({'message': message})
8990
except Exception:
@@ -295,7 +296,7 @@ def _populate_entry_span_data(self, span):
295296
self.data["lambda"]["functionName"] = span.tags.pop('lambda.name', "Unknown")
296297
self.data["lambda"]["functionVersion"] = span.tags.pop('lambda.version', "Unknown")
297298
self.data["lambda"]["trigger"] = span.tags.pop('lambda.trigger', None)
298-
self.data["lambda"]["error"] = None
299+
self.data["lambda"]["error"] = span.tags.pop('lambda.error', None)
299300

300301
trigger_type = self.data["lambda"]["trigger"]
301302

instana/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
# Module version file. Used by setup.py and snapshot reporting.
55

6-
VERSION = '1.35.1'
6+
VERSION = '1.35.2'

0 commit comments

Comments
 (0)