Skip to content

Commit 349a5d5

Browse files
committed
sync with develop
2 parents 8416d25 + 17de07e commit 349a5d5

File tree

33 files changed

+968
-55
lines changed

33 files changed

+968
-55
lines changed

.github/ISSUE_TEMPLATE/feature_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ body:
3838
options:
3939
- label: This feature request meets [Lambda Powertools Tenets](https://awslabs.github.io/aws-lambda-powertools-dotnet/tenets)
4040
required: true
41-
- label: Should this be considered in other Lambda Powertools languages? i.e. [Java](https://github.com/awslabs/aws-lambda-powertools-java/), [TypeScript](https://github.com/awslabs/aws-lambda-powertools-typescript/)
41+
- label: Should this be considered in other Lambda Powertools languages? i.e. [Python](https://github.com/awslabs/aws-lambda-powertools-python), [Java](https://github.com/awslabs/aws-lambda-powertools-java/), and [TypeScript](https://github.com/awslabs/aws-lambda-powertools-typescript/)
4242
required: false
4343
- type: markdown
4444
attributes:

.github/ISSUE_TEMPLATE/maintenance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ body:
6060
attributes:
6161
label: Acknowledgment
6262
options:
63-
- label: This request meets [Lambda Powertools Tenets](https://awslabs.github.io/aws-lambda-powertools-python/latest/#tenets)
63+
- label: This request meets [Lambda Powertools Tenets](https://awslabs.github.io/aws-lambda-powertools-dotnet/latest/#tenets)
6464
required: true
6565
- type: markdown
6666
attributes:

.github/ISSUE_TEMPLATE/rfc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ body:
8181
options:
8282
- label: This feature request meets [Lambda Powertools Tenets](https://awslabs.github.io/aws-lambda-powertools-dotnet/tenets/)
8383
required: true
84-
- label: Should this be considered in other Lambda Powertools languages? i.e. [Python](https://github.com/awslabs/aws-lambda-powertools-python), [Java](https://github.com/awslabs/aws-lambda-powertools-java/), [TypeScript](https://github.com/awslabs/aws-lambda-powertools-typescript/)
84+
- label: Should this be considered in other Lambda Powertools languages? i.e. [Python](https://github.com/awslabs/aws-lambda-powertools-python), [Java](https://github.com/awslabs/aws-lambda-powertools-java/), and [TypeScript](https://github.com/awslabs/aws-lambda-powertools-typescript/)
8585
required: false
8686
- type: markdown
8787
attributes:
@@ -94,4 +94,4 @@ body:
9494
9595
* RFC PR:
9696
* Approved by: ''
97-
* Reviewed by: ''
97+
* Reviewed by: ''
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Dispatch analytics
2+
3+
on:
4+
workflow_dispatch:
5+
6+
schedule:
7+
- cron: '0 * * * *'
8+
9+
permissions:
10+
id-token: write
11+
actions: read
12+
checks: read
13+
contents: read
14+
deployments: read
15+
issues: read
16+
discussions: read
17+
packages: read
18+
pages: read
19+
pull-requests: read
20+
repository-projects: read
21+
security-events: read
22+
statuses: read
23+
24+
jobs:
25+
dispatch_token:
26+
if: github.repository == 'awslabs/aws-lambda-powertools-dotnet'
27+
concurrency:
28+
group: analytics
29+
runs-on: ubuntu-latest
30+
environment: analytics
31+
steps:
32+
- name: Configure AWS credentials
33+
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef
34+
with:
35+
aws-region: eu-central-1
36+
role-to-assume: ${{ secrets.AWS_ANALYTICS_ROLE_ARN }}
37+
38+
- name: Invoke Lambda function
39+
run: |
40+
payload=$(echo -n '{"githubToken": "${{ secrets.GITHUB_TOKEN }}"}' | base64)
41+
aws lambda invoke \
42+
--function-name ${{ secrets.AWS_ANALYTICS_DISPATCHER_ARN }} \
43+
--payload "$payload" response.json
44+
cat response.json

docs/core/metrics.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,26 @@ These metrics can be visualized through [Amazon CloudWatch Console](https://aws.
1010
## Key features
1111

1212
* Aggregate up to 100 metrics using a single CloudWatch EMF object (large JSON blob)
13-
* Validate against common metric definitions mistakes (metric unit, values, max dimensions, max metrics, etc)
14-
* Metrics are created asynchronously by CloudWatch service, no custom stacks needed
13+
* Validating your metrics against common metric definitions mistakes (for example, metric unit, values, max dimensions, max metrics)
14+
* Metrics are created asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency
1515
* Context manager to create a one off metric with a different dimension
1616

17+
<br />
18+
19+
<figure>
20+
<img src="../../media/metrics_utility_showcase.png" loading="lazy" alt="Screenshot of the Amazon CloudWatch Console showing an example of business metrics in the Metrics Explorer" />
21+
<figcaption>Metrics showcase - Metrics Explorer</figcaption>
22+
</figure>
23+
1724
## Terminologies
1825

1926
If you're new to Amazon CloudWatch, there are two terminologies you must be aware of before using this utility:
2027

21-
* **Namespace**. It's the highest level container that will group multiple metrics from multiple services for a given application, for example `MyCompanyEcommerce`.
28+
* **Namespace**. It's the highest level container that will group multiple metrics from multiple services for a given application, for example `ServerlessEcommerce`.
2229
* **Dimensions**. Metrics metadata in key-value format. They help you slice and dice metrics visualization, for example `ColdStart` metric by Payment `service`.
30+
* **Metric**. It's the name of the metric, for example: SuccessfulBooking or UpdatedBooking.
31+
* **Unit**. It's a value representing the unit of measure for the corresponding metric, for example: Count or Seconds.
32+
* **Resolution**. It's a value representing the storage resolution for the corresponding metric. Metrics can be either Standard or High resolution. Read more [here](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Resolution_definition).
2333

2434
Visit the AWS documentation for a complete explanation for [Amazon CloudWatch concepts](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html).
2535

@@ -130,6 +140,38 @@ You can create metrics using **`AddMetric`**, and you can create dimensions for
130140
!!! warning "Do not create metrics or dimensions outside the handler"
131141
Metrics or dimensions added in the global scope will only be added during cold start. Disregard if that's the intended behavior.
132142

143+
### Adding high-resolution metrics
144+
145+
You can create [high-resolution metrics](https://aws.amazon.com/about-aws/whats-new/2023/02/amazon-cloudwatch-high-resolution-metric-extraction-structured-logs/) passing `MetricResolution` as parameter to `AddMetric`.
146+
147+
!!! tip "When is it useful?"
148+
High-resolution metrics are data with a granularity of one second and are very useful in several situations such as telemetry, time series, real-time incident management, and others.
149+
150+
=== "Metrics with high resolution"
151+
152+
```csharp hl_lines="9 12 15"
153+
using AWS.Lambda.Powertools.Metrics;
154+
155+
public class Function {
156+
157+
[Metrics(Namespace = "ExampleApplication", Service = "Booking")]
158+
public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
159+
{
160+
// Publish a metric with standard resolution i.e. StorageResolution = 60
161+
Metrics.AddMetric("SuccessfulBooking", 1, MetricUnit.Count, MetricResolution.Standard);
162+
163+
// Publish a metric with high resolution i.e. StorageResolution = 1
164+
Metrics.AddMetric("FailedBooking", 1, MetricUnit.Count, MetricResolution.High);
165+
166+
// The last parameter (storage resolution) is optional
167+
Metrics.AddMetric("SuccessfulUpgrade", 1, MetricUnit.Count);
168+
}
169+
}
170+
```
171+
172+
!!! tip "Autocomplete Metric Resolutions"
173+
Use the `MetricResolution` enum to easily find a supported metric resolution by CloudWatch.
174+
133175
### Adding default dimensions
134176

135177
You can use **`SetDefaultDimensions`** method to persist dimensions across Lambda invocations.
165 KB
Loading

examples/Logging/src/HelloWorld/HelloWorld.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.5.0" />
1010
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
11-
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.0.1" />
11+
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.1.0" />
1212
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.101.14" />
1313
</ItemGroup>
14-
</Project>
14+
</Project>

examples/Metrics/src/HelloWorld/HelloWorld.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.5.0" />
1010
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
11-
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.0.1" />
12-
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.0.1" />
11+
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.1.0" />
12+
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.2.0" />
1313
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.101.14" />
1414
</ItemGroup>
15-
</Project>
15+
</Project>

examples/Tracing/src/HelloWorld/HelloWorld.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.5.0" />
1010
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
11-
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.0.1" />
12-
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.0.1" />
11+
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.1.0" />
12+
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.1.0" />
1313
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.101.14" />
1414
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.11.0" />
1515
</ItemGroup>
16-
</Project>
16+
</Project>

libraries/src/AWS.Lambda.Powertools.Common/Core/Constants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,14 @@ internal static class Constants
8080
/// Constant for LAMBDA_TASK_ROOT environment variable
8181
/// </summary>
8282
internal const string LambdaTaskRoot = "LAMBDA_TASK_ROOT";
83+
84+
/// <summary>
85+
/// Constant for AWS_EXECUTION_ENV environment variable
86+
/// </summary>
87+
internal const string AwsExecutionEnvironmentVariableName = "AWS_EXECUTION_ENV";
88+
89+
/// <summary>
90+
/// Constant for Powertools feature identifier fo AWS_EXECUTION_ENV environment variable
91+
/// </summary>
92+
internal const string FeatureContextIdentifier = "PT";
8393
}

0 commit comments

Comments
 (0)