|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift Distributed Tracing open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Moritz Lang and the Swift Tracing project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// |
| 10 | +// SPDX-License-Identifier: Apache-2.0 |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +import TracingInstrumentation |
| 15 | + |
| 16 | +extension SpanAttributeName { |
| 17 | + /// - See: GRPCAttributes |
| 18 | + public enum GRPC { |
| 19 | + /// - See: GRPCAttributes |
| 20 | + public static let messageType = "message.type" |
| 21 | + /// - See: GRPCAttributes |
| 22 | + public static let messageID = "message.id" |
| 23 | + /// - See: GRPCAttributes |
| 24 | + public static let messageCompressedSize = "message.compressed_size" |
| 25 | + /// - See: GRPCAttributes |
| 26 | + public static let messageUncompressedSize = "message.uncompressed_size" |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +#if swift(>=5.2) |
| 31 | +extension SpanAttributes { |
| 32 | + /// Semantic conventions for gRPC spans. |
| 33 | + public var gRPC: GRPCAttributes { |
| 34 | + get { |
| 35 | + .init(attributes: self) |
| 36 | + } |
| 37 | + set { |
| 38 | + self = newValue.attributes |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +/// Semantic conventions for gRPC spans as defined in the OpenTelemetry spec. |
| 44 | +/// |
| 45 | +/// - SeeAlso: [OpenTelemetry: Semantic conventions for gRPC spans](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/rpc.md#grpc) (as of August 2020) |
| 46 | +@dynamicMemberLookup |
| 47 | +public struct GRPCAttributes: SpanAttributeNamespace { |
| 48 | + public var attributes: SpanAttributes |
| 49 | + |
| 50 | + public init(attributes: SpanAttributes) { |
| 51 | + self.attributes = attributes |
| 52 | + } |
| 53 | + |
| 54 | + public struct NestedAttributes: NestedSpanAttributesProtocol { |
| 55 | + public init() {} |
| 56 | + |
| 57 | + /// The type of message, e.g. "SENT" or "RECEIVED". |
| 58 | + public var messageType: SpanAttributeKey<String> { .init(name: SpanAttributeName.GRPC.messageType) } |
| 59 | + |
| 60 | + /// The message id calculated as two different counters starting from 1, one for sent messages and one for received messages. |
| 61 | + public var messageID: SpanAttributeKey<Int> { .init(name: SpanAttributeName.GRPC.messageID) } |
| 62 | + |
| 63 | + /// The compressed message size in bytes. |
| 64 | + public var messageCompressedSize: SpanAttributeKey<Int> { |
| 65 | + .init(name: SpanAttributeName.GRPC.messageCompressedSize) |
| 66 | + } |
| 67 | + |
| 68 | + /// The uncompressed message size in bytes. |
| 69 | + public var messageUncompressedSize: SpanAttributeKey<Int> { |
| 70 | + .init(name: SpanAttributeName.GRPC.messageUncompressedSize) |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | +#endif |
0 commit comments