Skip to content

Commit 947a36a

Browse files
committed
updated network status attributes to match the semconv
1 parent 2f06851 commit 947a36a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Sources/Instrumentation/NetworkStatus/NetworkStatusInjector.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import CoreTelephony
99
import Foundation
1010
import Network
1111
import OpenTelemetryApi
12+
import OpenTelemetrySdk
13+
1214
public class NetworkStatusInjector {
1315
private var netstat: NetworkStatus
1416

@@ -18,27 +20,27 @@ public class NetworkStatusInjector {
1820

1921
public func inject(span: Span) {
2022
let (type, subtype, carrier) = netstat.status()
21-
span.setAttribute(key: "net.host.connection.type", value: AttributeValue.string(type))
23+
span.setAttribute(key: SemanticAttributes.networkConnectionType.rawValue, value: AttributeValue.string(type))
2224

2325
if let subtype: String = subtype {
24-
span.setAttribute(key: "net.host.connection.subtype", value: AttributeValue.string(subtype))
26+
span.setAttribute(key: SemanticAttributes.networkConnectionSubtype.rawValue, value: AttributeValue.string(subtype))
2527
}
2628

2729
if let carrierInfo: CTCarrier = carrier {
2830
if let carrierName = carrierInfo.carrierName {
29-
span.setAttribute(key: "net.host.carrier.name", value: AttributeValue.string(carrierName))
31+
span.setAttribute(key: SemanticAttributes.networkCarrierName.rawValue, value: AttributeValue.string(carrierName))
3032
}
3133

3234
if let isoCountryCode = carrierInfo.isoCountryCode {
33-
span.setAttribute(key: "net.host.carrier.icc", value: AttributeValue.string(isoCountryCode))
35+
span.setAttribute(key: SemanticAttributes.networkCarrierIcc.rawValue, value: AttributeValue.string(isoCountryCode))
3436
}
3537

3638
if let mobileCountryCode = carrierInfo.mobileCountryCode {
37-
span.setAttribute(key: "net.host.carrier.mcc", value: AttributeValue.string(mobileCountryCode))
39+
span.setAttribute(key: SemanticAttributes.networkCarrierMcc.rawValue, value: AttributeValue.string(mobileCountryCode))
3840
}
3941

4042
if let mobileNetworkCode = carrierInfo.mobileNetworkCode {
41-
span.setAttribute(key: "net.host.carrier.mnc", value: AttributeValue.string(mobileNetworkCode))
43+
span.setAttribute(key: SemanticAttributes.networkCarrierMnc.rawValue, value: AttributeValue.string(mobileNetworkCode))
4244
}
4345
}
4446
}

0 commit comments

Comments
 (0)