Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: ability to remove 'environment' dimension from metrics #5368

Closed
2 tasks done
bml1g12 opened this issue Oct 11, 2024 · 4 comments
Closed
2 tasks done
Labels
feature-request feature request triage Pending triage from maintainers

Comments

@bml1g12
Copy link

bml1g12 commented Oct 11, 2024

Use case

This is a quite related to #3917

I've been using the https://github.com/aws-powertools/powertools-lambda-typescript/
I'm using "@aws-lambda-powertools/metrics": "^2.8.0" on the JS side, which is up to date at time of writing. I wanted to log from python to the same metric. That JS library does not by default add an 'environment' dimension (or at least if it does, I've removed it in the way I'm operating with it)

Whereas it seems in this library in Python there is always an 'environment' dimension even when explicitly calling clear_default_dimensions().

API_METRICS_SERVICE = Metrics(service="cci-call-panel-api")
API_METRICS_SERVICE.clear_default_dimensions()  # remove default "environment" dimension
API_METRICS_SERVICE.set_default_dimensions(
    aws_region=os.environ.get("REGION", "ap-northeast-1"),
    stage=os.environ.get("NODE_ENV", "unknown")
)

I should note I'm using a little old version of the library (aws-lambda-powertools==2.30.2) as it's not trivial for me to upgrade (would need to update a lot of repos using that layer) - so please feel free to close this issue if it's an issue already resolved.

Solution/User Experience

  • It would be good to document that environment is always added as a default dimension, and make behaviour consistent with the JS library.
  • clear_default_dimensions() should clear all dimensions

Alternative solutions

I can maybe edit my Javascript repo to add this dimension...but the problem is that I think cloudwatch metrics are fairly immutable, so I would lose historical data of that metric if I made a new metric with this dimension.

Acknowledgment

@leandrodamascena
Copy link
Contributor

Hi @bml1g12! Thanks for raising this issue. I'm trying to reproduce this error and I'm having trouble. Can you help me understand this issue a bit more?

I'm using this code

import os

from aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit
from aws_lambda_powertools.utilities.typing import LambdaContext

API_METRICS_SERVICE = Metrics(service="cci-call-panel-api", namespace="x")
API_METRICS_SERVICE.clear_default_dimensions()  # remove default "environment" dimension
API_METRICS_SERVICE.set_default_dimensions(
    aws_region=os.environ.get("REGION", "ap-northeast-1"),
    stage=os.environ.get("NODE_ENV", "unknown")
)


@API_METRICS_SERVICE.log_metrics  # ensures metrics are flushed upon request completion/failure
def lambda_handler(event: dict, context: LambdaContext):
    API_METRICS_SERVICE.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1)

And the output doesn't contain the environment dimension.

{"_aws":{"Timestamp":1728658422426,"CloudWatchMetrics":[{"Namespace":"x","Dimensions":[["aws_region","stage","service"]],"Metrics":[{"Name":"SuccessfulBooking","Unit":"Count"}]}]},"aws_region":"ap-northeast-1","stage":"unknown","service":"cci-call-panel-api","SuccessfulBooking":[1.0]}

Thanks.

@bml1g12
Copy link
Author

bml1g12 commented Oct 11, 2024

Oh dear, I'm terribly sorry, After seeing your post I realise this dimension is being added within some in-house middleware we're using to our handlers! So this issue can be closed

@bml1g12 bml1g12 closed this as completed Oct 11, 2024
@github-project-automation github-project-automation bot moved this from Triage to Coming soon in Powertools for AWS Lambda (Python) Oct 11, 2024
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@leandrodamascena
Copy link
Contributor

Oh dear, I'm terribly sorry, After seeing your post I realise this dimension is being added within some in-house middleware we're using to our handlers! So this issue can be closed

No problem at all! Ping us if you need any additional help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request triage Pending triage from maintainers
Projects
Status: Coming soon
Development

No branches or pull requests

2 participants