Skip to content

Commit c3e589f

Browse files
committed
Add RPC semantic attributes
1 parent d57e613 commit c3e589f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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: 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"
23+
}
24+
25+
#if swift(>=5.2)
26+
extension SpanAttributes {
27+
/// Semantic conventions for RPC spans.
28+
public var rpc: RPCAttributes {
29+
get {
30+
.init(attributes: self)
31+
}
32+
set {
33+
self = newValue.attributes
34+
}
35+
}
36+
}
37+
38+
/// Semantic conventions for RPC spans as defined in the OpenTelemetry spec.
39+
///
40+
/// - SeeAlso: [OpenTelemetry: Semantic conventions for RPC spans](https://github.com/open-telemetry/opentelemetry-specification/blob/b70565d5a8a13d26c91fb692879dc874d22c3ac8/specification/trace/semantic_conventions/rpc.md) (as of August 2020)
41+
@dynamicMemberLookup
42+
public struct RPCAttributes: SpanAttributeNamespace {
43+
public var attributes: SpanAttributes
44+
45+
public init(attributes: SpanAttributes) {
46+
self.attributes = attributes
47+
}
48+
49+
public struct NestedAttributes: NestedSpanAttributesProtocol {
50+
public init() {}
51+
52+
/// A string identifying the remoting system, e.g., "grpc", "java_rmi" or "wcf".
53+
public var system: SpanAttributeKey<String> { .init(name: SpanAttributeName.rpcSystem) }
54+
55+
/// The full name of the service being called, including its package name, if applicable.
56+
public var service: SpanAttributeKey<String> { .init(name: SpanAttributeName.rpcService) }
57+
58+
/// 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) }
60+
}
61+
}
62+
#endif

0 commit comments

Comments
 (0)