Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for endpoint counts in profile uploads (#4840)
## Description Add support for uploading endpoint invocations counts along with profiles. <!-- Briefly describe the change and why it was required. --> <!-- If this is a breaking change, explain why it is necessary. Breaking changes must append `!` after the type/scope. See https://ddtrace.readthedocs.io/en/stable/contributing.html for more details. --> ## Checklist - [x] Followed the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) when writing a release note. - [x] Add additional sections for `feat` and `fix` pull requests. - [x] [Library documentation](https://github.com/DataDog/dd-trace-py/tree/1.x/docs) and/or [Datadog's documentation site](https://github.com/DataDog/documentation/) is updated. Link to doc PR in description. <!-- Copy and paste the relevant snippet based on the type of pull request --> <!-- START feat --> ## Motivation This is ti support mo in depth profile analysis. <!-- Expand on why the change is required, include relevant context for reviewers --> ## Design <!-- Include benefits from the change as well as possible drawbacks and trade-offs --> ## Testing strategy Use web-based service with profiling enabled. Normalization by endpoint counts should appear in the UI. <!-- Describe the automated tests and/or the steps for manual testing. <!-- END feat --> ## Reviewer Checklist - [x] Title is accurate. - [x] Description motivates each change. - [x] No unnecessary changes were introduced in this PR. - [x] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Tests provided or description of manual testing performed is included in the code or PR. - [x] Release note has been added and follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines), or else `changelog/no-changelog` label added. - [x] All relevant GitHub issues are correctly linked. - [x] Backports are identified and tagged with Mergifyio. Co-authored-by: Tahir H. Butt <tahir.butt@datadoghq.com> Co-authored-by: Munir Abdinur <munir.abdinur@datadoghq.com>
- Loading branch information
1 parent
99c89a9
commit 7a75af3
Showing
9 changed files
with
197 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import typing | ||
|
||
import attr | ||
|
||
from ddtrace.ext import SpanTypes | ||
from ddtrace.internal import forksafe | ||
from ddtrace.internal.compat import ensure_str | ||
from ddtrace.internal.processor import SpanProcessor | ||
from ddtrace.span import Span | ||
|
||
|
||
EndpointCountsType = typing.Dict[str, int] | ||
|
||
|
||
@attr.s(eq=False) | ||
class EndpointCallCounterProcessor(SpanProcessor): | ||
|
||
endpoint_counts = attr.ib(init=False, repr=False, type=EndpointCountsType, factory=lambda: {}, eq=False) | ||
_endpoint_counts_lock = attr.ib(init=False, repr=False, factory=forksafe.Lock, eq=False) | ||
_enabled = attr.ib(default=False, repr=False, eq=False) | ||
|
||
def enable(self): | ||
# type: () -> None | ||
self._enabled = True | ||
|
||
def on_span_start(self, span): | ||
# type: (Span) -> None | ||
pass | ||
|
||
def on_span_finish(self, span): | ||
# type: (Span) -> None | ||
if not self._enabled: | ||
return | ||
if span._local_root == span and span.span_type == SpanTypes.WEB: | ||
resource = ensure_str(span.resource, errors="backslashreplace") | ||
with self._endpoint_counts_lock: | ||
self.endpoint_counts[resource] = self.endpoint_counts.get(resource, 0) + 1 | ||
|
||
def reset(self): | ||
# type: () -> EndpointCountsType | ||
with self._endpoint_counts_lock: | ||
counts = self.endpoint_counts | ||
self.endpoint_counts = {} | ||
return counts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
features: | ||
- | | ||
profiling: Collects endpoint invocation counts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.