|
3 | 3 |
|
4 | 4 | from .version import name, version |
5 | 5 |
|
6 | | -fields = {} |
7 | | - |
8 | 6 | def get_fields(context): |
| 7 | + fields = {} |
9 | 8 | function_arn = context.invoked_function_arn |
10 | 9 |
|
| 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) |
11 | 40 | 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 | | - |
15 | 41 | 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 |
22 | 43 | }) |
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 |
40 | 46 |
|
41 | 47 |
|
42 | 48 | def get_metrics_url(): |
|
0 commit comments