powertools-lambda-dotnet icon indicating copy to clipboard operation
powertools-lambda-dotnet copied to clipboard

Feature request: Add support for default dimensions on ColdStart metric

Open hjgraca opened this issue 1 year ago • 0 comments

Use case

Related to https://github.com/aws-powertools/powertools-lambda-python/issues/5237

Add anew DefaultDimensions property to Metrics decorator to allow it to set Default Dimentsions on coldstart. This new property will set global default dimensions not just for the cold start The existing SetDefaultDimensions Metrics static method will still work. If same key added it will replace that key on Metrics called after the method was called

Solution/User Experience

using AWS.Lambda.Powertools.Metrics;

public class Function {
  private Dictionary<string, string> _defaultDimensions = new Dictionary<string, string>{
        {"Environment", "Prod"},
        {"Another", "One"}
    }; 

  [Metrics(Namespace = "ExampleApplication", Service = "Booking", DefaultDimensions = _defaultDimensions)]
  public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
  {
   // SetDefaultDimensions still available and will override existing properties in later calls to Metrics 
    Metrics.SetDefaultDimensions(_defaultDimensions);
    Metrics.AddMetric("SuccessfulBooking", 1, MetricUnit.Count);
  }
}

Alternative solutions

No response

Acknowledgment

hjgraca avatar Sep 27 '24 09:09 hjgraca