Skip to content

Commit b4f8eba

Browse files
committed
Namespace (g)RPC SpanAttributeNames
1 parent ab12067 commit b4f8eba

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

Sources/OpenTelemetryInstrumentationSupport/SpanAttribute+GRPCSemantics.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ import TracingInstrumentation
1515

1616
extension SpanAttributeName {
1717
/// - See: GRPCAttributes
18-
public static let gRPCMessageType = "message.type"
19-
/// - See: GRPCAttributes
20-
public static let gRPCMessageID = "message.id"
21-
/// - See: GRPCAttributes
22-
public static let gRPCMessageCompressedSize = "message.compressed_size"
23-
/// - See: GRPCAttributes
24-
public static let gRPCMessageUncompressedSize = "message.uncompressed_size"
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+
}
2528
}
2629

2730
#if swift(>=5.2)
@@ -52,19 +55,19 @@ public struct GRPCAttributes: SpanAttributeNamespace {
5255
public init() {}
5356

5457
/// The type of message, e.g. "SENT" or "RECEIVED".
55-
public var messageType: SpanAttributeKey<String> { .init(name: SpanAttributeName.gRPCMessageType) }
58+
public var messageType: SpanAttributeKey<String> { .init(name: SpanAttributeName.GRPC.messageType) }
5659

5760
/// The message id calculated as two different counters starting from 1, one for sent messages and one for received messages.
58-
public var messageID: SpanAttributeKey<Int> { .init(name: SpanAttributeName.gRPCMessageID) }
61+
public var messageID: SpanAttributeKey<Int> { .init(name: SpanAttributeName.GRPC.messageID) }
5962

6063
/// The compressed message size in bytes.
6164
public var messageCompressedSize: SpanAttributeKey<Int> {
62-
.init(name: SpanAttributeName.gRPCMessageCompressedSize)
65+
.init(name: SpanAttributeName.GRPC.messageCompressedSize)
6366
}
6467

6568
/// The uncompressed message size in bytes.
6669
public var messageUncompressedSize: SpanAttributeKey<Int> {
67-
.init(name: SpanAttributeName.gRPCMessageUncompressedSize)
70+
.init(name: SpanAttributeName.GRPC.messageUncompressedSize)
6871
}
6972
}
7073
}

Sources/OpenTelemetryInstrumentationSupport/SpanAttribute+RPCSemantics.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ import TracingInstrumentation
1515

1616
extension SpanAttributeName {
1717
/// - See: RPCAttributes
18-
public static let rpcSystem = "rpc.system"
19-
/// - See: RPCAttributes
20-
public static let rpcService = "rpc.service"
21-
/// - See: RPCAttributes
22-
public static let rpcMethod = "rpc.method"
18+
public enum RPC {
19+
/// - See: RPCAttributes
20+
public static let system = "rpc.system"
21+
/// - See: RPCAttributes
22+
public static let service = "rpc.service"
23+
/// - See: RPCAttributes
24+
public static let method = "rpc.method"
25+
}
2326
}
2427

2528
#if swift(>=5.2)
@@ -50,13 +53,13 @@ public struct RPCAttributes: SpanAttributeNamespace {
5053
public init() {}
5154

5255
/// A string identifying the remoting system, e.g., "grpc", "java_rmi" or "wcf".
53-
public var system: SpanAttributeKey<String> { .init(name: SpanAttributeName.rpcSystem) }
56+
public var system: SpanAttributeKey<String> { .init(name: SpanAttributeName.RPC.system) }
5457

5558
/// The full name of the service being called, including its package name, if applicable.
56-
public var service: SpanAttributeKey<String> { .init(name: SpanAttributeName.rpcService) }
59+
public var service: SpanAttributeKey<String> { .init(name: SpanAttributeName.RPC.service) }
5760

5861
/// The name of the method being called, must be equal to the $method part in the span name.
59-
public var method: SpanAttributeKey<String> { .init(name: SpanAttributeName.rpcMethod) }
62+
public var method: SpanAttributeKey<String> { .init(name: SpanAttributeName.RPC.method) }
6063
}
6164
}
6265
#endif

0 commit comments

Comments
 (0)