Skip to content

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

Merged
leandrodamascena merged 3 commits into
aws-powertools:developfrom
leandrodamascena:datadog/fix-tags
Aug 24, 2023
Merged

fix(metrics): preserve default_tags when metric-specific tag is set in Datadog provider#2997
leandrodamascena merged 3 commits into
aws-powertools:developfrom
leandrodamascena:datadog/fix-tags

Conversation

@leandrodamascena

Copy link
Copy Markdown
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

@rubenfonseca rubenfonseca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stellar!

@sonarqubecloud

Copy link
Copy Markdown

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

codecov-commenter commented Aug 24, 2023

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.56%. Comparing base (2a8be25) to head (e8b3b8e).
⚠️ Report is 3036 commits behind head on develop.

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           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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