Coverage Report

Created: 2025-09-04 06:32

/src/grpc-swift/Sources/GRPC/Logger.swift
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2019, gRPC Authors All rights reserved.
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
import Logging
17
import NIOCore
18
19
/// Keys for `Logger` metadata.
20
enum MetadataKey {
21
  static let requestID = "grpc_request_id"
22
  static let connectionID = "grpc_connection_id"
23
24
  static let eventLoop = "event_loop"
25
26
  static let h2StreamID = "h2_stream_id"
27
  static let h2ActiveStreams = "h2_active_streams"
28
  static let h2EndStream = "h2_end_stream"
29
  static let h2Payload = "h2_payload"
30
  static let h2Headers = "h2_headers"
31
  static let h2DataBytes = "h2_data_bytes"
32
  static let h2GoAwayError = "h2_goaway_error"
33
  static let h2GoAwayLastStreamID = "h2_goaway_last_stream_id"
34
  static let h2PingAck = "h2_ping_ack"
35
36
  static let delayMs = "delay_ms"
37
  static let intervalMs = "interval_ms"
38
39
  static let error = "error"
40
}
41
42
extension Logger {
43
0
  internal mutating func addIPAddressMetadata(local: SocketAddress?, remote: SocketAddress?) {
44
0
    if let local = local?.ipAddress {
45
0
      self[metadataKey: "grpc.conn.addr_local"] = "\(local)"
46
0
    }
47
0
    if let remote = remote?.ipAddress {
48
0
      self[metadataKey: "grpc.conn.addr_remote"] = "\(remote)"
49
0
    }
50
0
  }
51
}