Skip to content

[Instrumentation.AWS] Add AWS metrics instrumentation#1980

Merged
cijothomas merged 9 commits intoopen-telemetry:mainfrom
muhammad-othman:aws-metrics-instrumentation
Aug 12, 2024
Merged

[Instrumentation.AWS] Add AWS metrics instrumentation#1980
cijothomas merged 9 commits intoopen-telemetry:mainfrom
muhammad-othman:aws-metrics-instrumentation

Conversation

@muhammad-othman
Copy link
Copy Markdown
Member

Changes

  • Integration of New Metrics APIs:
    Implemented the new AWS SDK tracing APIs, starting with AWSMeterProvider.

  • Added Instrumentation Method:
    Introduced MeterProviderBuilderExtensions.AddAWSInstrumentation to enable metrics instrumentation.

  • SDK Version Update:
    Updated the SDK version to 3.7.400 to incorporate the new tracing APIs.
    This update conflicts with the changes in PR #1974. The last merged PR will rebase accordingly.

Merge requirement checklist

  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes

@muhammad-othman muhammad-othman requested a review from a team July 26, 2024 22:44
@github-actions github-actions bot requested review from ppittle and srprash July 26, 2024 22:44
@github-actions github-actions bot added the comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS label Jul 26, 2024
@normj
Copy link
Copy Markdown
Contributor

normj commented Aug 1, 2024

Getting metrics added for the AWS SDK looks really cool in the Aspire Dashboard.

image

@vishweshbankwar
Copy link
Copy Markdown
Member

@muhammad-othman - Could you please take a look at failing tests?


namespace OpenTelemetry.Instrumentation.AWS.Implementation.Metrics;

internal class AWSHistogram<T> : Histogram<T>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what is the need of these wrappers over existing Histogram and others? Metrics API are designed to support high performance, allocation-free scenarios, and this wrappers is negating some of the perf optimizations... Wondering if this is really needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We needed these wrappers to allow the AWS SDK to call these methods directly, and unfortunately the AWS SDK cannot take on new dependencies, and we supported .NET Standard and .NET Core 3.1, which lack System.Diagnostics.DiagnosticSource that is available in newer versions.

{
if (attributes != null)
{
this.histogram.Record(value, attributes.AllAttributes.ToArray());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The array allocation of heap is not desirable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

unfortunately I couldn't avoid that with the current APIs, Histogram.Record accepts params as an array, and the API that the AWS SDK exposes uses IEnumerable since the attributes can be mutable in other places, maybe at some point Histogram.Record may accepts params as an IEnumerable which would be more flexible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Histogram.Record has many overloads to accepts attributes(Tags) without forcing allocation.
https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/metrics#metrics-api

It is unfortunate that the AWS wrapper is forcing heap allocation for metrics in hot path.

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.

@muhammad-othman When we move the SDK's observability changes into the V4 development branch we can add an AttributesAsSpan property and use it here to remove the allocation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will create a v4 task for this, also this isn't the only place that we use .ToArray() so it should be useful to use it in other places including the tracing changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you add a TODO comment here that future aws sdk will offer api's to avoid allocation.?

Copy link
Copy Markdown
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Glad to see more metrics instrumentation.
I am concerned about the heap allocated in the hot path, see #1980 (comment)
but given the owners have approved, will proceed to merge.

@cijothomas
Copy link
Copy Markdown
Member

@srprash Could you review?

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 5, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 90.45%. Comparing base (71655ce) to head (4b0c59f).
Report is 379 commits behind head on main.

Files Patch % Lines
...ntation.AWS/Implementation/Metrics/AWSHistogram.cs 71.42% 2 Missing ⚠️
....AWS/Implementation/Metrics/AWSMonotonicCounter.cs 71.42% 2 Missing ⚠️
...ion.AWS/Implementation/Metrics/AWSUpDownCounter.cs 85.71% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1980       +/-   ##
===========================================
+ Coverage   73.91%   90.45%   +16.54%     
===========================================
  Files         267       18      -249     
  Lines        9615      241     -9374     
===========================================
- Hits         7107      218     -6889     
+ Misses       2508       23     -2485     
Flag Coverage Δ
unittests-Instrumentation.AWS 90.45% <87.50%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...rumentation.AWS/Implementation/Metrics/AWSMeter.cs 100.00% <100.00%> (ø)
...ion.AWS/Implementation/Metrics/AWSMeterProvider.cs 100.00% <100.00%> (ø)
...trumentation.AWS/MeterProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...ion.AWS/Implementation/Metrics/AWSUpDownCounter.cs 85.71% <85.71%> (ø)
...ntation.AWS/Implementation/Metrics/AWSHistogram.cs 71.42% <71.42%> (ø)
....AWS/Implementation/Metrics/AWSMonotonicCounter.cs 71.42% <71.42%> (ø)

... and 268 files with indirect coverage changes

@muhammad-othman muhammad-othman force-pushed the aws-metrics-instrumentation branch from 094b661 to 16fb984 Compare August 6, 2024 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants