1+ /*
2+ * Copyright 2025 The gRPC Authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package io .grpc .internal ;
18+
19+
20+ import io .grpc .Attributes ;
21+
22+ class OtelMetricsAttributes {
23+ final String target ;
24+ final String backendService ;
25+ final String locality ;
26+ final String disconnectError ;
27+ final String securityLevel ;
28+
29+ public OtelMetricsAttributes (String target , String backendService , String locality ,
30+ String disconnectError , String securityLevel ) {
31+ this .target = target ;
32+ this .backendService = backendService ;
33+ this .locality = locality ;
34+ this .disconnectError = disconnectError ;
35+ this .securityLevel = securityLevel ;
36+ }
37+
38+ public Attributes toOtelMetricsAttributes () {
39+ Attributes attributes =
40+ Attributes .EMPTY ;
41+
42+ if (target != null ) {
43+ attributes .toBuilder ()
44+ .set (Attributes .Key .create ("grpc.target" ), target )
45+ .build ();
46+ }
47+ if (backendService != null ) {
48+ attributes .toBuilder ()
49+ .set (Attributes .Key .create ("grpc.lb.backend_service" ), backendService )
50+ .build ();
51+ }
52+ if (locality != null ) {
53+ attributes .toBuilder ()
54+ .set (Attributes .Key .create ("grpc.lb.locality" ), locality )
55+ .build ();
56+ }
57+ if (disconnectError != null ) {
58+ attributes .toBuilder ()
59+ .set (Attributes .Key .create ("grpc.disconnect_error" ), disconnectError )
60+ .build ();
61+ }
62+ if (securityLevel != null ) {
63+ attributes .toBuilder ()
64+ .set (Attributes .Key .create ("grpc.security_level" ), securityLevel )
65+ .build ();
66+ }
67+ return attributes ;
68+ }
69+ }
0 commit comments