1 // 2 // 3 // Copyright 2024 gRPC authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // 17 // 18 19 #ifndef GRPC_PYTHON_OBSERVABILITY_METADATA_EXCHANGE_H 20 #define GRPC_PYTHON_OBSERVABILITY_METADATA_EXCHANGE_H 21 22 #include <stddef.h> 23 #include <stdint.h> 24 25 #include <bitset> 26 #include <memory> 27 #include <string> 28 #include <utility> 29 30 #include "absl/strings/string_view.h" 31 #include "constants.h" 32 #include "python_observability_context.h" 33 #include "src/core/lib/transport/metadata_batch.h" 34 35 namespace grpc_observability { 36 37 class PythonLabelsInjector { 38 public: 39 explicit PythonLabelsInjector(const std::vector<Label>& exchange_labels); 40 41 // Read the incoming initial metadata to get the set of labels exchanged from 42 // peer. 43 std::vector<Label> GetExchangeLabels( 44 grpc_metadata_batch* incoming_initial_metadata) const; 45 46 // Add metadata_to_exchange_ to the outgoing initial metadata. 47 void AddExchangeLabelsToMetadata( 48 grpc_metadata_batch* outgoing_initial_metadata) const; 49 50 // Add optional xds labels from optional_labels_span to labels. 51 void AddXdsOptionalLabels( 52 bool is_client, 53 absl::Span<const grpc_core::RefCountedStringValue> optional_labels_span, 54 std::vector<Label>& labels); 55 56 private: 57 std::vector<std::pair<std::string, std::string>> metadata_to_exchange_; 58 }; 59 60 } // namespace grpc_observability 61 62 #endif // GRPC_PYTHON_OBSERVABILITY_CONSTANTS_H 63