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

Commit 502cd5d

Browse files
author
Mark Stumpf
authored
Merge pull request #25 from signalfx/FEED-2131
Add conditional check for a dimension related to tracing only
2 parents df575b1 + 8493172 commit 502cd5d

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
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: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,46 @@
33

44
from .version import name, version
55

6-
fields = {}
7-
86
def get_fields(context):
7+
fields = {}
98
function_arn = context.invoked_function_arn
109

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

4147

4248
def get_metrics_url():

0 commit comments

Comments
 (0)