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

feat(tracer): Support for external observability providers - Tracer #2342

Closed
wants to merge 46 commits into from

Conversation

roger-zhangg
Copy link
Member

Issue number:
2030

Summary

Support provider in tracer

Changes

Modify the provider with more genreral tracer feature, provide a new x-ray provider.

User experience

This change doesn't affect users who just use default x-ray provider.
This change allows users to bring their own tracer provider to use other solution provider other than X-ray

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.

@boring-cyborg boring-cyborg bot added the tracer Tracer utility label May 30, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 30, 2023
@roger-zhangg roger-zhangg changed the title (feature draft) Support for external observability providers - Tracer feat(Tracer) Support for external observability providers - Tracer May 30, 2023
@roger-zhangg roger-zhangg changed the title feat(Tracer) Support for external observability providers - Tracer feat(tracer): Support for external observability providers - Tracer May 30, 2023
@github-actions github-actions bot added the feature New feature or functionality label May 30, 2023
@roger-zhangg
Copy link
Member Author

Drafted the first PR for tracer provider.

  • Provided a more general Tracer Provider interface.
  • Drafted a x-ray provider
    I wasn't included in the initial discussions in this projects so I might have missed something.

Questions:

  • Decide how to refactor BaseSegment Class
  • Check on current x-ray provider's design.(Doesn't support add_span, end_span)
  • In the RFC there's a capture_method function included in the provider. But currently this function is in Tracer class. Do we need to move it into our provider?

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2024

Codecov Report

Attention: Patch coverage is 75.22936% with 27 lines in your changes missing coverage. Please review.

Project coverage is 95.71%. Comparing base (e14e768) to head (7efe7e4).
Report is 806 commits behind head on develop.

Files Patch % Lines
...da_powertools/tracing/provider/xray/xray_tracer.py 69.23% 17 Missing and 3 partials ⚠️
aws_lambda_powertools/tracing/tracer.py 69.56% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2342      +/-   ##
===========================================
- Coverage    96.38%   95.71%   -0.67%     
===========================================
  Files          214      218       +4     
  Lines        10030    10488     +458     
  Branches      1846     1945      +99     
===========================================
+ Hits          9667    10039     +372     
- Misses         259      332      +73     
- Partials       104      117      +13     

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

@boring-cyborg boring-cyborg bot added the dependencies Pull requests that update a dependency file label Feb 6, 2024
@boring-cyborg boring-cyborg bot added the tests label Mar 19, 2024
@roger-zhangg roger-zhangg marked this pull request as ready for review March 20, 2024 00:15
@roger-zhangg roger-zhangg requested a review from a team as a code owner March 20, 2024 00:15
@roger-zhangg
Copy link
Member Author

@rubenfonseca Thanks for the super detailed feedback. I've resolved all the comments now. Please help with a final review, thanks.

@rubenfonseca rubenfonseca self-requested a review April 17, 2024 09:43
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.

Super good progress! Just left some tiny picks and some questions on breaking changes. @leandrodamascena can you help implement the changes so we commit quickly?

@@ -11,7 +11,7 @@ def collect_payment(charge_id: str) -> str:
@tracer.capture_lambda_handler
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
with tracer.provider.in_subsegment("## collect_payment") as subsegment:
with tracer.provider.in_subsegment("## collect_payment") as subsegment: # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

We should review this to make sure we don't have a typing breaking change

@@ -177,6 +178,36 @@ def __init__(
if self._is_xray_provider():
self._disable_xray_trace_batching()

def set_attribute(self, key: str, value: Any, **kwargs):
"""Set attribute on current active span with a key-value pair.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""Set attribute on current active span with a key-value pair.
"""Set an attribute on current active span with a key-value pair.


Parameters
----------
key : str
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
key : str
key: str

----------
key : str
attribute key
value : Any
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
value : Any
value: Any


Example
-------
Set attribute for a pseudo service named payment
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Set attribute for a pseudo service named payment
Set an attribute for a pseudo service named payment

**kwargs,
) -> None:
"""
Set attribute on the current active span with a key-value pair.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Set attribute on the current active span with a key-value pair.
Set an attribute on the current active span with a key-value pair.


Parameters
----------
key : str
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
key : str
key: str

----------
key : str
attribute key
value : Any
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
value : Any
value: Any

attribute key
value : Any
Value for attribute
category : Literal["Annotation","Metadata","Auto"] = "Auto"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
category : Literal["Annotation","Metadata","Auto"] = "Auto"
category: Literal["Annotation","Metadata","Auto"] = "Auto"

class BaseSegment(abc.ABC):
"""Holds common properties and methods on segment and subsegment."""

@abc.abstractmethod
def close(self, end_time: Optional[int] = None):
def close(self, end_time: Optional[float] = None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a breaking change? Or are we assuming that no one is inheriting from BaseSegment today?

Copy link
Contributor

Choose a reason for hiding this comment

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

We will deprecate this in Powertools v3. We're not using this class today, but we never know if customers are, so it's best to revert this change.

Reverted.

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
8.6% Duplication on New Code

See analysis details on SonarCloud

@leandrodamascena
Copy link
Contributor

We can consider this PR completed, but we will not merge it now. We'll start conversations about Powertools V3 and add this refactor when we're ready for it:

1 - We will deprecate the BaseSegment in Powertools v3.
2 - This is a potential breaking change for customers who are accessing the XRay methods directly.
3 - We can take this opportunity to standardize method names like trace instead of subsegment in our documentation and ease for customers adopt new Observability providers.

I'm approving this PR and changing it to Draft state just so I don't mess up our stats.

@leandrodamascena leandrodamascena marked this pull request as draft April 17, 2024 16:40
@leandrodamascena leandrodamascena self-requested a review April 17, 2024 16:40
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

Thanks for another stellar job @roger-zhangg! This refactor will open the opportunity to expand the Tracer utility and add more observability providers.

I left a comment explaining why we are approving but not merging this PR right now:
#2342 (comment)

@leandrodamascena
Copy link
Contributor

Hi @roger-zhangg! I'm closing this PR in favor of #4902! It was really hard to fix the entire merge conflict here, so I've created a new one.

Thank you for all the effort you've put in here, and I'll give you credit for this work when I release v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file feature New feature or functionality on-hold This item is on-hold and will be revisited in the future size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests tracer Tracer utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants