-
Notifications
You must be signed in to change notification settings - Fork 11k
[OTel] Experimental API for metrics #35348
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
731649b
[OTel] Experimental API for metrics
yashykt f0464a9
Fix xds_interop_server
yashykt 2ad7487
Merge branch 'master' into OTelPublicApi
yashykt 62de366
Fix xds_interop_client
yashykt 9a1321e
Reviewer comments
yashykt e4324a7
Testing out static constexpr absl::string_view in header
yashykt e323288
Replace metric name functions with just string constants
yashykt 9286a63
Reviwer comments
yashykt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,108 @@ | ||
| // | ||
| // | ||
| // Copyright 2023 gRPC authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // | ||
|
|
||
| #ifndef GRPCPP_EXT_OTEL_PLUGIN_H | ||
| #define GRPCPP_EXT_OTEL_PLUGIN_H | ||
|
|
||
| #include <grpc/support/port_platform.h> | ||
|
|
||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "absl/functional/any_invocable.h" | ||
| #include "absl/strings/string_view.h" | ||
| #include "opentelemetry/metrics/meter_provider.h" | ||
|
|
||
| namespace grpc { | ||
|
|
||
| namespace internal { | ||
| class OpenTelemetryPluginBuilderImpl; | ||
| } // namespace internal | ||
|
|
||
| namespace experimental { | ||
|
|
||
| /// The most common way to use this API is - | ||
| /// | ||
| /// OpenTelemetryPluginBuilder().SetMeterProvider(provider).BuildAndRegister(); | ||
| /// | ||
| /// The set of instruments available are - | ||
| /// grpc.client.attempt.started | ||
| /// grpc.client.attempt.duration | ||
| /// grpc.client.attempt.sent_total_compressed_message_size | ||
| /// grpc.client.attempt.rcvd_total_compressed_message_size | ||
| /// grpc.server.call.started | ||
| /// grpc.server.call.duration | ||
| /// grpc.server.call.sent_total_compressed_message_size | ||
| /// grpc.server.call.rcvd_total_compressed_message_size | ||
|
||
| class OpenTelemetryPluginBuilder { | ||
| public: | ||
| /// Metrics | ||
| static constexpr absl::string_view kClientAttemptStartedInstrumentName = | ||
| "grpc.client.attempt.started"; | ||
| static constexpr absl::string_view kClientAttemptDurationInstrumentName = | ||
| "grpc.client.attempt.duration"; | ||
| static constexpr absl::string_view | ||
| kClientAttemptSentTotalCompressedMessageSizeInstrumentName = | ||
| "grpc.client.attempt.sent_total_compressed_message_size"; | ||
| static constexpr absl::string_view | ||
| kClientAttemptRcvdTotalCompressedMessageSizeInstrumentName = | ||
| "grpc.client.attempt.rcvd_total_compressed_message_size"; | ||
| static constexpr absl::string_view kServerCallStartedInstrumentName = | ||
| "grpc.server.call.started"; | ||
| static constexpr absl::string_view kServerCallDurationInstrumentName = | ||
| "grpc.server.call.duration"; | ||
| static constexpr absl::string_view | ||
| kServerCallSentTotalCompressedMessageSizeInstrumentName = | ||
| "grpc.server.call.sent_total_compressed_message_size"; | ||
| static constexpr absl::string_view | ||
| kServerCallRcvdTotalCompressedMessageSizeInstrumentName = | ||
| "grpc.server.call.rcvd_total_compressed_message_size"; | ||
|
|
||
| OpenTelemetryPluginBuilder(); | ||
| /// If `SetMeterProvider()` is not called, no metrics are collected. | ||
| OpenTelemetryPluginBuilder& SetMeterProvider( | ||
| std::shared_ptr<opentelemetry::metrics::MeterProvider> meter_provider); | ||
| /// If set, \a target_attribute_filter is called per channel to decide whether | ||
| /// to record the target attribute on client or to replace it with "other". | ||
| /// This helps reduce the cardinality on metrics in cases where many channels | ||
| /// are created with different targets in the same binary (which might happen | ||
| /// for example, if the channel target string uses IP addresses directly). | ||
| OpenTelemetryPluginBuilder& SetTargetAttributeFilter( | ||
| absl::AnyInvocable<bool(absl::string_view /*target*/) const> | ||
| target_attribute_filter); | ||
| /// If set, \a generic_method_attribute_filter is called per call with a | ||
| /// generic method type to decide whether to record the method name or to | ||
| /// replace it with "other". Non-generic or pre-registered methods remain | ||
| /// unaffected. If not set, by default, generic method names are replaced with | ||
| /// "other" when recording metrics. | ||
| OpenTelemetryPluginBuilder& SetGenericMethodAttributeFilter( | ||
| absl::AnyInvocable<bool(absl::string_view /*generic_method*/) const> | ||
| generic_method_attribute_filter); | ||
| /// Registers a global plugin that acts on all channels and servers running on | ||
| /// the process. | ||
| void BuildAndRegisterGlobal(); | ||
|
|
||
| private: | ||
| std::unique_ptr<internal::OpenTelemetryPluginBuilderImpl> impl_; | ||
| }; | ||
| } // namespace experimental | ||
| } // namespace grpc | ||
|
|
||
| #endif // GRPCPP_EXT_OTEL_PLUGIN_H | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that once we have the plugin option API in place, there will no longer be any need for having two different layers here (the private API wrapped inside of the public API)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think once the experimental
CsmObservabilityAPI goes away, we won't need to do this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we need the CSM plugin option implemented before we can remove the
CsmObservabilityAPI. And once we have the CSM plugin option implemented, theCsmObservabilitycode can use that plugin option in the public API, so it won't need to reach inside the internal API anymore. Or am I missing something here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. I wasn't originally planning on changing the implementation of
CsmObservabilityto use the plugin option, but I like that idea. I will be able to remove the internal API earlier. Will do that. Thanks!