From 4b61a0a2557e89861a2dc4a0bcd294606664eff0 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Tue, 2 Jan 2024 14:31:19 +0100 Subject: [PATCH 01/13] RUM-1836 feat(otel-tracer): scaffold conformance to otel Tracer, SpanBuilder and Span --- DatadogTrace/Sources/DDNoOps.swift | 9 +- DatadogTrace/Sources/DatadogTracer.swift | 9 +- .../Sources/OpenTelemetry/OTelNoOpSpan.swift | 47 ++++++++++ .../OpenTelemetry/OTelNoOpSpanBuilder.swift | 50 ++++++++++ .../Sources/OpenTelemetry/OTelSpan.swift | 94 +++++++++++++++++++ .../OpenTelemetry/OTelSpanBuilder.swift | 50 ++++++++++ DatadogTrace/Sources/Tracer.swift | 3 +- 7 files changed, 259 insertions(+), 3 deletions(-) create mode 100644 DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift create mode 100644 DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift create mode 100644 DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift create mode 100644 DatadogTrace/Sources/OpenTelemetry/OTelSpanBuilder.swift diff --git a/DatadogTrace/Sources/DDNoOps.swift b/DatadogTrace/Sources/DDNoOps.swift index 1f013b0161..fe71dc1fc3 100644 --- a/DatadogTrace/Sources/DDNoOps.swift +++ b/DatadogTrace/Sources/DDNoOps.swift @@ -6,6 +6,7 @@ import Foundation import DatadogInternal +import OpenTelemetryApi internal struct DDNoopGlobals { static let tracer = DDNoopTracer() @@ -13,7 +14,7 @@ internal struct DDNoopGlobals { static let context = DDNoopSpanContext() } -internal struct DDNoopTracer: OTTracer { +internal class DDNoopTracer: OTTracer, OpenTelemetryApi.Tracer { var activeSpan: OTSpan? = nil private func warn() { @@ -44,6 +45,12 @@ internal struct DDNoopTracer: OTTracer { warn() return DDNoopGlobals.span } + + // MARK: - Open Telemetry + + func spanBuilder(spanName: String) -> OpenTelemetryApi.SpanBuilder { + fatalError("Not implemented") + } } internal struct DDNoopSpan: OTSpan { diff --git a/DatadogTrace/Sources/DatadogTracer.swift b/DatadogTrace/Sources/DatadogTracer.swift index 6d737634c7..ee26cb7414 100644 --- a/DatadogTrace/Sources/DatadogTracer.swift +++ b/DatadogTrace/Sources/DatadogTracer.swift @@ -6,8 +6,9 @@ import Foundation import DatadogInternal +import OpenTelemetryApi -internal class DatadogTracer: OTTracer { +internal class DatadogTracer: OTTracer, OpenTelemetryApi.Tracer { internal weak var core: DatadogCoreProtocol? /// Global tags configured for Trace feature. @@ -156,4 +157,10 @@ internal class DatadogTracer: OTTracer { forKey: SpanCoreContext.key ) } + + // MARK: - OpenTelemetry + + func spanBuilder(spanName: String) -> OpenTelemetryApi.SpanBuilder { + OTelSpanBuilder() + } } diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift new file mode 100644 index 0000000000..31e08e4c67 --- /dev/null +++ b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift @@ -0,0 +1,47 @@ +/* +* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. +* This product includes software developed at Datadog (https://www.datadoghq.com/). +* Copyright 2019-Present Datadog, Inc. +*/ + +import Foundation +import OpenTelemetryApi + +class OTelNoOpSpan: Span { + var kind: OpenTelemetryApi.SpanKind = .internal + + var name: String = "" + + var context: SpanContext = SpanContext.create( + traceId: TraceId.invalid, + spanId: SpanId.invalid, + traceFlags: TraceFlags(), + traceState: TraceState() + ) + + var isRecording: Bool = false + + var status: Status = Status.unset + + var description: String = "NoOpSpan" + + func updateName(name: String) {} + + func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue?) {} + + func addEvent(name: String) {} + + func addEvent(name: String, timestamp: Date) {} + + func addEvent(name: String, attributes: [String: OpenTelemetryApi.AttributeValue]) {} + + func addEvent(name: String, attributes: [String: OpenTelemetryApi.AttributeValue], timestamp: Date) {} + + func end() { + OpenTelemetry.instance.contextProvider.removeContextForSpan(self) + } + + func end(time: Date) { + end() + } +} diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift new file mode 100644 index 0000000000..ae2b8abe70 --- /dev/null +++ b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift @@ -0,0 +1,50 @@ +/* +* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. +* This product includes software developed at Datadog (https://www.datadoghq.com/). +* Copyright 2019-Present Datadog, Inc. +*/ + +import Foundation +import OpenTelemetryApi + +class NoOpSpanBuilder: SpanBuilder { + @discardableResult public func startSpan() -> Span { + return OTelNoOpSpan() + } + + @discardableResult public func setParent(_ parent: Span) -> Self { + return self + } + + @discardableResult public func setParent(_ parent: SpanContext) -> Self { + return self + } + + @discardableResult public func setNoParent() -> Self { + return self + } + + @discardableResult public func addLink(spanContext: SpanContext) -> Self { + return self + } + + @discardableResult public func addLink(spanContext: SpanContext, attributes: [String: OpenTelemetryApi.AttributeValue]) -> Self { + return self + } + + @discardableResult public func setSpanKind(spanKind: SpanKind) -> Self { + return self + } + + @discardableResult public func setStartTime(time: Date) -> Self { + return self + } + + public func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue) -> Self { + return self + } + + func setActive(_ active: Bool) -> Self { + return self + } +} diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift new file mode 100644 index 0000000000..aa83590685 --- /dev/null +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift @@ -0,0 +1,94 @@ +/* +* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. +* This product includes software developed at Datadog (https://www.datadoghq.com/). +* Copyright 2019-Present Datadog, Inc. +*/ + +import Foundation +import OpenTelemetryApi + +class OTelSpan: OpenTelemetryApi.Span { + private let tracer: DatadogTracer + private let queue: DispatchQueue + private var _status: OpenTelemetryApi.Status + private var _name: String + + init( + context: OpenTelemetryApi.SpanContext, + kind: OpenTelemetryApi.SpanKind, + name: String, + tracer: DatadogTracer + ) { + self._name = name + self._status = .unset + self.context = context + self.isRecording = true + self.kind = kind + self.queue = tracer.queue + self.tracer = tracer + } + + var kind: OpenTelemetryApi.SpanKind + + var context: OpenTelemetryApi.SpanContext + + var isRecording: Bool + + var status: OpenTelemetryApi.Status { + get { + queue.sync { + _status + } + } + set { + queue.sync { + _status = newValue + } + } + } + + var name: String { + get { + queue.sync { + _name + } + } + set { + queue.sync { + _name = newValue + } + } + } + + func addEvent(name: String) { + fatalError("Not implemented") + } + + func addEvent(name: String, timestamp: Date) { + fatalError("Not implemented") + } + + func addEvent(name: String, attributes: [String : OpenTelemetryApi.AttributeValue]) { + fatalError("Not implemented") + } + + func addEvent(name: String, attributes: [String : OpenTelemetryApi.AttributeValue], timestamp: Date) { + fatalError("Not implemented") + } + + func end() { + fatalError("Not implemented") + } + + func end(time: Date) { + fatalError("Not implemented") + } + + var description: String { + return "WrapperSpan" + } + + func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue?) { + fatalError("Not implemented") + } +} diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpanBuilder.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpanBuilder.swift new file mode 100644 index 0000000000..2f3b051883 --- /dev/null +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpanBuilder.swift @@ -0,0 +1,50 @@ +/* +* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. +* This product includes software developed at Datadog (https://www.datadoghq.com/). +* Copyright 2019-Present Datadog, Inc. +*/ + +import Foundation +import OpenTelemetryApi + +class OTelSpanBuilder: OpenTelemetryApi.SpanBuilder { + func setParent(_ parent: OpenTelemetryApi.Span) -> Self { + fatalError("Not implemented") + } + + func setParent(_ parent: OpenTelemetryApi.SpanContext) -> Self { + fatalError("Not implemented") + } + + func setNoParent() -> Self { + fatalError("Not implemented") + } + + func addLink(spanContext: OpenTelemetryApi.SpanContext) -> Self { + fatalError("Not implemented") + } + + func addLink(spanContext: OpenTelemetryApi.SpanContext, attributes: [String : OpenTelemetryApi.AttributeValue]) -> Self { + fatalError("Not implemented") + } + + func setSpanKind(spanKind: OpenTelemetryApi.SpanKind) -> Self { + fatalError("Not implemented") + } + + func setStartTime(time: Date) -> Self { + fatalError("Not implemented") + } + + func setActive(_ active: Bool) -> Self { + fatalError("Not implemented") + } + + func startSpan() -> OpenTelemetryApi.Span { + fatalError("Not implemented") + } + + func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue) -> Self { + fatalError("Not implemented") + } +} diff --git a/DatadogTrace/Sources/Tracer.swift b/DatadogTrace/Sources/Tracer.swift index fd3431f569..1f8cb36a13 100644 --- a/DatadogTrace/Sources/Tracer.swift +++ b/DatadogTrace/Sources/Tracer.swift @@ -6,6 +6,7 @@ import Foundation import DatadogInternal +import OpenTelemetryApi /// Datadog - specific span tags to be used with `Tracer.shared().startSpan(operationName:references:tags:startTime:)` /// and `span.setTag(key:value:)`. @@ -49,7 +50,7 @@ public class Tracer { /// It requires `Trace.enable(with:in:)` to be called first - otherwise it will return no-op implementation. /// - Parameter core: the instance of Datadog SDK the Trace feature was enabled in (global instance by default) /// - Returns: the Tracer that conforms to Open Tracing API (`OTTracer`) - public static func shared(in core: DatadogCoreProtocol = CoreRegistry.default) -> OTTracer { + public static func shared(in core: DatadogCoreProtocol = CoreRegistry.default) -> OTTracer & OpenTelemetryApi.Tracer { do { guard !(core is NOPDatadogCore) else { throw ProgrammerError( From 27ecb2a8a00a31e92879db180f2de1dafe8e7b69 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Wed, 3 Jan 2024 10:41:35 +0100 Subject: [PATCH 02/13] RUM-1836 feat(otel-tracer): implement core functionality of the otel tracer --- DatadogTrace/Sources/DDNoOps.swift | 3 +- DatadogTrace/Sources/DatadogTracer.swift | 10 +- .../Sources/OpenTelemetry/OTelNoOpSpan.swift | 8 +- .../OpenTelemetry/OTelNoOpSpanBuilder.swift | 28 ++-- .../Sources/OpenTelemetry/OTelSpan.swift | 123 +++++++++++++----- .../OpenTelemetry/OTelSpanBuilder.swift | 122 ++++++++++++++--- .../OpenTelemetry/OtelSpanId+Datadog.swift | 20 +++ .../OpenTelemetry/OtelTraceId+Datadog.swift | 20 +++ .../OtelSpanId+DatadogTests.swift | 20 +++ .../Tests/OpenTelemetry/OtelSpanTests.swift | 100 ++++++++++++++ .../OtelTraceId+DatadogTests.swift | 20 +++ 11 files changed, 413 insertions(+), 61 deletions(-) create mode 100644 DatadogTrace/Sources/OpenTelemetry/OtelSpanId+Datadog.swift create mode 100644 DatadogTrace/Sources/OpenTelemetry/OtelTraceId+Datadog.swift create mode 100644 DatadogTrace/Tests/OpenTelemetry/OtelSpanId+DatadogTests.swift create mode 100644 DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift create mode 100644 DatadogTrace/Tests/OpenTelemetry/OtelTraceId+DatadogTests.swift diff --git a/DatadogTrace/Sources/DDNoOps.swift b/DatadogTrace/Sources/DDNoOps.swift index fe71dc1fc3..b39f818020 100644 --- a/DatadogTrace/Sources/DDNoOps.swift +++ b/DatadogTrace/Sources/DDNoOps.swift @@ -49,7 +49,8 @@ internal class DDNoopTracer: OTTracer, OpenTelemetryApi.Tracer { // MARK: - Open Telemetry func spanBuilder(spanName: String) -> OpenTelemetryApi.SpanBuilder { - fatalError("Not implemented") + warn() + return OTelNoOpSpanBuilder() } } diff --git a/DatadogTrace/Sources/DatadogTracer.swift b/DatadogTrace/Sources/DatadogTracer.swift index ee26cb7414..cb371aa813 100644 --- a/DatadogTrace/Sources/DatadogTracer.swift +++ b/DatadogTrace/Sources/DatadogTracer.swift @@ -161,6 +161,14 @@ internal class DatadogTracer: OTTracer, OpenTelemetryApi.Tracer { // MARK: - OpenTelemetry func spanBuilder(spanName: String) -> OpenTelemetryApi.SpanBuilder { - OTelSpanBuilder() + OTelSpanBuilder( + active: false, + attributes: [:], + parent: .currentSpan, + spanKind: .client, + spanName: spanName, + startTime: nil, + tracer: self + ) } } diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift index 31e08e4c67..c0f08291f7 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift @@ -7,21 +7,21 @@ import Foundation import OpenTelemetryApi -class OTelNoOpSpan: Span { +internal class OTelNoOpSpan: Span { var kind: OpenTelemetryApi.SpanKind = .internal var name: String = "" - var context: SpanContext = SpanContext.create( + var context = SpanContext.create( traceId: TraceId.invalid, spanId: SpanId.invalid, traceFlags: TraceFlags(), traceState: TraceState() ) - var isRecording: Bool = false + var isRecording = false - var status: Status = Status.unset + var status = Status.unset var description: String = "NoOpSpan" diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift index ae2b8abe70..b4b0c4560d 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift @@ -7,40 +7,48 @@ import Foundation import OpenTelemetryApi -class NoOpSpanBuilder: SpanBuilder { - @discardableResult public func startSpan() -> Span { +internal class OTelNoOpSpanBuilder: SpanBuilder { + @discardableResult + func startSpan() -> Span { return OTelNoOpSpan() } - @discardableResult public func setParent(_ parent: Span) -> Self { + @discardableResult + func setParent(_ parent: Span) -> Self { return self } - @discardableResult public func setParent(_ parent: SpanContext) -> Self { + @discardableResult + func setParent(_ parent: SpanContext) -> Self { return self } - @discardableResult public func setNoParent() -> Self { + @discardableResult + func setNoParent() -> Self { return self } - @discardableResult public func addLink(spanContext: SpanContext) -> Self { + @discardableResult + func addLink(spanContext: SpanContext) -> Self { return self } - @discardableResult public func addLink(spanContext: SpanContext, attributes: [String: OpenTelemetryApi.AttributeValue]) -> Self { + @discardableResult + func addLink(spanContext: SpanContext, attributes: [String: OpenTelemetryApi.AttributeValue]) -> Self { return self } - @discardableResult public func setSpanKind(spanKind: SpanKind) -> Self { + @discardableResult + func setSpanKind(spanKind: SpanKind) -> Self { return self } - @discardableResult public func setStartTime(time: Date) -> Self { + @discardableResult + func setStartTime(time: Date) -> Self { return self } - public func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue) -> Self { + func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue) -> Self { return self } diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift index aa83590685..b6d6f47380 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift @@ -7,33 +7,29 @@ import Foundation import OpenTelemetryApi -class OTelSpan: OpenTelemetryApi.Span { - private let tracer: DatadogTracer - private let queue: DispatchQueue +internal enum DatadogTagKeys: String { + case spanKind = "span.kind" + case errorMessage = "error.Message" +} + +internal class OTelSpan: OpenTelemetryApi.Span { private var _status: OpenTelemetryApi.Status private var _name: String - init( - context: OpenTelemetryApi.SpanContext, - kind: OpenTelemetryApi.SpanKind, - name: String, - tracer: DatadogTracer - ) { - self._name = name - self._status = .unset - self.context = context - self.isRecording = true - self.kind = kind - self.queue = tracer.queue - self.tracer = tracer - } - + var attributes: [String: OpenTelemetryApi.AttributeValue] + let context: OpenTelemetryApi.SpanContext var kind: OpenTelemetryApi.SpanKind + let nestedSpan: DDSpan + let tracer: DatadogTracer + let queue: DispatchQueue - var context: OpenTelemetryApi.SpanContext - + /// `isRecording` indicates whether the span is recording or not + /// and events can be added to it. var isRecording: Bool + /// `status` saves state of the code and description indicating + /// whether the span has recorded errors. This will be done by setting `error.message` + /// tag on the span. var status: OpenTelemetryApi.Status { get { queue.sync { @@ -42,11 +38,16 @@ class OTelSpan: OpenTelemetryApi.Span { } set { queue.sync { + guard isRecording else { + return + } + _status = newValue } } } + /// `name` of the span is akin to operation name in Datadog var name: String { get { queue.sync { @@ -55,33 +56,93 @@ class OTelSpan: OpenTelemetryApi.Span { } set { queue.sync { + guard isRecording else { + return + } _name = newValue } + nestedSpan.setOperationName(name) } } + init( + attributes: [String: OpenTelemetryApi.AttributeValue], + kind: OpenTelemetryApi.SpanKind, + name: String, + parentSpanID: OpenTelemetryApi.SpanId?, + spanContext: OpenTelemetryApi.SpanContext, + spanKind: OpenTelemetryApi.SpanKind, + startTime: Date, + tracer: DatadogTracer + ) { + self._name = name + self._status = .unset + self.attributes = attributes + self.context = spanContext + self.kind = kind + self.isRecording = true + self.queue = tracer.queue + self.tracer = tracer + self.nestedSpan = .init( + tracer: tracer, + context: .init( + traceID: context.traceId.toDatadog(), + spanID: context.spanId.toDatadog(), + parentSpanID: parentSpanID?.toDatadog(), + baggageItems: .init() + ), + operationName: name, + startTime: startTime, + tags: [:] + ) + } + + // swiftlint:disable unavailable_function func addEvent(name: String) { - fatalError("Not implemented") + fatalError("Not implemented yet") } func addEvent(name: String, timestamp: Date) { - fatalError("Not implemented") + fatalError("Not implemented yet") } - func addEvent(name: String, attributes: [String : OpenTelemetryApi.AttributeValue]) { - fatalError("Not implemented") + func addEvent(name: String, attributes: [String: OpenTelemetryApi.AttributeValue]) { + fatalError("Not implemented yet") } - func addEvent(name: String, attributes: [String : OpenTelemetryApi.AttributeValue], timestamp: Date) { - fatalError("Not implemented") + func addEvent(name: String, attributes: [String: OpenTelemetryApi.AttributeValue], timestamp: Date) { + fatalError("Not implemented yet") } + // swiftlint:enable unavailable_function func end() { - fatalError("Not implemented") + end(time: Date()) } func end(time: Date) { - fatalError("Not implemented") + queue.sync { + guard isRecording else { + return + } + isRecording = false + + // Attributes maps to tags in Datadog + for (key, value) in attributes { + nestedSpan.setTag(key: key, value: value.description) + } + + // If status is error, error.message tag is added + switch self._status { + case .error(description: let description): + nestedSpan.setTag(key: DatadogTagKeys.errorMessage.rawValue, value: description) + case .ok, .unset: + break + } + + // SpanKind maps to the `span.kind` tag in Datadog + nestedSpan.setTag(key: DatadogTagKeys.spanKind.rawValue, value: kind.rawValue) + } + nestedSpan.finish(at: time) } var description: String { @@ -89,6 +150,10 @@ class OTelSpan: OpenTelemetryApi.Span { } func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue?) { - fatalError("Not implemented") + guard isRecording else { + return + } + + attributes[key] = value } } diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpanBuilder.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpanBuilder.swift index 2f3b051883..93a4deb244 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelSpanBuilder.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpanBuilder.swift @@ -1,50 +1,140 @@ /* -* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. -* This product includes software developed at Datadog (https://www.datadoghq.com/). -* Copyright 2019-Present Datadog, Inc. -*/ + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ import Foundation import OpenTelemetryApi -class OTelSpanBuilder: OpenTelemetryApi.SpanBuilder { +internal class OTelSpanBuilder: OpenTelemetryApi.SpanBuilder { + var tracer: DatadogTracer + var spanName: String + var spanKind = SpanKind.client + var attributes: [String: OpenTelemetryApi.AttributeValue] + var startTime: Date? + var active: Bool + var parent: Parent + + enum Parent { + case currentSpan + case span(OpenTelemetryApi.Span) + case spanContext(OpenTelemetryApi.SpanContext) + case noParent + + func context() -> OpenTelemetryApi.SpanContext? { + switch self { + case .currentSpan: + return OpenTelemetry.instance.contextProvider.activeSpan?.context + case .span(let span): + return span.context + case .spanContext(let context): + return context + case .noParent: + return nil + } + } + } + + init( + active: Bool, + attributes: [String: OpenTelemetryApi.AttributeValue], + parent: Parent, + spanKind: SpanKind, + spanName: String, + startTime: Date?, + tracer: DatadogTracer + ) { + self.tracer = tracer + self.spanName = spanName + self.spanKind = spanKind + self.attributes = attributes + self.startTime = startTime + self.active = active + self.parent = parent + } + func setParent(_ parent: OpenTelemetryApi.Span) -> Self { - fatalError("Not implemented") + self.parent = .span(parent) + return self } func setParent(_ parent: OpenTelemetryApi.SpanContext) -> Self { - fatalError("Not implemented") + self.parent = .spanContext(parent) + return self } func setNoParent() -> Self { - fatalError("Not implemented") + self.parent = .noParent + return self } + // swiftlint:disable unavailable_function func addLink(spanContext: OpenTelemetryApi.SpanContext) -> Self { - fatalError("Not implemented") + fatalError("Not implemented yet") } - func addLink(spanContext: OpenTelemetryApi.SpanContext, attributes: [String : OpenTelemetryApi.AttributeValue]) -> Self { - fatalError("Not implemented") + func addLink(spanContext: OpenTelemetryApi.SpanContext, attributes: [String: OpenTelemetryApi.AttributeValue]) -> Self { + fatalError("Not implemented yet") } + // swiftlint:enable unavailable_function func setSpanKind(spanKind: OpenTelemetryApi.SpanKind) -> Self { - fatalError("Not implemented") + self.spanKind = spanKind + return self } func setStartTime(time: Date) -> Self { - fatalError("Not implemented") + self.startTime = time + return self } func setActive(_ active: Bool) -> Self { - fatalError("Not implemented") + self.active = active + return self } func startSpan() -> OpenTelemetryApi.Span { - fatalError("Not implemented") + let parentContext = parent.context() + let traceId: TraceId + let spanId = SpanId.random() + let traceState: TraceState + + if let parentContext = parentContext, parentContext.isValid { + traceId = parentContext.traceId + traceState = parentContext.traceState + } else { + traceId = TraceId.random() + traceState = .init() + } + + let spanContext = SpanContext.create( + traceId: traceId, + spanId: spanId, + traceFlags: TraceFlags(), + traceState: traceState + ) + + let createdSpan = OTelSpan( + attributes: attributes, + kind: spanKind, + name: spanName, + parentSpanID: parentContext?.spanId, + spanContext: spanContext, + spanKind: spanKind, + startTime: startTime ?? Date(), + tracer: tracer + ) + + if active { + OpenTelemetry.instance.contextProvider.setActiveSpan(createdSpan) + } + + return createdSpan } func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue) -> Self { - fatalError("Not implemented") + attributes[key] = value + return self } } diff --git a/DatadogTrace/Sources/OpenTelemetry/OtelSpanId+Datadog.swift b/DatadogTrace/Sources/OpenTelemetry/OtelSpanId+Datadog.swift new file mode 100644 index 0000000000..6c8ff2c0b8 --- /dev/null +++ b/DatadogTrace/Sources/OpenTelemetry/OtelSpanId+Datadog.swift @@ -0,0 +1,20 @@ +/* +* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. +* This product includes software developed at Datadog (https://www.datadoghq.com/). +* Copyright 2019-Present Datadog, Inc. +*/ + +import Foundation +import OpenTelemetryApi +import DatadogInternal + +extension OpenTelemetryApi.SpanId { + /// Converts OpenTelemetry `SpanId` to Datadog `SpanID`. + /// - Returns: Datadog `SpanID`. + func toDatadog() -> SpanID { + var data = Data(count: 8) + self.copyBytesTo(dest: &data, destOffset: 0) + let integerLiteral = UInt64(bigEndian: data.withUnsafeBytes { $0.load(as: UInt64.self) }) + return .init(integerLiteral: integerLiteral) + } +} diff --git a/DatadogTrace/Sources/OpenTelemetry/OtelTraceId+Datadog.swift b/DatadogTrace/Sources/OpenTelemetry/OtelTraceId+Datadog.swift new file mode 100644 index 0000000000..9f34b8cf8d --- /dev/null +++ b/DatadogTrace/Sources/OpenTelemetry/OtelTraceId+Datadog.swift @@ -0,0 +1,20 @@ +/* +* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. +* This product includes software developed at Datadog (https://www.datadoghq.com/). +* Copyright 2019-Present Datadog, Inc. +*/ + +import Foundation +import OpenTelemetryApi +import DatadogInternal + +extension OpenTelemetryApi.TraceId { + /// Converts OpenTelemetry `TraceId` to Datadog `TraceID`. + /// - Returns: Datadog `TraceID` with only higher order bits considered. + func toDatadog() -> TraceID { + var data = Data(count: 16) + self.copyBytesTo(dest: &data, destOffset: 0) + let integerLiteral = UInt64(bigEndian: data.withUnsafeBytes { $0.load(as: UInt64.self) }) + return .init(integerLiteral: integerLiteral) + } +} diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelSpanId+DatadogTests.swift b/DatadogTrace/Tests/OpenTelemetry/OtelSpanId+DatadogTests.swift new file mode 100644 index 0000000000..b1e2566259 --- /dev/null +++ b/DatadogTrace/Tests/OpenTelemetry/OtelSpanId+DatadogTests.swift @@ -0,0 +1,20 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ + +import XCTest +import TestUtilities +import DatadogInternal +import OpenTelemetryApi + +@testable import DatadogTrace + +class OtelSpanIdDatadogTests: XCTestCase { + func testToDatadog() { + let otelId = SpanId.random() + let ddId = otelId.toDatadog() + XCTAssertEqual(otelId.rawValue, ddId.rawValue) + } +} diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift new file mode 100644 index 0000000000..80ebebb49a --- /dev/null +++ b/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift @@ -0,0 +1,100 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ + +import XCTest +import TestUtilities +import DatadogInternal + +@testable import DatadogTrace + +final class OtelSpanTests: XCTestCase { + func testSpanResourceNameDefault() { + let writeSpanExpectation = expectation(description: "write span event") + let core = PassthroughCoreMock(expectation: writeSpanExpectation) + + // Given + let tracer: DatadogTracer = .mockWith(core: core) + let span = tracer.spanBuilder(spanName: "OperationName").startSpan() + + // When + span.end() + + // Then + waitForExpectations(timeout: 0.5, handler: nil) + let events: [SpanEventsEnvelope] = core.events() + XCTAssertEqual(events.count, 1) + let recordedSpan = events.first!.spans.first! + XCTAssertEqual(recordedSpan.resource, "OperationName") + XCTAssertEqual(recordedSpan.operationName, "OperationName") + } + + func testSpanSetName() { + let writeSpanExpectation = expectation(description: "write span event") + let core = PassthroughCoreMock(expectation: writeSpanExpectation) + + // Given + let tracer: DatadogTracer = .mockWith(core: core) + let span = tracer.spanBuilder(spanName: "OperationName").startSpan() + + // When + span.name = "NewOperationName" + span.end() + + // Then + waitForExpectations(timeout: 0.5, handler: nil) + let events: [SpanEventsEnvelope] = core.events() + XCTAssertEqual(events.count, 1) + let recordedSpan = events.first!.spans.first! + XCTAssertEqual(recordedSpan.resource, "NewOperationName") + XCTAssertEqual(recordedSpan.operationName, "NewOperationName") + } + + func testSpanEnd() { + // Given + let (name, ignoredName) = ("trueName", "invalidName") + let (code, ignoredCode) = (200, 400) + let (message, ignoredMessage) = ("message", "ignoredMessage") + let (attributes, ignoredAttributes) = (["key": "value"], ["ignoredKey": "ignoredValue"]) + + let writeSpanExpectation = expectation(description: "write span event") + let core = PassthroughCoreMock(expectation: writeSpanExpectation) + + let tracer: DatadogTracer = .mockWith(core: core) + let span = tracer.spanBuilder(spanName: name).startSpan() + span.putHttpStatusCode(statusCode: code, reasonPhrase: message) + for (key, value) in attributes { + span.setAttribute(key: key, value: value) + } + XCTAssertTrue(span.isRecording) + + // When + span.end() + XCTAssertFalse(span.isRecording) + + // Then ignores + span.name = ignoredName + span.putHttpStatusCode(statusCode: ignoredCode, reasonPhrase: ignoredMessage) + for (key, value) in ignoredAttributes { + span.setAttribute(key: key, value: value) + } + + span.end() + + waitForExpectations(timeout: 0.5, handler: nil) + let events: [SpanEventsEnvelope] = core.events() + XCTAssertEqual(events.count, 1) + let recordedSpan = events.first!.spans.first! + + XCTAssertEqual(recordedSpan.resource, name) + XCTAssertEqual(recordedSpan.operationName, name) + let expectedTags = [ + "http.status_code": "200", + "key": "value", + "span.kind": "client", + ] + XCTAssertEqual(recordedSpan.tags, expectedTags) + } +} diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelTraceId+DatadogTests.swift b/DatadogTrace/Tests/OpenTelemetry/OtelTraceId+DatadogTests.swift new file mode 100644 index 0000000000..749ec16f63 --- /dev/null +++ b/DatadogTrace/Tests/OpenTelemetry/OtelTraceId+DatadogTests.swift @@ -0,0 +1,20 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ + +import XCTest +import TestUtilities +import DatadogInternal +import OpenTelemetryApi + +@testable import DatadogTrace + +class OtelTraceIdDatadogTests: XCTestCase { + func testToDatadog_onlyHigherOrderBitsAreConsidered() { + let otelId = TraceId.random() + let ddId = otelId.toDatadog() + XCTAssertEqual(otelId.rawHigherLong, ddId.rawValue) + } +} From c9143b0c2d58942982a665a6ea14dacf094f5332 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Wed, 3 Jan 2024 10:56:41 +0100 Subject: [PATCH 03/13] RUM-1836 feat(otel-tracer): add test cases --- .../Sources/OpenTelemetry/OTelNoOpSpan.swift | 2 +- .../Sources/OpenTelemetry/OTelSpan.swift | 2 +- .../Tests/OpenTelemetry/OtelSpanTests.swift | 77 ++++++++++++++++++- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift index c0f08291f7..8bd29b4e44 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift @@ -23,7 +23,7 @@ internal class OTelNoOpSpan: Span { var status = Status.unset - var description: String = "NoOpSpan" + var description: String = "OTelNoOpSpan" func updateName(name: String) {} diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift index b6d6f47380..afae72b353 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift @@ -146,7 +146,7 @@ internal class OTelSpan: OpenTelemetryApi.Span { } var description: String { - return "WrapperSpan" + return "OTelSpan" } func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue?) { diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift index 80ebebb49a..5052221477 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift @@ -74,7 +74,7 @@ final class OtelSpanTests: XCTestCase { span.end() XCTAssertFalse(span.isRecording) - // Then ignores + // Then ignores span.name = ignoredName span.putHttpStatusCode(statusCode: ignoredCode, reasonPhrase: ignoredMessage) for (key, value) in ignoredAttributes { @@ -97,4 +97,79 @@ final class OtelSpanTests: XCTestCase { ] XCTAssertEqual(recordedSpan.tags, expectedTags) } + + func testSetParentSpan() { + let writeSpanExpectation = expectation(description: "write span event") + writeSpanExpectation.expectedFulfillmentCount = 2 + let core = PassthroughCoreMock(expectation: writeSpanExpectation) + + // Given + let tracer: DatadogTracer = .mockWith(core: core) + let parentSpan = tracer.spanBuilder(spanName: "Parent").startSpan() + let _ = tracer.spanBuilder(spanName: "Noise").startSpan() + let childSpan = tracer.spanBuilder(spanName: "Child").setParent(parentSpan).startSpan() + + // When + childSpan.end() + parentSpan.end() + + // Then + waitForExpectations(timeout: 0.5, handler: nil) + let events: [SpanEventsEnvelope] = core.events() + XCTAssertEqual(events.count, 2) + let child = events.first!.spans.first! + let parent = events.last!.spans.first! + XCTAssertEqual(parent.parentID, nil) + XCTAssertEqual(child.parentID, parent.spanID) + } + + func testSetParentContext() { + let writeSpanExpectation = expectation(description: "write span event") + writeSpanExpectation.expectedFulfillmentCount = 2 + let core = PassthroughCoreMock(expectation: writeSpanExpectation) + + // Given + let tracer: DatadogTracer = .mockWith(core: core) + let parentSpan = tracer.spanBuilder(spanName: "Parent").startSpan() + let _ = tracer.spanBuilder(spanName: "Noise").startSpan() + let childSpan = tracer.spanBuilder(spanName: "Child").setParent(parentSpan.context).startSpan() + + // When + childSpan.end() + parentSpan.end() + + // Then + waitForExpectations(timeout: 0.5, handler: nil) + let events: [SpanEventsEnvelope] = core.events() + XCTAssertEqual(events.count, 2) + let child = events.first!.spans.first! + let parent = events.last!.spans.first! + XCTAssertEqual(parent.parentID, nil) + XCTAssertEqual(child.parentID, parent.spanID) + } + + func testSetNoParent() { + let writeSpanExpectation = expectation(description: "write span event") + writeSpanExpectation.expectedFulfillmentCount = 2 + let core = PassthroughCoreMock(expectation: writeSpanExpectation) + + // Given + let tracer: DatadogTracer = .mockWith(core: core) + let parentSpan = tracer.spanBuilder(spanName: "Parent").startSpan() + let _ = tracer.spanBuilder(spanName: "Noise").startSpan() + let childSpan = tracer.spanBuilder(spanName: "Child").setNoParent().startSpan() + + // When + childSpan.end() + parentSpan.end() + + // Then + waitForExpectations(timeout: 0.5, handler: nil) + let events: [SpanEventsEnvelope] = core.events() + XCTAssertEqual(events.count, 2) + let child = events.first!.spans.first! + let parent = events.last!.spans.first! + XCTAssertEqual(parent.parentID, nil) + XCTAssertEqual(child.parentID, nil) + } } From bf55a6c3824bbc2c7c061c71b4eaa6c7af4805e8 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Wed, 3 Jan 2024 10:59:27 +0100 Subject: [PATCH 04/13] RUM-1836 feat(otel-tracer): fix linter --- DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift index 5052221477..5a19d431a6 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift @@ -106,7 +106,7 @@ final class OtelSpanTests: XCTestCase { // Given let tracer: DatadogTracer = .mockWith(core: core) let parentSpan = tracer.spanBuilder(spanName: "Parent").startSpan() - let _ = tracer.spanBuilder(spanName: "Noise").startSpan() + _ = tracer.spanBuilder(spanName: "Noise").startSpan() let childSpan = tracer.spanBuilder(spanName: "Child").setParent(parentSpan).startSpan() // When @@ -131,7 +131,7 @@ final class OtelSpanTests: XCTestCase { // Given let tracer: DatadogTracer = .mockWith(core: core) let parentSpan = tracer.spanBuilder(spanName: "Parent").startSpan() - let _ = tracer.spanBuilder(spanName: "Noise").startSpan() + _ = tracer.spanBuilder(spanName: "Noise").startSpan() let childSpan = tracer.spanBuilder(spanName: "Child").setParent(parentSpan.context).startSpan() // When @@ -156,7 +156,7 @@ final class OtelSpanTests: XCTestCase { // Given let tracer: DatadogTracer = .mockWith(core: core) let parentSpan = tracer.spanBuilder(spanName: "Parent").startSpan() - let _ = tracer.spanBuilder(spanName: "Noise").startSpan() + _ = tracer.spanBuilder(spanName: "Noise").startSpan() let childSpan = tracer.spanBuilder(spanName: "Child").setNoParent().startSpan() // When From 156454d415d178f6f6842c83604ccd988f5fb897 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Wed, 3 Jan 2024 11:35:20 +0100 Subject: [PATCH 05/13] RUM-1836 feat(otel-tracer): add tests --- .../Tests/OpenTelemetry/OtelSpanTests.swift | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift index 5a19d431a6..63be2c1322 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift @@ -95,7 +95,7 @@ final class OtelSpanTests: XCTestCase { "key": "value", "span.kind": "client", ] - XCTAssertEqual(recordedSpan.tags, expectedTags) + XCTAssertTagsEqual(recordedSpan.tags, expectedTags) } func testSetParentSpan() { @@ -172,4 +172,62 @@ final class OtelSpanTests: XCTestCase { XCTAssertEqual(parent.parentID, nil) XCTAssertEqual(child.parentID, nil) } + + func testSetAttribute() { + let writeSpanExpectation = expectation(description: "write span event") + let core = PassthroughCoreMock(expectation: writeSpanExpectation) + + // Given + let tracer: DatadogTracer = .mockWith(core: core) + let span = tracer.spanBuilder(spanName: "Span").startSpan() + + // When + span.setAttribute(key: "key", value: .bool(true)) + span.setAttribute(key: "key2", value: .string("value2")) + span.setAttribute(key: "key3", value: .int(3)) + span.setAttribute(key: "key4", value: .double(4.0)) + span.setAttribute(key: "key5", value: .stringArray(["value5", "value6"])) + span.setAttribute(key: "key6", value: .intArray([6, 7])) + span.setAttribute(key: "key7", value: .doubleArray([7.0, 8.0])) + span.setAttribute(key: "key8", value: .boolArray([true, false])) + + span.end() + + // Then + waitForExpectations(timeout: 0.5, handler: nil) + let events: [SpanEventsEnvelope] = core.events() + XCTAssertEqual(events.count, 1) + let recordedSpan = events.first!.spans.first! + let expectedTags = + [ + "key": "true", + "key2": "value2", + "key3": "3", + "key4": "4.0", + "key5": "[\"value5\", \"value6\"]", + "key6": "[6, 7]", + "key7": "[7.0, 8.0]", + "key8": "[true, false]", + "span.kind": "client", + ] + XCTAssertTagsEqual(recordedSpan.tags, expectedTags) + } +} + +func XCTAssertTagsEqual( + _ dict1: [String: String], + _ dict2: [String: String], + file: StaticString = #filePath, + line: UInt = #line +) { + XCTAssertEqual(dict1.count, dict2.count, file: file, line: line) + for (key, value) in dict1 { + XCTAssertEqual( + dict2[key], + value, + "Expected \(key) to be \(value), but was \(String(describing: dict2[key]))", + file: file, + line: line + ) + } } From 3a8b2ca2bcfaaaaa4732352f739701b1d031c262 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Wed, 3 Jan 2024 14:39:55 +0100 Subject: [PATCH 06/13] RUM-1836 feat(otel-tracer): add source files to project --- Datadog/Datadog.xcodeproj/project.pbxproj | 70 +++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Datadog/Datadog.xcodeproj/project.pbxproj b/Datadog/Datadog.xcodeproj/project.pbxproj index 6845215121..f4a2211ccd 100644 --- a/Datadog/Datadog.xcodeproj/project.pbxproj +++ b/Datadog/Datadog.xcodeproj/project.pbxproj @@ -36,6 +36,24 @@ 3C41693C29FBF4D50042B9D2 /* DatadogWebViewTracking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CE119FE29F7BE0100202522 /* DatadogWebViewTracking.framework */; }; 3C6C7FDB2B45738C006F5CBC /* OpenTelemetryApi in Frameworks */ = {isa = PBXBuildFile; productRef = 3C6C7FDA2B45738C006F5CBC /* OpenTelemetryApi */; }; 3C6C7FDD2B457392006F5CBC /* OpenTelemetryApi in Frameworks */ = {isa = PBXBuildFile; productRef = 3C6C7FDC2B457392006F5CBC /* OpenTelemetryApi */; }; + 3C6C7FE52B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */; }; + 3C6C7FE62B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */; }; + 3C6C7FE72B459AAA006F5CBC /* OTelSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */; }; + 3C6C7FE82B459AAA006F5CBC /* OTelSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */; }; + 3C6C7FE92B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */; }; + 3C6C7FEA2B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */; }; + 3C6C7FEB2B459AAA006F5CBC /* OtelTraceId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE22B459AAA006F5CBC /* OtelTraceId+Datadog.swift */; }; + 3C6C7FEC2B459AAA006F5CBC /* OtelTraceId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE22B459AAA006F5CBC /* OtelTraceId+Datadog.swift */; }; + 3C6C7FED2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */; }; + 3C6C7FEE2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */; }; + 3C6C7FEF2B459AAA006F5CBC /* OtelSpanId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE42B459AAA006F5CBC /* OtelSpanId+Datadog.swift */; }; + 3C6C7FF02B459AAA006F5CBC /* OtelSpanId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE42B459AAA006F5CBC /* OtelSpanId+Datadog.swift */; }; + 3C6C7FFB2B459AF6006F5CBC /* OtelSpanId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF22B459AB3006F5CBC /* OtelSpanId+DatadogTests.swift */; }; + 3C6C7FFC2B459AF6006F5CBC /* OtelTraceId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF32B459AB3006F5CBC /* OtelTraceId+DatadogTests.swift */; }; + 3C6C7FFD2B459AF6006F5CBC /* OtelSpanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF42B459AB3006F5CBC /* OtelSpanTests.swift */; }; + 3C6C7FFE2B459AF6006F5CBC /* OtelSpanId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF22B459AB3006F5CBC /* OtelSpanId+DatadogTests.swift */; }; + 3C6C7FFF2B459AF6006F5CBC /* OtelTraceId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF32B459AB3006F5CBC /* OtelTraceId+DatadogTests.swift */; }; + 3C6C80002B459AF6006F5CBC /* OtelSpanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF42B459AB3006F5CBC /* OtelSpanTests.swift */; }; 3C74305C29FBC0480053B80F /* DatadogInternal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2DA2385298D57AA00C6C7E6 /* DatadogInternal.framework */; }; 3C85D42129F7C5C900AFF894 /* WebViewTracking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C85D41429F7C59C00AFF894 /* WebViewTracking.swift */; }; 3C85D42A29F7C70300AFF894 /* TestUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D257953E298ABA65008A1BE5 /* TestUtilities.framework */; }; @@ -1882,6 +1900,15 @@ 3C2206F22AB9CE9300DE780C /* MetaTypeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetaTypeExtensions.swift; sourceTree = ""; }; 3C394EF62AA5F49F008F48BA /* URLSessionDataDelegateSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionDataDelegateSwizzler.swift; sourceTree = ""; }; 3C394EF92AA5F4C8008F48BA /* URLSessionDataDelegateSwizzlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionDataDelegateSwizzlerTests.swift; sourceTree = ""; }; + 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelNoOpSpanBuilder.swift; sourceTree = ""; }; + 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelSpan.swift; sourceTree = ""; }; + 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelSpanBuilder.swift; sourceTree = ""; }; + 3C6C7FE22B459AAA006F5CBC /* OtelTraceId+Datadog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OtelTraceId+Datadog.swift"; sourceTree = ""; }; + 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelNoOpSpan.swift; sourceTree = ""; }; + 3C6C7FE42B459AAA006F5CBC /* OtelSpanId+Datadog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OtelSpanId+Datadog.swift"; sourceTree = ""; }; + 3C6C7FF22B459AB3006F5CBC /* OtelSpanId+DatadogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OtelSpanId+DatadogTests.swift"; sourceTree = ""; }; + 3C6C7FF32B459AB3006F5CBC /* OtelTraceId+DatadogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OtelTraceId+DatadogTests.swift"; sourceTree = ""; }; + 3C6C7FF42B459AB3006F5CBC /* OtelSpanTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OtelSpanTests.swift; sourceTree = ""; }; 3C85D41429F7C59C00AFF894 /* WebViewTracking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewTracking.swift; sourceTree = ""; }; 3C85D42B29F7C87D00AFF894 /* HostsSanitizerMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HostsSanitizerMock.swift; sourceTree = ""; }; 3CB32AD32ACB733000D602ED /* URLSessionSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionSwizzler.swift; sourceTree = ""; }; @@ -3084,6 +3111,29 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 3C6C7FDE2B459AAA006F5CBC /* OpenTelemetry */ = { + isa = PBXGroup; + children = ( + 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */, + 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */, + 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */, + 3C6C7FE22B459AAA006F5CBC /* OtelTraceId+Datadog.swift */, + 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */, + 3C6C7FE42B459AAA006F5CBC /* OtelSpanId+Datadog.swift */, + ); + path = OpenTelemetry; + sourceTree = ""; + }; + 3C6C7FF12B459AB3006F5CBC /* OpenTelemetry */ = { + isa = PBXGroup; + children = ( + 3C6C7FF22B459AB3006F5CBC /* OtelSpanId+DatadogTests.swift */, + 3C6C7FF32B459AB3006F5CBC /* OtelTraceId+DatadogTests.swift */, + 3C6C7FF42B459AB3006F5CBC /* OtelSpanTests.swift */, + ); + path = OpenTelemetry; + sourceTree = ""; + }; 3CE11A3B29F7BEE700202522 /* DatadogWebViewTracking */ = { isa = PBXGroup; children = ( @@ -5486,6 +5536,7 @@ D25EE93529C4C3C300CE3839 /* DatadogTrace */ = { isa = PBXGroup; children = ( + 3C6C7FDE2B459AAA006F5CBC /* OpenTelemetry */, 61A2CC382A44B0EA0000FF25 /* Trace.swift */, 61A2CC352A44B0A20000FF25 /* TraceConfiguration.swift */, 61A2CC3B2A44BED30000FF25 /* Tracer.swift */, @@ -5508,6 +5559,7 @@ D25EE93F29C4C3C400CE3839 /* DatadogTraceTests */ = { isa = PBXGroup; children = ( + 3C6C7FF12B459AB3006F5CBC /* OpenTelemetry */, 619CE75D2A458CE1005588CB /* TraceConfigurationTests.swift */, 61AD4E172451C7FF006E34EA /* TracingFeatureMocks.swift */, 61C5A89824509C1100DA608C /* DDSpanTests.swift */, @@ -8276,14 +8328,20 @@ D2C1A4FC29C4C4CB00946C31 /* RequestBuilder.swift in Sources */, D2C1A50D29C4C4CB00946C31 /* SpanTagsReducer.swift in Sources */, D2C1A51A29C4C5DD00946C31 /* JSONEncoder.swift in Sources */, + 3C6C7FED2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */, + 3C6C7FE52B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */, D2C1A51829C4C53F00946C31 /* OTSpan.swift in Sources */, D2C1A51429C4C53F00946C31 /* OTSpanContext.swift in Sources */, + 3C6C7FEB2B459AAA006F5CBC /* OtelTraceId+Datadog.swift in Sources */, + 3C6C7FE92B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */, D2C1A51329C4C53F00946C31 /* OTReference.swift in Sources */, + 3C6C7FEF2B459AAA006F5CBC /* OtelSpanId+Datadog.swift in Sources */, D2C1A4FB29C4C4CB00946C31 /* MessageReceivers.swift in Sources */, 61A2CC362A44B0A20000FF25 /* TraceConfiguration.swift in Sources */, 61A2CC392A44B0EA0000FF25 /* Trace.swift in Sources */, D2C1A50029C4C4CB00946C31 /* ActiveSpansPool.swift in Sources */, D2C1A50929C4C4CB00946C31 /* SpanEventEncoder.swift in Sources */, + 3C6C7FE72B459AAA006F5CBC /* OTelSpan.swift in Sources */, D2C1A4FE29C4C4CB00946C31 /* SpanEventMapper.swift in Sources */, D2C1A50329C4C4CB00946C31 /* DDFormat.swift in Sources */, D2C1A51629C4C53F00946C31 /* OTConstants.swift in Sources */, @@ -8314,10 +8372,13 @@ D2C1A51D29C4C75700946C31 /* SpanEventBuilderTests.swift in Sources */, D2C1A52229C4C75700946C31 /* DDNoopTracerTests.swift in Sources */, D2C1A51C29C4C75700946C31 /* ContextMessageReceiverTests.swift in Sources */, + 3C6C7FFD2B459AF6006F5CBC /* OtelSpanTests.swift in Sources */, 619CE7612A458D66005588CB /* TraceTests.swift in Sources */, D2C1A52029C4C75700946C31 /* DDSpanTests.swift in Sources */, + 3C6C7FFC2B459AF6006F5CBC /* OtelTraceId+DatadogTests.swift in Sources */, D2C1A51B29C4C75700946C31 /* DDSpanContextTests.swift in Sources */, D2C1A52729C4C7D000946C31 /* TracingFeatureMocks.swift in Sources */, + 3C6C7FFB2B459AF6006F5CBC /* OtelSpanId+DatadogTests.swift in Sources */, D2C1A51F29C4C75700946C31 /* ActiveSpansPoolTests.swift in Sources */, D2C1A52529C4C75700946C31 /* SpanSanitizerTests.swift in Sources */, ); @@ -8465,14 +8526,20 @@ D2C1A53A29C4F2DF00946C31 /* RequestBuilder.swift in Sources */, D2C1A53B29C4F2DF00946C31 /* SpanTagsReducer.swift in Sources */, D2C1A53C29C4F2DF00946C31 /* JSONEncoder.swift in Sources */, + 3C6C7FEE2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */, + 3C6C7FE62B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */, D2C1A53D29C4F2DF00946C31 /* OTSpan.swift in Sources */, D2C1A53E29C4F2DF00946C31 /* OTSpanContext.swift in Sources */, + 3C6C7FEC2B459AAA006F5CBC /* OtelTraceId+Datadog.swift in Sources */, + 3C6C7FEA2B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */, D2C1A53F29C4F2DF00946C31 /* OTReference.swift in Sources */, + 3C6C7FF02B459AAA006F5CBC /* OtelSpanId+Datadog.swift in Sources */, D2C1A54129C4F2DF00946C31 /* MessageReceivers.swift in Sources */, 61A2CC372A44B0A20000FF25 /* TraceConfiguration.swift in Sources */, 61A2CC3A2A44B0EA0000FF25 /* Trace.swift in Sources */, D2C1A54229C4F2DF00946C31 /* ActiveSpansPool.swift in Sources */, D2C1A54329C4F2DF00946C31 /* SpanEventEncoder.swift in Sources */, + 3C6C7FE82B459AAA006F5CBC /* OTelSpan.swift in Sources */, D2C1A54429C4F2DF00946C31 /* SpanEventMapper.swift in Sources */, D2C1A54529C4F2DF00946C31 /* DDFormat.swift in Sources */, D2C1A54629C4F2DF00946C31 /* OTConstants.swift in Sources */, @@ -8503,10 +8570,13 @@ D2C1A56229C4F2E800946C31 /* SpanEventBuilderTests.swift in Sources */, D2C1A56329C4F2E800946C31 /* DDNoopTracerTests.swift in Sources */, D2C1A56529C4F2E800946C31 /* ContextMessageReceiverTests.swift in Sources */, + 3C6C80002B459AF6006F5CBC /* OtelSpanTests.swift in Sources */, 619CE7622A458D66005588CB /* TraceTests.swift in Sources */, D2C1A56629C4F2E800946C31 /* DDSpanTests.swift in Sources */, + 3C6C7FFF2B459AF6006F5CBC /* OtelTraceId+DatadogTests.swift in Sources */, D2C1A56729C4F2E800946C31 /* DDSpanContextTests.swift in Sources */, D2C1A56829C4F2E800946C31 /* TracingFeatureMocks.swift in Sources */, + 3C6C7FFE2B459AF6006F5CBC /* OtelSpanId+DatadogTests.swift in Sources */, D2C1A56929C4F2E800946C31 /* ActiveSpansPoolTests.swift in Sources */, D2C1A56A29C4F2E800946C31 /* SpanSanitizerTests.swift in Sources */, ); From 84a7f78ac1d80ae18b24e481971dad589ca7404a Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Wed, 3 Jan 2024 14:43:19 +0100 Subject: [PATCH 07/13] RUM-1836 feat(otel-tracer): casing - now all OTel --- Datadog/Datadog.xcodeproj/project.pbxproj | 60 +++++++++---------- ...Datadog.swift => OTelSpanId+Datadog.swift} | 0 ...atadog.swift => OTelTraceId+Datadog.swift} | 0 ...ts.swift => OTelSpanId+DatadogTests.swift} | 2 +- ...telSpanTests.swift => OTelSpanTests.swift} | 2 +- ...s.swift => OTelTraceId+DatadogTests.swift} | 2 +- 6 files changed, 33 insertions(+), 33 deletions(-) rename DatadogTrace/Sources/OpenTelemetry/{OtelSpanId+Datadog.swift => OTelSpanId+Datadog.swift} (100%) rename DatadogTrace/Sources/OpenTelemetry/{OtelTraceId+Datadog.swift => OTelTraceId+Datadog.swift} (100%) rename DatadogTrace/Tests/OpenTelemetry/{OtelSpanId+DatadogTests.swift => OTelSpanId+DatadogTests.swift} (92%) rename DatadogTrace/Tests/OpenTelemetry/{OtelSpanTests.swift => OTelSpanTests.swift} (99%) rename DatadogTrace/Tests/OpenTelemetry/{OtelTraceId+DatadogTests.swift => OTelTraceId+DatadogTests.swift} (92%) diff --git a/Datadog/Datadog.xcodeproj/project.pbxproj b/Datadog/Datadog.xcodeproj/project.pbxproj index f4a2211ccd..06da6fee37 100644 --- a/Datadog/Datadog.xcodeproj/project.pbxproj +++ b/Datadog/Datadog.xcodeproj/project.pbxproj @@ -42,18 +42,18 @@ 3C6C7FE82B459AAA006F5CBC /* OTelSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */; }; 3C6C7FE92B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */; }; 3C6C7FEA2B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */; }; - 3C6C7FEB2B459AAA006F5CBC /* OtelTraceId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE22B459AAA006F5CBC /* OtelTraceId+Datadog.swift */; }; - 3C6C7FEC2B459AAA006F5CBC /* OtelTraceId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE22B459AAA006F5CBC /* OtelTraceId+Datadog.swift */; }; + 3C6C7FEB2B459AAA006F5CBC /* OTelTraceId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE22B459AAA006F5CBC /* OTelTraceId+Datadog.swift */; }; + 3C6C7FEC2B459AAA006F5CBC /* OTelTraceId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE22B459AAA006F5CBC /* OTelTraceId+Datadog.swift */; }; 3C6C7FED2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */; }; 3C6C7FEE2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */; }; - 3C6C7FEF2B459AAA006F5CBC /* OtelSpanId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE42B459AAA006F5CBC /* OtelSpanId+Datadog.swift */; }; - 3C6C7FF02B459AAA006F5CBC /* OtelSpanId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE42B459AAA006F5CBC /* OtelSpanId+Datadog.swift */; }; - 3C6C7FFB2B459AF6006F5CBC /* OtelSpanId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF22B459AB3006F5CBC /* OtelSpanId+DatadogTests.swift */; }; - 3C6C7FFC2B459AF6006F5CBC /* OtelTraceId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF32B459AB3006F5CBC /* OtelTraceId+DatadogTests.swift */; }; - 3C6C7FFD2B459AF6006F5CBC /* OtelSpanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF42B459AB3006F5CBC /* OtelSpanTests.swift */; }; - 3C6C7FFE2B459AF6006F5CBC /* OtelSpanId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF22B459AB3006F5CBC /* OtelSpanId+DatadogTests.swift */; }; - 3C6C7FFF2B459AF6006F5CBC /* OtelTraceId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF32B459AB3006F5CBC /* OtelTraceId+DatadogTests.swift */; }; - 3C6C80002B459AF6006F5CBC /* OtelSpanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF42B459AB3006F5CBC /* OtelSpanTests.swift */; }; + 3C6C7FEF2B459AAA006F5CBC /* OTelSpanId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE42B459AAA006F5CBC /* OTelSpanId+Datadog.swift */; }; + 3C6C7FF02B459AAA006F5CBC /* OTelSpanId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE42B459AAA006F5CBC /* OTelSpanId+Datadog.swift */; }; + 3C6C7FFB2B459AF6006F5CBC /* OTelSpanId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF22B459AB3006F5CBC /* OTelSpanId+DatadogTests.swift */; }; + 3C6C7FFC2B459AF6006F5CBC /* OTelTraceId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF32B459AB3006F5CBC /* OTelTraceId+DatadogTests.swift */; }; + 3C6C7FFD2B459AF6006F5CBC /* OTelSpanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF42B459AB3006F5CBC /* OTelSpanTests.swift */; }; + 3C6C7FFE2B459AF6006F5CBC /* OTelSpanId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF22B459AB3006F5CBC /* OTelSpanId+DatadogTests.swift */; }; + 3C6C7FFF2B459AF6006F5CBC /* OTelTraceId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF32B459AB3006F5CBC /* OTelTraceId+DatadogTests.swift */; }; + 3C6C80002B459AF6006F5CBC /* OTelSpanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF42B459AB3006F5CBC /* OTelSpanTests.swift */; }; 3C74305C29FBC0480053B80F /* DatadogInternal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2DA2385298D57AA00C6C7E6 /* DatadogInternal.framework */; }; 3C85D42129F7C5C900AFF894 /* WebViewTracking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C85D41429F7C59C00AFF894 /* WebViewTracking.swift */; }; 3C85D42A29F7C70300AFF894 /* TestUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D257953E298ABA65008A1BE5 /* TestUtilities.framework */; }; @@ -1903,12 +1903,12 @@ 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelNoOpSpanBuilder.swift; sourceTree = ""; }; 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelSpan.swift; sourceTree = ""; }; 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelSpanBuilder.swift; sourceTree = ""; }; - 3C6C7FE22B459AAA006F5CBC /* OtelTraceId+Datadog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OtelTraceId+Datadog.swift"; sourceTree = ""; }; + 3C6C7FE22B459AAA006F5CBC /* OTelTraceId+Datadog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OTelTraceId+Datadog.swift"; sourceTree = ""; }; 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelNoOpSpan.swift; sourceTree = ""; }; - 3C6C7FE42B459AAA006F5CBC /* OtelSpanId+Datadog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OtelSpanId+Datadog.swift"; sourceTree = ""; }; - 3C6C7FF22B459AB3006F5CBC /* OtelSpanId+DatadogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OtelSpanId+DatadogTests.swift"; sourceTree = ""; }; - 3C6C7FF32B459AB3006F5CBC /* OtelTraceId+DatadogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OtelTraceId+DatadogTests.swift"; sourceTree = ""; }; - 3C6C7FF42B459AB3006F5CBC /* OtelSpanTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OtelSpanTests.swift; sourceTree = ""; }; + 3C6C7FE42B459AAA006F5CBC /* OTelSpanId+Datadog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OTelSpanId+Datadog.swift"; sourceTree = ""; }; + 3C6C7FF22B459AB3006F5CBC /* OTelSpanId+DatadogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OTelSpanId+DatadogTests.swift"; sourceTree = ""; }; + 3C6C7FF32B459AB3006F5CBC /* OTelTraceId+DatadogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OTelTraceId+DatadogTests.swift"; sourceTree = ""; }; + 3C6C7FF42B459AB3006F5CBC /* OTelSpanTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelSpanTests.swift; sourceTree = ""; }; 3C85D41429F7C59C00AFF894 /* WebViewTracking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewTracking.swift; sourceTree = ""; }; 3C85D42B29F7C87D00AFF894 /* HostsSanitizerMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HostsSanitizerMock.swift; sourceTree = ""; }; 3CB32AD32ACB733000D602ED /* URLSessionSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionSwizzler.swift; sourceTree = ""; }; @@ -3117,9 +3117,9 @@ 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */, 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */, 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */, - 3C6C7FE22B459AAA006F5CBC /* OtelTraceId+Datadog.swift */, + 3C6C7FE22B459AAA006F5CBC /* OTelTraceId+Datadog.swift */, 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */, - 3C6C7FE42B459AAA006F5CBC /* OtelSpanId+Datadog.swift */, + 3C6C7FE42B459AAA006F5CBC /* OTelSpanId+Datadog.swift */, ); path = OpenTelemetry; sourceTree = ""; @@ -3127,9 +3127,9 @@ 3C6C7FF12B459AB3006F5CBC /* OpenTelemetry */ = { isa = PBXGroup; children = ( - 3C6C7FF22B459AB3006F5CBC /* OtelSpanId+DatadogTests.swift */, - 3C6C7FF32B459AB3006F5CBC /* OtelTraceId+DatadogTests.swift */, - 3C6C7FF42B459AB3006F5CBC /* OtelSpanTests.swift */, + 3C6C7FF22B459AB3006F5CBC /* OTelSpanId+DatadogTests.swift */, + 3C6C7FF32B459AB3006F5CBC /* OTelTraceId+DatadogTests.swift */, + 3C6C7FF42B459AB3006F5CBC /* OTelSpanTests.swift */, ); path = OpenTelemetry; sourceTree = ""; @@ -8332,10 +8332,10 @@ 3C6C7FE52B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */, D2C1A51829C4C53F00946C31 /* OTSpan.swift in Sources */, D2C1A51429C4C53F00946C31 /* OTSpanContext.swift in Sources */, - 3C6C7FEB2B459AAA006F5CBC /* OtelTraceId+Datadog.swift in Sources */, + 3C6C7FEB2B459AAA006F5CBC /* OTelTraceId+Datadog.swift in Sources */, 3C6C7FE92B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */, D2C1A51329C4C53F00946C31 /* OTReference.swift in Sources */, - 3C6C7FEF2B459AAA006F5CBC /* OtelSpanId+Datadog.swift in Sources */, + 3C6C7FEF2B459AAA006F5CBC /* OTelSpanId+Datadog.swift in Sources */, D2C1A4FB29C4C4CB00946C31 /* MessageReceivers.swift in Sources */, 61A2CC362A44B0A20000FF25 /* TraceConfiguration.swift in Sources */, 61A2CC392A44B0EA0000FF25 /* Trace.swift in Sources */, @@ -8372,13 +8372,13 @@ D2C1A51D29C4C75700946C31 /* SpanEventBuilderTests.swift in Sources */, D2C1A52229C4C75700946C31 /* DDNoopTracerTests.swift in Sources */, D2C1A51C29C4C75700946C31 /* ContextMessageReceiverTests.swift in Sources */, - 3C6C7FFD2B459AF6006F5CBC /* OtelSpanTests.swift in Sources */, + 3C6C7FFD2B459AF6006F5CBC /* OTelSpanTests.swift in Sources */, 619CE7612A458D66005588CB /* TraceTests.swift in Sources */, D2C1A52029C4C75700946C31 /* DDSpanTests.swift in Sources */, - 3C6C7FFC2B459AF6006F5CBC /* OtelTraceId+DatadogTests.swift in Sources */, + 3C6C7FFC2B459AF6006F5CBC /* OTelTraceId+DatadogTests.swift in Sources */, D2C1A51B29C4C75700946C31 /* DDSpanContextTests.swift in Sources */, D2C1A52729C4C7D000946C31 /* TracingFeatureMocks.swift in Sources */, - 3C6C7FFB2B459AF6006F5CBC /* OtelSpanId+DatadogTests.swift in Sources */, + 3C6C7FFB2B459AF6006F5CBC /* OTelSpanId+DatadogTests.swift in Sources */, D2C1A51F29C4C75700946C31 /* ActiveSpansPoolTests.swift in Sources */, D2C1A52529C4C75700946C31 /* SpanSanitizerTests.swift in Sources */, ); @@ -8530,10 +8530,10 @@ 3C6C7FE62B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */, D2C1A53D29C4F2DF00946C31 /* OTSpan.swift in Sources */, D2C1A53E29C4F2DF00946C31 /* OTSpanContext.swift in Sources */, - 3C6C7FEC2B459AAA006F5CBC /* OtelTraceId+Datadog.swift in Sources */, + 3C6C7FEC2B459AAA006F5CBC /* OTelTraceId+Datadog.swift in Sources */, 3C6C7FEA2B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */, D2C1A53F29C4F2DF00946C31 /* OTReference.swift in Sources */, - 3C6C7FF02B459AAA006F5CBC /* OtelSpanId+Datadog.swift in Sources */, + 3C6C7FF02B459AAA006F5CBC /* OTelSpanId+Datadog.swift in Sources */, D2C1A54129C4F2DF00946C31 /* MessageReceivers.swift in Sources */, 61A2CC372A44B0A20000FF25 /* TraceConfiguration.swift in Sources */, 61A2CC3A2A44B0EA0000FF25 /* Trace.swift in Sources */, @@ -8570,13 +8570,13 @@ D2C1A56229C4F2E800946C31 /* SpanEventBuilderTests.swift in Sources */, D2C1A56329C4F2E800946C31 /* DDNoopTracerTests.swift in Sources */, D2C1A56529C4F2E800946C31 /* ContextMessageReceiverTests.swift in Sources */, - 3C6C80002B459AF6006F5CBC /* OtelSpanTests.swift in Sources */, + 3C6C80002B459AF6006F5CBC /* OTelSpanTests.swift in Sources */, 619CE7622A458D66005588CB /* TraceTests.swift in Sources */, D2C1A56629C4F2E800946C31 /* DDSpanTests.swift in Sources */, - 3C6C7FFF2B459AF6006F5CBC /* OtelTraceId+DatadogTests.swift in Sources */, + 3C6C7FFF2B459AF6006F5CBC /* OTelTraceId+DatadogTests.swift in Sources */, D2C1A56729C4F2E800946C31 /* DDSpanContextTests.swift in Sources */, D2C1A56829C4F2E800946C31 /* TracingFeatureMocks.swift in Sources */, - 3C6C7FFE2B459AF6006F5CBC /* OtelSpanId+DatadogTests.swift in Sources */, + 3C6C7FFE2B459AF6006F5CBC /* OTelSpanId+DatadogTests.swift in Sources */, D2C1A56929C4F2E800946C31 /* ActiveSpansPoolTests.swift in Sources */, D2C1A56A29C4F2E800946C31 /* SpanSanitizerTests.swift in Sources */, ); diff --git a/DatadogTrace/Sources/OpenTelemetry/OtelSpanId+Datadog.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpanId+Datadog.swift similarity index 100% rename from DatadogTrace/Sources/OpenTelemetry/OtelSpanId+Datadog.swift rename to DatadogTrace/Sources/OpenTelemetry/OTelSpanId+Datadog.swift diff --git a/DatadogTrace/Sources/OpenTelemetry/OtelTraceId+Datadog.swift b/DatadogTrace/Sources/OpenTelemetry/OTelTraceId+Datadog.swift similarity index 100% rename from DatadogTrace/Sources/OpenTelemetry/OtelTraceId+Datadog.swift rename to DatadogTrace/Sources/OpenTelemetry/OTelTraceId+Datadog.swift diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelSpanId+DatadogTests.swift b/DatadogTrace/Tests/OpenTelemetry/OTelSpanId+DatadogTests.swift similarity index 92% rename from DatadogTrace/Tests/OpenTelemetry/OtelSpanId+DatadogTests.swift rename to DatadogTrace/Tests/OpenTelemetry/OTelSpanId+DatadogTests.swift index b1e2566259..8085592062 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OtelSpanId+DatadogTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OTelSpanId+DatadogTests.swift @@ -11,7 +11,7 @@ import OpenTelemetryApi @testable import DatadogTrace -class OtelSpanIdDatadogTests: XCTestCase { +class OTelSpanIdDatadogTests: XCTestCase { func testToDatadog() { let otelId = SpanId.random() let ddId = otelId.toDatadog() diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift similarity index 99% rename from DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift rename to DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift index 63be2c1322..48cc819c7d 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OtelSpanTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift @@ -10,7 +10,7 @@ import DatadogInternal @testable import DatadogTrace -final class OtelSpanTests: XCTestCase { +final class OTelSpanTests: XCTestCase { func testSpanResourceNameDefault() { let writeSpanExpectation = expectation(description: "write span event") let core = PassthroughCoreMock(expectation: writeSpanExpectation) diff --git a/DatadogTrace/Tests/OpenTelemetry/OtelTraceId+DatadogTests.swift b/DatadogTrace/Tests/OpenTelemetry/OTelTraceId+DatadogTests.swift similarity index 92% rename from DatadogTrace/Tests/OpenTelemetry/OtelTraceId+DatadogTests.swift rename to DatadogTrace/Tests/OpenTelemetry/OTelTraceId+DatadogTests.swift index 749ec16f63..f5bcc823bc 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OtelTraceId+DatadogTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OTelTraceId+DatadogTests.swift @@ -11,7 +11,7 @@ import OpenTelemetryApi @testable import DatadogTrace -class OtelTraceIdDatadogTests: XCTestCase { +class OTelTraceIdDatadogTests: XCTestCase { func testToDatadog_onlyHigherOrderBitsAreConsidered() { let otelId = TraceId.random() let ddId = otelId.toDatadog() From f03cd630d04a869859d843ff2f38a0e2ba435774 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Thu, 4 Jan 2024 09:41:38 +0100 Subject: [PATCH 08/13] RUM-1836 feat(otel-tracer): remove status API for now, will add later --- .../Sources/OpenTelemetry/OTelSpan.swift | 23 ++----------------- .../Tests/OpenTelemetry/OTelSpanTests.swift | 5 +--- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift index afae72b353..d08f82f5ca 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift @@ -27,23 +27,12 @@ internal class OTelSpan: OpenTelemetryApi.Span { /// and events can be added to it. var isRecording: Bool - /// `status` saves state of the code and description indicating - /// whether the span has recorded errors. This will be done by setting `error.message` - /// tag on the span. var status: OpenTelemetryApi.Status { get { - queue.sync { - _status - } + fatalError("Not implemented yet") } set { - queue.sync { - guard isRecording else { - return - } - - _status = newValue - } + fatalError("Not implemented yet") } } @@ -131,14 +120,6 @@ internal class OTelSpan: OpenTelemetryApi.Span { nestedSpan.setTag(key: key, value: value.description) } - // If status is error, error.message tag is added - switch self._status { - case .error(description: let description): - nestedSpan.setTag(key: DatadogTagKeys.errorMessage.rawValue, value: description) - case .ok, .unset: - break - } - // SpanKind maps to the `span.kind` tag in Datadog nestedSpan.setTag(key: DatadogTagKeys.spanKind.rawValue, value: kind.rawValue) } diff --git a/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift index 48cc819c7d..18f85f263f 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift @@ -55,7 +55,7 @@ final class OTelSpanTests: XCTestCase { func testSpanEnd() { // Given let (name, ignoredName) = ("trueName", "invalidName") - let (code, ignoredCode) = (200, 400) + let (message, ignoredMessage) = ("message", "ignoredMessage") let (attributes, ignoredAttributes) = (["key": "value"], ["ignoredKey": "ignoredValue"]) @@ -64,7 +64,6 @@ final class OTelSpanTests: XCTestCase { let tracer: DatadogTracer = .mockWith(core: core) let span = tracer.spanBuilder(spanName: name).startSpan() - span.putHttpStatusCode(statusCode: code, reasonPhrase: message) for (key, value) in attributes { span.setAttribute(key: key, value: value) } @@ -76,7 +75,6 @@ final class OTelSpanTests: XCTestCase { // Then ignores span.name = ignoredName - span.putHttpStatusCode(statusCode: ignoredCode, reasonPhrase: ignoredMessage) for (key, value) in ignoredAttributes { span.setAttribute(key: key, value: value) } @@ -91,7 +89,6 @@ final class OTelSpanTests: XCTestCase { XCTAssertEqual(recordedSpan.resource, name) XCTAssertEqual(recordedSpan.operationName, name) let expectedTags = [ - "http.status_code": "200", "key": "value", "span.kind": "client", ] From dec5b26e280eec622e2e19e5f61cca22607c40d3 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Thu, 4 Jan 2024 09:47:28 +0100 Subject: [PATCH 09/13] RUM-1836 feat(otel-tracer): handle attribute cases one by one --- .../Sources/OpenTelemetry/OTelSpan.swift | 22 +++++++++++++++++++ .../Tests/OpenTelemetry/OTelSpanTests.swift | 9 -------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift index d08f82f5ca..09820d5424 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift @@ -117,6 +117,28 @@ internal class OTelSpan: OpenTelemetryApi.Span { // Attributes maps to tags in Datadog for (key, value) in attributes { + switch value { + case .string(let value): + nestedSpan.setTag(key: key, value: value) + case .bool(let value): + nestedSpan.setTag(key: key, value: value.description) + case .int(let value): + nestedSpan.setTag(key: key, value: value.description) + case .double(let value): + nestedSpan.setTag(key: key, value: value.description) + // swiftlint:disable unavailable_function + case .stringArray: + fatalError("Not implemented yet") + case .boolArray: + fatalError("Not implemented yet") + case .intArray: + fatalError("Not implemented yet") + case .doubleArray: + fatalError("Not implemented yet") + case .set: + fatalError("Not implemented yet") + // swiftlint:enable unavailable_function + } nestedSpan.setTag(key: key, value: value.description) } diff --git a/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift index 18f85f263f..55b799e80d 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift @@ -55,7 +55,6 @@ final class OTelSpanTests: XCTestCase { func testSpanEnd() { // Given let (name, ignoredName) = ("trueName", "invalidName") - let (message, ignoredMessage) = ("message", "ignoredMessage") let (attributes, ignoredAttributes) = (["key": "value"], ["ignoredKey": "ignoredValue"]) @@ -183,10 +182,6 @@ final class OTelSpanTests: XCTestCase { span.setAttribute(key: "key2", value: .string("value2")) span.setAttribute(key: "key3", value: .int(3)) span.setAttribute(key: "key4", value: .double(4.0)) - span.setAttribute(key: "key5", value: .stringArray(["value5", "value6"])) - span.setAttribute(key: "key6", value: .intArray([6, 7])) - span.setAttribute(key: "key7", value: .doubleArray([7.0, 8.0])) - span.setAttribute(key: "key8", value: .boolArray([true, false])) span.end() @@ -201,10 +196,6 @@ final class OTelSpanTests: XCTestCase { "key2": "value2", "key3": "3", "key4": "4.0", - "key5": "[\"value5\", \"value6\"]", - "key6": "[6, 7]", - "key7": "[7.0, 8.0]", - "key8": "[true, false]", "span.kind": "client", ] XCTAssertTagsEqual(recordedSpan.tags, expectedTags) From c0450520d1bb609ea75cd2e0bc003bc1f59baa42 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Thu, 4 Jan 2024 09:53:01 +0100 Subject: [PATCH 10/13] RUM-1836 feat(otel-tracer): remove unused variables --- DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift index 55b799e80d..57b81701c1 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift @@ -55,7 +55,6 @@ final class OTelSpanTests: XCTestCase { func testSpanEnd() { // Given let (name, ignoredName) = ("trueName", "invalidName") - let (message, ignoredMessage) = ("message", "ignoredMessage") let (attributes, ignoredAttributes) = (["key": "value"], ["ignoredKey": "ignoredValue"]) let writeSpanExpectation = expectation(description: "write span event") From a53814ee93d24d146f1f852f8977e691ecc12843 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Fri, 5 Jan 2024 13:24:34 +0100 Subject: [PATCH 11/13] RUM-1836 feat(otel-tracer): PR feedback --- DatadogTrace/Sources/DDNoOps.swift | 2 +- DatadogTrace/Sources/DatadogTracer.swift | 2 +- .../{OTelNoOpSpan.swift => NOPOTelSpan.swift} | 2 +- ...Builder.swift => NOPOTelSpanBuilder.swift} | 4 +- .../Sources/OpenTelemetry/OTelSpan.swift | 95 ++++++++++++------- .../Tests/OpenTelemetry/OTelSpanTests.swift | 71 ++++++-------- 6 files changed, 94 insertions(+), 82 deletions(-) rename DatadogTrace/Sources/OpenTelemetry/{OTelNoOpSpan.swift => NOPOTelSpan.swift} (97%) rename DatadogTrace/Sources/OpenTelemetry/{OTelNoOpSpanBuilder.swift => NOPOTelSpanBuilder.swift} (94%) diff --git a/DatadogTrace/Sources/DDNoOps.swift b/DatadogTrace/Sources/DDNoOps.swift index b39f818020..85730d6e51 100644 --- a/DatadogTrace/Sources/DDNoOps.swift +++ b/DatadogTrace/Sources/DDNoOps.swift @@ -50,7 +50,7 @@ internal class DDNoopTracer: OTTracer, OpenTelemetryApi.Tracer { func spanBuilder(spanName: String) -> OpenTelemetryApi.SpanBuilder { warn() - return OTelNoOpSpanBuilder() + return NOPOTelSpanBuilder() } } diff --git a/DatadogTrace/Sources/DatadogTracer.swift b/DatadogTrace/Sources/DatadogTracer.swift index cb371aa813..ceb9c5b3b9 100644 --- a/DatadogTrace/Sources/DatadogTracer.swift +++ b/DatadogTrace/Sources/DatadogTracer.swift @@ -8,7 +8,7 @@ import Foundation import DatadogInternal import OpenTelemetryApi -internal class DatadogTracer: OTTracer, OpenTelemetryApi.Tracer { +internal final class DatadogTracer: OTTracer, OpenTelemetryApi.Tracer { internal weak var core: DatadogCoreProtocol? /// Global tags configured for Trace feature. diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift b/DatadogTrace/Sources/OpenTelemetry/NOPOTelSpan.swift similarity index 97% rename from DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift rename to DatadogTrace/Sources/OpenTelemetry/NOPOTelSpan.swift index 8bd29b4e44..76e2705483 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/NOPOTelSpan.swift @@ -7,7 +7,7 @@ import Foundation import OpenTelemetryApi -internal class OTelNoOpSpan: Span { +internal class NOPOTelSpan: Span { var kind: OpenTelemetryApi.SpanKind = .internal var name: String = "" diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift b/DatadogTrace/Sources/OpenTelemetry/NOPOTelSpanBuilder.swift similarity index 94% rename from DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift rename to DatadogTrace/Sources/OpenTelemetry/NOPOTelSpanBuilder.swift index b4b0c4560d..d20796a70a 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpanBuilder.swift +++ b/DatadogTrace/Sources/OpenTelemetry/NOPOTelSpanBuilder.swift @@ -7,10 +7,10 @@ import Foundation import OpenTelemetryApi -internal class OTelNoOpSpanBuilder: SpanBuilder { +internal class NOPOTelSpanBuilder: SpanBuilder { @discardableResult func startSpan() -> Span { - return OTelNoOpSpan() + return NOPOTelSpan() } @discardableResult diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift index 09820d5424..a4091a3ad9 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift @@ -19,7 +19,7 @@ internal class OTelSpan: OpenTelemetryApi.Span { var attributes: [String: OpenTelemetryApi.AttributeValue] let context: OpenTelemetryApi.SpanContext var kind: OpenTelemetryApi.SpanKind - let nestedSpan: DDSpan + let ddSpan: DDSpan let tracer: DatadogTracer let queue: DispatchQueue @@ -50,7 +50,7 @@ internal class OTelSpan: OpenTelemetryApi.Span { } _name = newValue } - nestedSpan.setOperationName(name) + ddSpan.setOperationName(name) } } @@ -72,7 +72,7 @@ internal class OTelSpan: OpenTelemetryApi.Span { self.isRecording = true self.queue = tracer.queue self.tracer = tracer - self.nestedSpan = .init( + self.ddSpan = .init( tracer: tracer, context: .init( traceID: context.traceId.toDatadog(), @@ -109,43 +109,64 @@ internal class OTelSpan: OpenTelemetryApi.Span { } func end(time: Date) { + let semaphore = DispatchSemaphore(value: 0) + var ended = false + var tags: [String: String] = [:] + queue.sync { guard isRecording else { + ended = true + semaphore.signal() return } isRecording = false + tags = makeTags() + semaphore.signal() + } + semaphore.wait() - // Attributes maps to tags in Datadog - for (key, value) in attributes { - switch value { - case .string(let value): - nestedSpan.setTag(key: key, value: value) - case .bool(let value): - nestedSpan.setTag(key: key, value: value.description) - case .int(let value): - nestedSpan.setTag(key: key, value: value.description) - case .double(let value): - nestedSpan.setTag(key: key, value: value.description) - // swiftlint:disable unavailable_function - case .stringArray: - fatalError("Not implemented yet") - case .boolArray: - fatalError("Not implemented yet") - case .intArray: - fatalError("Not implemented yet") - case .doubleArray: - fatalError("Not implemented yet") - case .set: - fatalError("Not implemented yet") - // swiftlint:enable unavailable_function - } - nestedSpan.setTag(key: key, value: value.description) - } + // if the span was already ended before, we don't want to end it again + guard !ended else { + return + } + + // There is no need to lock here, because `DDSpan` is thread-safe + for (key, value) in tags { + ddSpan.setTag(key: key, value: value) + } + + // SpanKind maps to the `span.kind` tag in Datadog + ddSpan.setTag(key: DatadogTagKeys.spanKind.rawValue, value: kind.rawValue) + ddSpan.finish(at: time) + } - // SpanKind maps to the `span.kind` tag in Datadog - nestedSpan.setTag(key: DatadogTagKeys.spanKind.rawValue, value: kind.rawValue) + private func makeTags() -> [String: String] { + var tags = [String: String]() + for (key, value) in attributes { + switch value { + case .string(let value): + tags[key] = value + case .bool(let value): + tags[key] = value.description + case .int(let value): + tags[key] = value.description + case .double(let value): + tags[key] = value.description + // swiftlint:disable unavailable_function + case .stringArray: + fatalError("Not implemented yet") + case .boolArray: + fatalError("Not implemented yet") + case .intArray: + fatalError("Not implemented yet") + case .doubleArray: + fatalError("Not implemented yet") + case .set: + fatalError("Not implemented yet") + // swiftlint:enable unavailable_function + } } - nestedSpan.finish(at: time) + return tags } var description: String { @@ -153,10 +174,12 @@ internal class OTelSpan: OpenTelemetryApi.Span { } func setAttribute(key: String, value: OpenTelemetryApi.AttributeValue?) { - guard isRecording else { - return - } + queue.sync { + guard isRecording else { + return + } - attributes[key] = value + attributes[key] = value + } } } diff --git a/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift index 57b81701c1..e5d43d89fd 100644 --- a/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift +++ b/DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift @@ -24,9 +24,9 @@ final class OTelSpanTests: XCTestCase { // Then waitForExpectations(timeout: 0.5, handler: nil) - let events: [SpanEventsEnvelope] = core.events() - XCTAssertEqual(events.count, 1) - let recordedSpan = events.first!.spans.first! + let recordedSpans = core.spans() + XCTAssertEqual(recordedSpans.count, 1) + let recordedSpan = recordedSpans.first! XCTAssertEqual(recordedSpan.resource, "OperationName") XCTAssertEqual(recordedSpan.operationName, "OperationName") } @@ -45,9 +45,9 @@ final class OTelSpanTests: XCTestCase { // Then waitForExpectations(timeout: 0.5, handler: nil) - let events: [SpanEventsEnvelope] = core.events() - XCTAssertEqual(events.count, 1) - let recordedSpan = events.first!.spans.first! + let recordedSpans = core.spans() + XCTAssertEqual(recordedSpans.count, 1) + let recordedSpan = recordedSpans.first! XCTAssertEqual(recordedSpan.resource, "NewOperationName") XCTAssertEqual(recordedSpan.operationName, "NewOperationName") } @@ -80,9 +80,9 @@ final class OTelSpanTests: XCTestCase { span.end() waitForExpectations(timeout: 0.5, handler: nil) - let events: [SpanEventsEnvelope] = core.events() - XCTAssertEqual(events.count, 1) - let recordedSpan = events.first!.spans.first! + let recordedSpans = core.spans() + XCTAssertEqual(recordedSpans.count, 1) + let recordedSpan = recordedSpans.first! XCTAssertEqual(recordedSpan.resource, name) XCTAssertEqual(recordedSpan.operationName, name) @@ -90,7 +90,7 @@ final class OTelSpanTests: XCTestCase { "key": "value", "span.kind": "client", ] - XCTAssertTagsEqual(recordedSpan.tags, expectedTags) + DDAssertDictionariesEqual(recordedSpan.tags, expectedTags) } func testSetParentSpan() { @@ -110,10 +110,10 @@ final class OTelSpanTests: XCTestCase { // Then waitForExpectations(timeout: 0.5, handler: nil) - let events: [SpanEventsEnvelope] = core.events() - XCTAssertEqual(events.count, 2) - let child = events.first!.spans.first! - let parent = events.last!.spans.first! + let recordedSpans = core.spans() + XCTAssertEqual(recordedSpans.count, 2) + let child = recordedSpans.first! + let parent = recordedSpans.last! XCTAssertEqual(parent.parentID, nil) XCTAssertEqual(child.parentID, parent.spanID) } @@ -135,10 +135,10 @@ final class OTelSpanTests: XCTestCase { // Then waitForExpectations(timeout: 0.5, handler: nil) - let events: [SpanEventsEnvelope] = core.events() - XCTAssertEqual(events.count, 2) - let child = events.first!.spans.first! - let parent = events.last!.spans.first! + let recordedSpans = core.spans() + XCTAssertEqual(recordedSpans.count, 2) + let child = recordedSpans.first! + let parent = recordedSpans.last! XCTAssertEqual(parent.parentID, nil) XCTAssertEqual(child.parentID, parent.spanID) } @@ -160,10 +160,10 @@ final class OTelSpanTests: XCTestCase { // Then waitForExpectations(timeout: 0.5, handler: nil) - let events: [SpanEventsEnvelope] = core.events() - XCTAssertEqual(events.count, 2) - let child = events.first!.spans.first! - let parent = events.last!.spans.first! + let recordedSpans = core.spans() + XCTAssertEqual(recordedSpans.count, 2) + let child = recordedSpans.first! + let parent = recordedSpans.last! XCTAssertEqual(parent.parentID, nil) XCTAssertEqual(child.parentID, nil) } @@ -186,9 +186,9 @@ final class OTelSpanTests: XCTestCase { // Then waitForExpectations(timeout: 0.5, handler: nil) - let events: [SpanEventsEnvelope] = core.events() - XCTAssertEqual(events.count, 1) - let recordedSpan = events.first!.spans.first! + let recordedSpans = core.spans() + XCTAssertEqual(recordedSpans.count, 1) + let recordedSpan = recordedSpans.first! let expectedTags = [ "key": "true", @@ -197,24 +197,13 @@ final class OTelSpanTests: XCTestCase { "key4": "4.0", "span.kind": "client", ] - XCTAssertTagsEqual(recordedSpan.tags, expectedTags) + DDAssertDictionariesEqual(recordedSpan.tags, expectedTags) } } -func XCTAssertTagsEqual( - _ dict1: [String: String], - _ dict2: [String: String], - file: StaticString = #filePath, - line: UInt = #line -) { - XCTAssertEqual(dict1.count, dict2.count, file: file, line: line) - for (key, value) in dict1 { - XCTAssertEqual( - dict2[key], - value, - "Expected \(key) to be \(value), but was \(String(describing: dict2[key]))", - file: file, - line: line - ) +extension PassthroughCoreMock { + func spans() -> [SpanEvent] { + let events: [SpanEventsEnvelope] = self.events() + return events.flatMap { $0.spans } } } From 140c95b19c45c4a884d8ba138aae85e28fc9ffcf Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Fri, 5 Jan 2024 13:31:43 +0100 Subject: [PATCH 12/13] RUM-1836 feat(otel-tracer): corresponding reference change of rename --- Datadog/Datadog.xcodeproj/project.pbxproj | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Datadog/Datadog.xcodeproj/project.pbxproj b/Datadog/Datadog.xcodeproj/project.pbxproj index 06da6fee37..99d61151a3 100644 --- a/Datadog/Datadog.xcodeproj/project.pbxproj +++ b/Datadog/Datadog.xcodeproj/project.pbxproj @@ -36,16 +36,12 @@ 3C41693C29FBF4D50042B9D2 /* DatadogWebViewTracking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CE119FE29F7BE0100202522 /* DatadogWebViewTracking.framework */; }; 3C6C7FDB2B45738C006F5CBC /* OpenTelemetryApi in Frameworks */ = {isa = PBXBuildFile; productRef = 3C6C7FDA2B45738C006F5CBC /* OpenTelemetryApi */; }; 3C6C7FDD2B457392006F5CBC /* OpenTelemetryApi in Frameworks */ = {isa = PBXBuildFile; productRef = 3C6C7FDC2B457392006F5CBC /* OpenTelemetryApi */; }; - 3C6C7FE52B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */; }; - 3C6C7FE62B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */; }; 3C6C7FE72B459AAA006F5CBC /* OTelSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */; }; 3C6C7FE82B459AAA006F5CBC /* OTelSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */; }; 3C6C7FE92B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */; }; 3C6C7FEA2B459AAA006F5CBC /* OTelSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */; }; 3C6C7FEB2B459AAA006F5CBC /* OTelTraceId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE22B459AAA006F5CBC /* OTelTraceId+Datadog.swift */; }; 3C6C7FEC2B459AAA006F5CBC /* OTelTraceId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE22B459AAA006F5CBC /* OTelTraceId+Datadog.swift */; }; - 3C6C7FED2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */; }; - 3C6C7FEE2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */; }; 3C6C7FEF2B459AAA006F5CBC /* OTelSpanId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE42B459AAA006F5CBC /* OTelSpanId+Datadog.swift */; }; 3C6C7FF02B459AAA006F5CBC /* OTelSpanId+Datadog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FE42B459AAA006F5CBC /* OTelSpanId+Datadog.swift */; }; 3C6C7FFB2B459AF6006F5CBC /* OTelSpanId+DatadogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6C7FF22B459AB3006F5CBC /* OTelSpanId+DatadogTests.swift */; }; @@ -60,6 +56,10 @@ 3C85D42C29F7C87D00AFF894 /* HostsSanitizerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C85D42B29F7C87D00AFF894 /* HostsSanitizerMock.swift */; }; 3C85D42D29F7C87D00AFF894 /* HostsSanitizerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C85D42B29F7C87D00AFF894 /* HostsSanitizerMock.swift */; }; 3C9C6BB429F7C0C000581C43 /* DatadogInternal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D23039A5298D513C001A1FA3 /* DatadogInternal.framework */; }; + 3CB012DD2B482E0400557951 /* NOPOTelSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB012DB2B482E0400557951 /* NOPOTelSpan.swift */; }; + 3CB012DE2B482E0400557951 /* NOPOTelSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB012DB2B482E0400557951 /* NOPOTelSpan.swift */; }; + 3CB012DF2B482E0400557951 /* NOPOTelSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB012DC2B482E0400557951 /* NOPOTelSpanBuilder.swift */; }; + 3CB012E02B482E0400557951 /* NOPOTelSpanBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB012DC2B482E0400557951 /* NOPOTelSpanBuilder.swift */; }; 3CB32AD42ACB733000D602ED /* URLSessionSwizzler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB32AD32ACB733000D602ED /* URLSessionSwizzler.swift */; }; 3CB32AD52ACB733000D602ED /* URLSessionSwizzler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB32AD32ACB733000D602ED /* URLSessionSwizzler.swift */; }; 3CB32AD72ACB735600D602ED /* URLSessionSwizzlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB32AD62ACB735600D602ED /* URLSessionSwizzlerTests.swift */; }; @@ -1900,17 +1900,17 @@ 3C2206F22AB9CE9300DE780C /* MetaTypeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetaTypeExtensions.swift; sourceTree = ""; }; 3C394EF62AA5F49F008F48BA /* URLSessionDataDelegateSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionDataDelegateSwizzler.swift; sourceTree = ""; }; 3C394EF92AA5F4C8008F48BA /* URLSessionDataDelegateSwizzlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionDataDelegateSwizzlerTests.swift; sourceTree = ""; }; - 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelNoOpSpanBuilder.swift; sourceTree = ""; }; 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelSpan.swift; sourceTree = ""; }; 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelSpanBuilder.swift; sourceTree = ""; }; 3C6C7FE22B459AAA006F5CBC /* OTelTraceId+Datadog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OTelTraceId+Datadog.swift"; sourceTree = ""; }; - 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelNoOpSpan.swift; sourceTree = ""; }; 3C6C7FE42B459AAA006F5CBC /* OTelSpanId+Datadog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OTelSpanId+Datadog.swift"; sourceTree = ""; }; 3C6C7FF22B459AB3006F5CBC /* OTelSpanId+DatadogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OTelSpanId+DatadogTests.swift"; sourceTree = ""; }; 3C6C7FF32B459AB3006F5CBC /* OTelTraceId+DatadogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OTelTraceId+DatadogTests.swift"; sourceTree = ""; }; 3C6C7FF42B459AB3006F5CBC /* OTelSpanTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OTelSpanTests.swift; sourceTree = ""; }; 3C85D41429F7C59C00AFF894 /* WebViewTracking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewTracking.swift; sourceTree = ""; }; 3C85D42B29F7C87D00AFF894 /* HostsSanitizerMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HostsSanitizerMock.swift; sourceTree = ""; }; + 3CB012DB2B482E0400557951 /* NOPOTelSpan.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NOPOTelSpan.swift; sourceTree = ""; }; + 3CB012DC2B482E0400557951 /* NOPOTelSpanBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NOPOTelSpanBuilder.swift; sourceTree = ""; }; 3CB32AD32ACB733000D602ED /* URLSessionSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionSwizzler.swift; sourceTree = ""; }; 3CB32AD62ACB735600D602ED /* URLSessionSwizzlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionSwizzlerTests.swift; sourceTree = ""; }; 3CBDE66D2AA08BF600F6A7B6 /* URLSessionTaskDelegateSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTaskDelegateSwizzler.swift; sourceTree = ""; }; @@ -3114,11 +3114,11 @@ 3C6C7FDE2B459AAA006F5CBC /* OpenTelemetry */ = { isa = PBXGroup; children = ( - 3C6C7FDF2B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift */, + 3CB012DB2B482E0400557951 /* NOPOTelSpan.swift */, + 3CB012DC2B482E0400557951 /* NOPOTelSpanBuilder.swift */, 3C6C7FE02B459AAA006F5CBC /* OTelSpan.swift */, 3C6C7FE12B459AAA006F5CBC /* OTelSpanBuilder.swift */, 3C6C7FE22B459AAA006F5CBC /* OTelTraceId+Datadog.swift */, - 3C6C7FE32B459AAA006F5CBC /* OTelNoOpSpan.swift */, 3C6C7FE42B459AAA006F5CBC /* OTelSpanId+Datadog.swift */, ); path = OpenTelemetry; @@ -8327,9 +8327,8 @@ D2C1A50C29C4C4CB00946C31 /* DDNoOps.swift in Sources */, D2C1A4FC29C4C4CB00946C31 /* RequestBuilder.swift in Sources */, D2C1A50D29C4C4CB00946C31 /* SpanTagsReducer.swift in Sources */, + 3CB012DD2B482E0400557951 /* NOPOTelSpan.swift in Sources */, D2C1A51A29C4C5DD00946C31 /* JSONEncoder.swift in Sources */, - 3C6C7FED2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */, - 3C6C7FE52B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */, D2C1A51829C4C53F00946C31 /* OTSpan.swift in Sources */, D2C1A51429C4C53F00946C31 /* OTSpanContext.swift in Sources */, 3C6C7FEB2B459AAA006F5CBC /* OTelTraceId+Datadog.swift in Sources */, @@ -8340,6 +8339,7 @@ 61A2CC362A44B0A20000FF25 /* TraceConfiguration.swift in Sources */, 61A2CC392A44B0EA0000FF25 /* Trace.swift in Sources */, D2C1A50029C4C4CB00946C31 /* ActiveSpansPool.swift in Sources */, + 3CB012DF2B482E0400557951 /* NOPOTelSpanBuilder.swift in Sources */, D2C1A50929C4C4CB00946C31 /* SpanEventEncoder.swift in Sources */, 3C6C7FE72B459AAA006F5CBC /* OTelSpan.swift in Sources */, D2C1A4FE29C4C4CB00946C31 /* SpanEventMapper.swift in Sources */, @@ -8525,9 +8525,8 @@ D2C1A53929C4F2DF00946C31 /* DDNoOps.swift in Sources */, D2C1A53A29C4F2DF00946C31 /* RequestBuilder.swift in Sources */, D2C1A53B29C4F2DF00946C31 /* SpanTagsReducer.swift in Sources */, + 3CB012DE2B482E0400557951 /* NOPOTelSpan.swift in Sources */, D2C1A53C29C4F2DF00946C31 /* JSONEncoder.swift in Sources */, - 3C6C7FEE2B459AAA006F5CBC /* OTelNoOpSpan.swift in Sources */, - 3C6C7FE62B459AAA006F5CBC /* OTelNoOpSpanBuilder.swift in Sources */, D2C1A53D29C4F2DF00946C31 /* OTSpan.swift in Sources */, D2C1A53E29C4F2DF00946C31 /* OTSpanContext.swift in Sources */, 3C6C7FEC2B459AAA006F5CBC /* OTelTraceId+Datadog.swift in Sources */, @@ -8538,6 +8537,7 @@ 61A2CC372A44B0A20000FF25 /* TraceConfiguration.swift in Sources */, 61A2CC3A2A44B0EA0000FF25 /* Trace.swift in Sources */, D2C1A54229C4F2DF00946C31 /* ActiveSpansPool.swift in Sources */, + 3CB012E02B482E0400557951 /* NOPOTelSpanBuilder.swift in Sources */, D2C1A54329C4F2DF00946C31 /* SpanEventEncoder.swift in Sources */, 3C6C7FE82B459AAA006F5CBC /* OTelSpan.swift in Sources */, D2C1A54429C4F2DF00946C31 /* SpanEventMapper.swift in Sources */, From 2eab9ac10d14144069ed6360fa2003b33413c5d4 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Fri, 5 Jan 2024 17:18:41 +0100 Subject: [PATCH 13/13] RUM-1836 feat(otel-tracer): remove semaphore usage --- DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift index a4091a3ad9..1ffcc037f0 100644 --- a/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift +++ b/DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift @@ -109,21 +109,17 @@ internal class OTelSpan: OpenTelemetryApi.Span { } func end(time: Date) { - let semaphore = DispatchSemaphore(value: 0) var ended = false var tags: [String: String] = [:] queue.sync { guard isRecording else { ended = true - semaphore.signal() return } isRecording = false tags = makeTags() - semaphore.signal() } - semaphore.wait() // if the span was already ended before, we don't want to end it again guard !ended else {