Skip to content

Commit b6dba77

Browse files
vvydierbryce-b
andauthored
updated InstrumentationLibrary to InstrumentationScope (#336)
* changed InstrumentationLibrary to InstrumentationScope as per OTLP spec update * Added comment for specifying otel-collector version Co-authored-by: Bryce Buchanan <[email protected]>
1 parent d7cf512 commit b6dba77

File tree

53 files changed

+1202
-671
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1202
-671
lines changed

.github/workflows/BuildAndTest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ jobs:
1515
run: |
1616
curl -Os https://uploader.codecov.io/latest/macos/codecov
1717
chmod +x codecov
18-
xcrun llvm-cov export -format="lcov" .build/debug/opentelemetry-swiftPackageTests.xctest/Contents/MacOS/opentelemetry-swiftPackageTests -instr-profile .build/debug/codecov/default.profdata > .build/debug/codecov/coverage_report.lcov
18+
xcrun llvm-cov export -ignore-filename-regex="pb\.swift|grpc\.swift" -format="lcov" .build/debug/opentelemetry-swiftPackageTests.xctest/Contents/MacOS/opentelemetry-swiftPackageTests -instr-profile .build/debug/codecov/default.profdata > .build/debug/codecov/coverage_report.lcov
1919
./codecov -f .build/debug/codecov/coverage_report.lcov

Examples/Datadog Sample/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ let resourceValue = "The resource"
1919
let sampleKey = "sampleKey"
2020
let sampleValue = "sampleValue"
2121

22-
let instrumentationLibraryName = "DatadogExporter"
23-
let instrumentationLibraryVersion = "semver:0.1.0"
24-
var instrumentationLibraryInfo = InstrumentationLibraryInfo(name: instrumentationLibraryName, version: instrumentationLibraryVersion)
22+
let instrumentationScopeName = "DatadogExporter"
23+
let instrumentationScopeVersion = "semver:0.1.0"
24+
var instrumentationScopeInfo = InstrumentationScopeInfo(name: instrumentationScopeName, version: instrumentationScopeVersion)
2525

2626
var tracer: TracerSdk
27-
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instrumentationLibraryName, instrumentationVersion: instrumentationLibraryVersion) as! TracerSdk
27+
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instrumentationScopeName, instrumentationVersion: instrumentationScopeVersion) as! TracerSdk
2828

2929
#if targetEnvironment(macCatalyst)
3030
let hostName = UIDevice.current.name

Examples/OTLP Exporter/docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ version: "3"
22
services:
33
# Collector
44
collector:
5-
image: otel/opentelemetry-collector:0.50.0
5+
image: otel/opentelemetry-collector:0.62.1
6+
# The latest image of the otel-collector may not work, so specifying the version that works with this release
67
# image: otel/opentelemetry-collector:latest
78
command: ["--config=/conf/collector-config.yaml"]
89
volumes:

Examples/OTLP Exporter/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ let sampleValue = "sampleValue"
2020

2121
var resources = DefaultResources().get()
2222

23-
let instrumentationLibraryName = "OTLPExporter"
24-
let instrumentationLibraryVersion = "semver:0.1.0"
25-
var instrumentationLibraryInfo = InstrumentationLibraryInfo(name: instrumentationLibraryName, version: instrumentationLibraryVersion)
23+
let instrumentationScopeName = "OTLPExporter"
24+
let instrumentationScopeVersion = "semver:0.1.0"
25+
var instrumentationScopeInfo = InstrumentationScopeInfo(name: instrumentationScopeName, version: instrumentationScopeVersion)
2626

2727
var tracer: TracerSdk
28-
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instrumentationLibraryName, instrumentationVersion: instrumentationLibraryVersion) as! TracerSdk
28+
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instrumentationScopeName, instrumentationVersion: instrumentationScopeVersion) as! TracerSdk
2929

3030
let configuration = ClientConnection.Configuration(
3131
target: .hostAndPort("localhost", 4317),

Examples/Simple Exporter/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ let sampleValue = "sampleValue"
1717

1818
let resources = DefaultResources().get()
1919

20-
let instrumentationLibraryName = "SimpleExporter"
21-
let instrumentationLibraryVersion = "semver:0.1.0"
22-
var instrumentationLibraryInfo = InstrumentationLibraryInfo(name: instrumentationLibraryName, version: instrumentationLibraryVersion)
20+
let instrumentationScopeName = "SimpleExporter"
21+
let instrumentationScopeVersion = "semver:0.1.0"
22+
var instrumentationScopeInfo = InstrumentationScopeInfo(name: instrumentationScopeName, version: instrumentationScopeVersion)
2323

2424
var tracer: TracerSdk
25-
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instrumentationLibraryName, instrumentationVersion: instrumentationLibraryVersion) as! TracerSdk
25+
tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instrumentationScopeName, instrumentationVersion: instrumentationScopeVersion) as! TracerSdk
2626

2727
func simpleSpan() {
2828
let span = tracer.spanBuilder(spanName: "SimpleSpan").setSpanKind(spanKind: .client).startSpan()

Package.resolved

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Exporters/OpenTelemetryProtocol/common/CommonAdapter.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ struct CommonAdapter {
4848
return keyValue
4949
}
5050

51-
static func toProtoInstrumentationLibrary(instrumentationLibraryInfo: InstrumentationLibraryInfo) -> Opentelemetry_Proto_Common_V1_InstrumentationLibrary {
51+
static func toProtoInstrumentationScope(instrumentationScopeInfo: InstrumentationScopeInfo) -> Opentelemetry_Proto_Common_V1_InstrumentationScope {
5252

53-
var instrumentationLibrary = Opentelemetry_Proto_Common_V1_InstrumentationLibrary()
54-
instrumentationLibrary.name = instrumentationLibraryInfo.name
55-
if let version = instrumentationLibraryInfo.version {
56-
instrumentationLibrary.version = version
53+
var instrumentationScope = Opentelemetry_Proto_Common_V1_InstrumentationScope()
54+
instrumentationScope.name = instrumentationScopeInfo.name
55+
if let version = instrumentationScopeInfo.version {
56+
instrumentationScope.version = version
5757
}
58-
return instrumentationLibrary
58+
return instrumentationScope
5959
}
6060

6161
}

Sources/Exporters/OpenTelemetryProtocol/metric/MetricsAdapter.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@ import OpenTelemetrySdk
88

99
struct MetricsAdapter {
1010
static func toProtoResourceMetrics(metricDataList: [Metric]) -> [Opentelemetry_Proto_Metrics_V1_ResourceMetrics] {
11-
let resourceAndLibraryMap = groupByResouceAndLibrary(metricDataList: metricDataList)
11+
let resourceAndScopeMap = groupByResouceAndScope(metricDataList: metricDataList)
1212
var resourceMetrics = [Opentelemetry_Proto_Metrics_V1_ResourceMetrics]()
1313

14-
resourceAndLibraryMap.forEach { resMap in
15-
var instrumentationLibraryMetrics = [Opentelemetry_Proto_Metrics_V1_InstrumentationLibraryMetrics]()
16-
resMap.value.forEach { instLibrary in
14+
resourceAndScopeMap.forEach { resMap in
15+
var instrumentationScopeMetrics = [Opentelemetry_Proto_Metrics_V1_ScopeMetrics]()
16+
resMap.value.forEach { instScope in
1717
var protoInst =
18-
Opentelemetry_Proto_Metrics_V1_InstrumentationLibraryMetrics()
19-
protoInst.instrumentationLibrary =
20-
CommonAdapter.toProtoInstrumentationLibrary(instrumentationLibraryInfo: instLibrary.key)
21-
instLibrary.value.forEach {
18+
Opentelemetry_Proto_Metrics_V1_ScopeMetrics()
19+
protoInst.scope =
20+
CommonAdapter.toProtoInstrumentationScope(instrumentationScopeInfo: instScope.key)
21+
instScope.value.forEach {
2222
protoInst.metrics.append($0)
2323
}
24-
instrumentationLibraryMetrics.append(protoInst)
24+
instrumentationScopeMetrics.append(protoInst)
2525
}
2626
var resourceMetric = Opentelemetry_Proto_Metrics_V1_ResourceMetrics()
2727
resourceMetric.resource = ResourceAdapter.toProtoResource(resource: resMap.key)
28-
resourceMetric.instrumentationLibraryMetrics.append(contentsOf: instrumentationLibraryMetrics)
28+
resourceMetric.scopeMetrics.append(contentsOf: instrumentationScopeMetrics)
2929
resourceMetrics.append(resourceMetric)
3030
}
3131

3232
return resourceMetrics
3333
}
3434

35-
private static func groupByResouceAndLibrary(metricDataList: [Metric]) -> [Resource: [InstrumentationLibraryInfo: [Opentelemetry_Proto_Metrics_V1_Metric]]] {
36-
var results = [Resource: [InstrumentationLibraryInfo: [Opentelemetry_Proto_Metrics_V1_Metric]]]()
35+
private static func groupByResouceAndScope(metricDataList: [Metric]) -> [Resource: [InstrumentationScopeInfo: [Opentelemetry_Proto_Metrics_V1_Metric]]] {
36+
var results = [Resource: [InstrumentationScopeInfo: [Opentelemetry_Proto_Metrics_V1_Metric]]]()
3737

3838
metricDataList.forEach {
3939
if let metric = toProtoMetric(metric: $0) {
40-
results[$0.resource, default: [InstrumentationLibraryInfo: [Opentelemetry_Proto_Metrics_V1_Metric]]()][$0.instrumentationLibraryInfo, default: [Opentelemetry_Proto_Metrics_V1_Metric]()]
40+
results[$0.resource, default: [InstrumentationScopeInfo: [Opentelemetry_Proto_Metrics_V1_Metric]]()][$0.instrumentationScopeInfo, default: [Opentelemetry_Proto_Metrics_V1_Metric]()]
4141
.append(metric)
4242
}
4343
}

Sources/Exporters/OpenTelemetryProtocol/metric/OtlpMetricExporter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import OpenTelemetrySdk
1313

1414
public class OtlpMetricExporter: MetricExporter {
1515
let channel: GRPCChannel
16-
let metricClient: Opentelemetry_Proto_Collector_Metrics_V1_MetricsServiceClient
16+
var metricClient: Opentelemetry_Proto_Collector_Metrics_V1_MetricsServiceNIOClient
1717
let config : OtlpConfiguration
1818
var callOptions : CallOptions? = nil
1919

@@ -22,7 +22,7 @@ public class OtlpMetricExporter: MetricExporter {
2222
public init(channel: GRPCChannel, config: OtlpConfiguration = OtlpConfiguration(), logger: Logger = Logger(label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() }), envVarHeaders: [(String,String)]? = EnvVarHeaders.attributes) {
2323
self.channel = channel
2424
self.config = config
25-
self.metricClient = Opentelemetry_Proto_Collector_Metrics_V1_MetricsServiceClient(channel: self.channel)
25+
self.metricClient = Opentelemetry_Proto_Collector_Metrics_V1_MetricsServiceNIOClient(channel: self.channel)
2626
if let headers = envVarHeaders {
2727
callOptions = CallOptions(customMetadata: HPACKHeaders(headers), logger: logger)
2828
} else if let headers = config.headers {

Sources/Exporters/OpenTelemetryProtocol/proto/common.pb.swift

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,6 @@ public struct Opentelemetry_Proto_Common_V1_KeyValue {
219219
fileprivate var _value: Opentelemetry_Proto_Common_V1_AnyValue? = nil
220220
}
221221

222-
/// InstrumentationLibrary is a message representing the instrumentation library information
223-
/// such as the fully qualified name and version.
224-
/// InstrumentationLibrary is wire-compatible with InstrumentationScope for binary
225-
/// Protobuf format.
226-
/// This message is deprecated and will be removed on June 15, 2022.
227-
public struct Opentelemetry_Proto_Common_V1_InstrumentationLibrary {
228-
// SwiftProtobuf.Message conformance is added in an extension below. See the
229-
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
230-
// methods supported on all messages.
231-
232-
/// An empty instrumentation library name means the name is unknown.
233-
public var name: String = String()
234-
235-
public var version: String = String()
236-
237-
public var unknownFields = SwiftProtobuf.UnknownStorage()
238-
239-
public init() {}
240-
}
241-
242222
/// InstrumentationScope is a message representing the instrumentation scope information
243223
/// such as the fully qualified name and version.
244224
public struct Opentelemetry_Proto_Common_V1_InstrumentationScope {
@@ -251,6 +231,10 @@ public struct Opentelemetry_Proto_Common_V1_InstrumentationScope {
251231

252232
public var version: String = String()
253233

234+
public var attributes: [Opentelemetry_Proto_Common_V1_KeyValue] = []
235+
236+
public var droppedAttributesCount: UInt32 = 0
237+
254238
public var unknownFields = SwiftProtobuf.UnknownStorage()
255239

256240
public init() {}
@@ -262,7 +246,6 @@ extension Opentelemetry_Proto_Common_V1_AnyValue.OneOf_Value: @unchecked Sendabl
262246
extension Opentelemetry_Proto_Common_V1_ArrayValue: @unchecked Sendable {}
263247
extension Opentelemetry_Proto_Common_V1_KeyValueList: @unchecked Sendable {}
264248
extension Opentelemetry_Proto_Common_V1_KeyValue: @unchecked Sendable {}
265-
extension Opentelemetry_Proto_Common_V1_InstrumentationLibrary: @unchecked Sendable {}
266249
extension Opentelemetry_Proto_Common_V1_InstrumentationScope: @unchecked Sendable {}
267250
#endif // swift(>=5.5) && canImport(_Concurrency)
268251

@@ -511,49 +494,13 @@ extension Opentelemetry_Proto_Common_V1_KeyValue: SwiftProtobuf.Message, SwiftPr
511494
}
512495
}
513496

514-
extension Opentelemetry_Proto_Common_V1_InstrumentationLibrary: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
515-
public static let protoMessageName: String = _protobuf_package + ".InstrumentationLibrary"
516-
public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
517-
1: .same(proto: "name"),
518-
2: .same(proto: "version"),
519-
]
520-
521-
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
522-
while let fieldNumber = try decoder.nextFieldNumber() {
523-
// The use of inline closures is to circumvent an issue where the compiler
524-
// allocates stack space for every case branch when no optimizations are
525-
// enabled. https://github.com/apple/swift-protobuf/issues/1034
526-
switch fieldNumber {
527-
case 1: try { try decoder.decodeSingularStringField(value: &self.name) }()
528-
case 2: try { try decoder.decodeSingularStringField(value: &self.version) }()
529-
default: break
530-
}
531-
}
532-
}
533-
534-
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
535-
if !self.name.isEmpty {
536-
try visitor.visitSingularStringField(value: self.name, fieldNumber: 1)
537-
}
538-
if !self.version.isEmpty {
539-
try visitor.visitSingularStringField(value: self.version, fieldNumber: 2)
540-
}
541-
try unknownFields.traverse(visitor: &visitor)
542-
}
543-
544-
public static func ==(lhs: Opentelemetry_Proto_Common_V1_InstrumentationLibrary, rhs: Opentelemetry_Proto_Common_V1_InstrumentationLibrary) -> Bool {
545-
if lhs.name != rhs.name {return false}
546-
if lhs.version != rhs.version {return false}
547-
if lhs.unknownFields != rhs.unknownFields {return false}
548-
return true
549-
}
550-
}
551-
552497
extension Opentelemetry_Proto_Common_V1_InstrumentationScope: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
553498
public static let protoMessageName: String = _protobuf_package + ".InstrumentationScope"
554499
public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
555500
1: .same(proto: "name"),
556501
2: .same(proto: "version"),
502+
3: .same(proto: "attributes"),
503+
4: .standard(proto: "dropped_attributes_count"),
557504
]
558505

559506
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
@@ -564,6 +511,8 @@ extension Opentelemetry_Proto_Common_V1_InstrumentationScope: SwiftProtobuf.Mess
564511
switch fieldNumber {
565512
case 1: try { try decoder.decodeSingularStringField(value: &self.name) }()
566513
case 2: try { try decoder.decodeSingularStringField(value: &self.version) }()
514+
case 3: try { try decoder.decodeRepeatedMessageField(value: &self.attributes) }()
515+
case 4: try { try decoder.decodeSingularUInt32Field(value: &self.droppedAttributesCount) }()
567516
default: break
568517
}
569518
}
@@ -576,12 +525,20 @@ extension Opentelemetry_Proto_Common_V1_InstrumentationScope: SwiftProtobuf.Mess
576525
if !self.version.isEmpty {
577526
try visitor.visitSingularStringField(value: self.version, fieldNumber: 2)
578527
}
528+
if !self.attributes.isEmpty {
529+
try visitor.visitRepeatedMessageField(value: self.attributes, fieldNumber: 3)
530+
}
531+
if self.droppedAttributesCount != 0 {
532+
try visitor.visitSingularUInt32Field(value: self.droppedAttributesCount, fieldNumber: 4)
533+
}
579534
try unknownFields.traverse(visitor: &visitor)
580535
}
581536

582537
public static func ==(lhs: Opentelemetry_Proto_Common_V1_InstrumentationScope, rhs: Opentelemetry_Proto_Common_V1_InstrumentationScope) -> Bool {
583538
if lhs.name != rhs.name {return false}
584539
if lhs.version != rhs.version {return false}
540+
if lhs.attributes != rhs.attributes {return false}
541+
if lhs.droppedAttributesCount != rhs.droppedAttributesCount {return false}
585542
if lhs.unknownFields != rhs.unknownFields {return false}
586543
return true
587544
}

0 commit comments

Comments
 (0)