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

Add interceptor for collecting client metrics #4021

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

landonxjames
Copy link
Contributor

Motivation and Context

Description

Testing

Checklist

  • For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "client," "server," or both in the applies_to key.
  • For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "aws-sdk-rust" in the applies_to key.

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

Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Remove use of SystemTime.elapsed(), fix private type in pub docs, and
style updates
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Contributor

@aajtodd aajtodd left a comment

Choose a reason for hiding this comment

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

Good start but I have some correctness/approach concerns.

Also unrelated to metrics, (and this can be a follow on PR) we probably want to try to align some of our spans with the SRA as well before we ship all this.

e.g. the root operation span for all smithy services should include attributes rpc.service and rpc.method (AWS SDK services would also set rpc.system to aws-api which would need to happen in codegen)

default_sleep_impl_plugin(),
default_time_source_plugin(),
default_timeout_config_plugin(),
enforce_content_length_runtime_plugin(),
default_stalled_stream_protection_config_plugin_v2(behavior_version),
metrics_runtime_plugin(
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't going to quite work the way we want.

The OperationBuilder isn't used in generated code and we apply default plugins when we create the client (see also here).

At that point we won't have the operation name.

We also want to be very careful to create the instruments and have them live on the client (i.e. we don't want them created per/operation, the attributes (dimensions) recorded with the metric will differentiate operations/services/etc). Default runtime plugins sort of gets us there (though you have to understand it's used differently by codegen than it is say by the runtime (e.g. IMDS cred provider in aws-config).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this bit to codegen in d7a3c3a, but leaving this chunk here for the manually created credentials clients.

Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Add dynamic metrics scope via codegen
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link

github-actions bot commented Mar 1, 2025

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link

github-actions bot commented Mar 5, 2025

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link

github-actions bot commented Mar 5, 2025

A new generated diff is ready to view.

A new doc preview is ready to view.

@landonxjames landonxjames marked this pull request as ready for review March 5, 2025 20:38
@landonxjames landonxjames requested a review from a team as a code owner March 5, 2025 20:38
Copy link
Contributor

@ysaito1001 ysaito1001 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 the change!

Semver failure on UnwindSafe is indeed puzzling 🤔
The check seems to have been introduced almost 2.5 years ago, even before the previous version of the cargo semver version we used.

@@ -201,6 +203,12 @@ impl<I, O, E> OperationBuilder<I, O, E> {
self
}

/// Configures the metrics scope for the builder.
pub fn scope(mut self, scope: &'static str) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to double check, since this is a pub API, are we sure that scope always takes &'static str but not something like Cow<'static, str>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not love the &'static str type here, but I don't think we have another option. The type is motivated by the type on ProvideMeter.get_meter() method which takes an &'static str. That was in turn motivated by the OpenTelemetry MeterProvider.meter method which also takes &'static str. So we are kind of stuck with &'static str all the way since it can't be constructed at runtime.

Copy link

github-actions bot commented Mar 6, 2025

A new generated diff is ready to view.

A new doc preview is ready to view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants