Skip to content

fix(metrics): preserve default_tags when metric-specific tag is set in Datadog provider #2997

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

Merged
merged 3 commits into from
Aug 24, 2023
Merged

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #2990

Summary

Changes

In this PR, we address an issue where default_tags were not preserved when adding metric-specific tags in the Datadog. We've implemented a fix to ensure that default_tags will be merged with metric-specific tags. We also fixed the precedence problem when default tags and metric-specific tags shared the same key, and now the metric-specific tags took precedence.

I also added datadog-lambda dependency as optional. We mistakenly removed this in some reviews of the original PR.

User experience

CODE

from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics, DatadogProvider
from aws_lambda_powertools.utilities.typing import LambdaContext

provider = DatadogProvider(flush_to_log=True)
metrics = DatadogMetrics(provider=provider)
metrics.set_default_tags(product="ticket")


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

Output before this fix:

{
    "m": "SuccessfulBooking",
    "v": 1,
    "e": 1692736997,
    "t": [
        "flight:AB123",
    ]
}

Output after this fix:

{
    "m": "SuccessfulBooking",
    "v": 1,
    "e": 1692736997,
    "t": [
        "product:ticket"
        "flight:AB123",
    ]
}

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team August 24, 2023 13:13
@boring-cyborg boring-cyborg bot added dependencies Pull requests that update a dependency file metrics tests labels Aug 24, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 24, 2023
@github-actions github-actions bot added the bug Something isn't working label Aug 24, 2023
@leandrodamascena leandrodamascena linked an issue Aug 24, 2023 that may be closed by this pull request
1 task
Copy link
Contributor

@rubenfonseca rubenfonseca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stellar!

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@codecov-commenter
Copy link

codecov-commenter commented Aug 24, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (2a8be25) 96.56% compared to head (e8b3b8e) 96.56%.
Report is 7 commits behind head on develop.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2997   +/-   ##
========================================
  Coverage    96.56%   96.56%           
========================================
  Files          175      175           
  Lines         7825     7825           
  Branches      1476     1476           
========================================
  Hits          7556     7556           
  Misses         217      217           
  Partials        52       52           
Files Changed Coverage Δ
...bda_powertools/metrics/provider/datadog/datadog.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leandrodamascena leandrodamascena changed the title fix(metrics): preserve default_tags when metric-specific tag is set in Datadog fix(metrics): preserve default_tags when metric-specific tag is set in Datadog provider Aug 24, 2023
@leandrodamascena leandrodamascena merged commit a93ed25 into aws-powertools:develop Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file metrics size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: Mention that datadog metric tags replace default_tags
3 participants