Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 22fe624

Browse files
author
Mark Stumpf
committed
Add conditional check for a dimension related to tracing only
1 parent df575b1 commit 22fe624

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

README.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ to SignalFx:
132132
+----------------------------------+----------------------------------+
133133
| Dimension | Description |
134134
+==================================+==================================+
135-
| aws_request_id | AWS Request ID |
136-
+----------------------------------+----------------------------------+
137135
| lambda_arn | ARN of the Lambda function |
138136
| | instance |
139137
+----------------------------------+----------------------------------+

signalfx_lambda/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def call(*args, **kwargs):
1313

1414
tracer = init_jaeger_tracer(context)
1515

16-
span_tags = utils.get_fields(context)
16+
span_tags = utils.get_tracing_fields(context)
1717
span_tags['component'] = 'python-lambda-wrapper'
1818
span_tags[ext_tags.SPAN_KIND] = ext_tags.SPAN_KIND_RPC_SERVER
1919

signalfx_lambda/utils.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,42 @@
88
def get_fields(context):
99
function_arn = context.invoked_function_arn
1010

11-
if fields.get('aws_request_id') != context.aws_request_id:
12-
# Expected format arn:aws:lambda:us-east-1:accountId:function:functionName:$LATEST
13-
splitted = function_arn.split(':')
11+
# Expected format arn:aws:lambda:us-east-1:accountId:function:functionName:$LATEST
12+
splitted = function_arn.split(':')
13+
14+
fields.update({
15+
'aws_function_version': context.function_version,
16+
'aws_function_name': context.function_name,
17+
'aws_region': splitted[3],
18+
'aws_account_id': splitted[4],
19+
'function_wrapper_version': name + '_' + version
20+
})
21+
22+
runtime_env = os.environ.get('AWS_EXECUTION_ENV')
23+
if runtime_env is not None:
24+
fields['aws_execution_env'] = runtime_env
25+
if splitted[5] == 'function':
26+
updatedArn = list(splitted)
27+
if len(splitted) == 8:
28+
fields['aws_function_qualifier'] = splitted[7]
29+
updatedArn[7] = context.function_version
30+
elif len(splitted) == 7:
31+
updatedArn.append(context.function_version)
32+
fields['lambda_arn'] = ':'.join(updatedArn)
33+
34+
elif splitted[5] == 'event-source-mappings':
35+
fields['event_source_mappings'] = splitted[6]
36+
fields['lambda_arn'] = function_arn
37+
38+
return fields.copy()
1439

40+
def get_tracing_fields():
41+
if fields.get('aws_request_id') != context.aws_request_id:
1542
fields.update({
16-
'aws_request_id': context.aws_request_id,
17-
'aws_function_version': context.function_version,
18-
'aws_function_name': context.function_name,
19-
'aws_region': splitted[3],
20-
'aws_account_id': splitted[4],
21-
'function_wrapper_version': name + '_' + version
43+
'aws_request_id': context.aws_request_id
2244
})
23-
runtime_env = os.environ.get('AWS_EXECUTION_ENV')
24-
if runtime_env is not None:
25-
fields['aws_execution_env'] = runtime_env
26-
if splitted[5] == 'function':
27-
updatedArn = list(splitted)
28-
if len(splitted) == 8:
29-
fields['aws_function_qualifier'] = splitted[7]
30-
updatedArn[7] = context.function_version
31-
elif len(splitted) == 7:
32-
updatedArn.append(context.function_version)
33-
fields['lambda_arn'] = ':'.join(updatedArn)
34-
35-
elif splitted[5] == 'event-source-mappings':
36-
fields['event_source_mappings'] = splitted[6]
37-
fields['lambda_arn'] = function_arn
3845

39-
return fields.copy()
46+
return get_fields()
4047

4148

4249
def get_metrics_url():

0 commit comments

Comments
 (0)