Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.19.0 #1267

Merged
merged 18 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be 1.19.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nooo! CI just passed!!


- [BUGFIX] Fix view attributes override by action attributes. See [#1250][]
- [IMPROVEMENT] Add Tracer sampling rate. See [#1259][]
- [BUGFIX] Fix RUM context not being attached to log when no user action exists. See [#1264][]

# 1.18.0 / 19-04-2023
- [IMPROVEMENT] Add start reason to the session. See [#1247][]
- [IMPROVEMENT] Add ability to stop the session. See [#1219][]
Expand Down Expand Up @@ -452,6 +456,9 @@
[#1219]: https://github.com/DataDog/dd-sdk-ios/pull/1219
[#1220]: https://github.com/DataDog/dd-sdk-ios/pull/1220
[#1247]: https://github.com/DataDog/dd-sdk-ios/pull/1247
[#1250]: https://github.com/DataDog/dd-sdk-ios/pull/1250
[#1259]: https://github.com/DataDog/dd-sdk-ios/pull/1259
[#1264]: https://github.com/DataDog/dd-sdk-ios/pull/1264
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
[@hengyu]: https://github.com/Hengyu
Expand Down
2 changes: 1 addition & 1 deletion DatadogSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "DatadogSDK"
s.module_name = "Datadog"
s.version = "1.18.0"
s.version = "1.19.0"
s.summary = "Official Datadog Swift SDK for iOS."

s.homepage = "https://www.datadoghq.com"
Expand Down
2 changes: 1 addition & 1 deletion DatadogSDKAlamofireExtension.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "DatadogSDKAlamofireExtension"
s.module_name = "DatadogAlamofireExtension"
s.version = "1.18.0"
s.version = "1.19.0"
s.summary = "An Official Extensions of Datadog Swift SDK for Alamofire."

s.homepage = "https://www.datadoghq.com"
Expand Down
4 changes: 2 additions & 2 deletions DatadogSDKCrashReporting.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "DatadogSDKCrashReporting"
s.module_name = "DatadogCrashReporting"
s.version = "1.18.0"
s.version = "1.19.0"
s.summary = "Official Datadog Crash Reporting SDK for iOS."

s.homepage = "https://www.datadoghq.com"
Expand All @@ -22,6 +22,6 @@ Pod::Spec.new do |s|
s.static_framework = true

s.source_files = "Sources/DatadogCrashReporting/**/*.swift"
s.dependency 'DatadogSDK', '1.18.0'
s.dependency 'DatadogSDK', '1.19.0'
s.dependency 'PLCrashReporter', '~> 1.11.0'
end
4 changes: 2 additions & 2 deletions DatadogSDKObjc.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "DatadogSDKObjc"
s.module_name = "DatadogObjc"
s.version = "1.18.0"
s.version = "1.19.0"
s.summary = "Official Datadog Objective-C SDK for iOS."

s.homepage = "https://www.datadoghq.com"
Expand All @@ -21,5 +21,5 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/DataDog/dd-sdk-ios.git', :tag => s.version.to_s }

s.source_files = "Sources/DatadogObjc/**/*.swift"
s.dependency 'DatadogSDK', '1.18.0'
s.dependency 'DatadogSDK', '1.19.0'
end
2 changes: 1 addition & 1 deletion DatadogSDKSessionReplay.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "DatadogSDKSessionReplay"
s.module_name = "DatadogSessionReplay"
s.version = "1.18.0"
s.version = "1.19.0"
s.summary = "Official Datadog Session Replay SDK for iOS. This module is currently in beta - contact Datadog to request a try."

s.homepage = "https://www.datadoghq.com"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand Down Expand Up @@ -79,7 +80,7 @@
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="5e8-XJ-d05">
<rect key="frame" x="20" y="79" width="353" height="261.33333333333331"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nE2-nF-tR0">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nE2-nF-tR0">
<rect key="frame" x="0.0" y="0.0" width="353" height="36"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="30"/>
Expand All @@ -93,7 +94,7 @@
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zGs-5s-YfK">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="right" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zGs-5s-YfK">
<rect key="frame" x="0.0" y="100.00000000000001" width="353" height="161.33333333333337"/>
<string key="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</string>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,21 @@ internal class WireframesBuilder {
cornerRadius: CGFloat? = nil,
opacity: CGFloat? = nil
) -> SRWireframe {
var textPosition: SRTextPosition? = nil

if let textFrame = textFrame {
textPosition = .init(
alignment: textAlignment,
padding: .init(
bottom: Int64(withNoOverflow: frame.maxY - textFrame.maxY),
left: Int64(withNoOverflow: textFrame.minX - frame.minX),
right: Int64(withNoOverflow: frame.maxX - textFrame.maxX),
top: Int64(withNoOverflow: textFrame.minY - frame.minY)
)
let textFrame = textFrame ?? frame
let textPosition = SRTextPosition(
alignment: textAlignment,
padding: .init(
bottom: Int64(withNoOverflow: frame.maxY - textFrame.maxY),
left: Int64(withNoOverflow: textFrame.minX - frame.minX),
right: Int64(withNoOverflow: frame.maxX - textFrame.maxX),
top: Int64(withNoOverflow: textFrame.minY - frame.minY)
)
}
)

var fontSize = Int64(withNoOverflow: font?.pointSize ?? Fallback.fontSize)
if let boundingBox = textFrame?.size, text.count > 0, fontScalingEnabled {
if text.count > 0, fontScalingEnabled {
// Calculates the approximate font size for available text area √(frameArea / numberOfCharacters)
let area = boundingBox.width * boundingBox.height
let area = textFrame.width * textFrame.height
let calculatedFontSize = Int64(sqrt(area / CGFloat(text.count)))
if calculatedFontSize < fontSize {
fontSize = calculatedFontSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,15 @@ internal class UILabelRecorder: NodeRecorder {
return InvisibleElement.constant
}

// The actual frame of the text, which is smaller than the frame of the label:
let textFrame = CGRect(
x: attributes.frame.minX,
y: attributes.frame.minY + (attributes.frame.height - attributes.intrinsicContentSize.height) * 0.5,
width: attributes.intrinsicContentSize.width,
height: attributes.intrinsicContentSize.height
)

let builder = UILabelWireframesBuilder(
wireframeID: context.ids.nodeID(for: label),
attributes: attributes,
text: label.text ?? "",
textColor: label.textColor?.cgColor,
textAlignment: nil,
textAlignment: label.textAlignment,
font: label.font,
fontScalingEnabled: label.adjustsFontSizeToFitWidth,
textObfuscator: textObfuscator(context),
wireframeRect: textFrame
textObfuscator: textObfuscator(context)
)
let node = Node(viewAttributes: attributes, wireframesBuilder: builderOverride(builder))
return SpecificElement(subtreeStrategy: .ignore, nodes: [node])
Expand All @@ -69,24 +60,25 @@ internal struct UILabelWireframesBuilder: NodeWireframesBuilder {
/// The color of the text.
var textColor: CGColor?
/// The alignment of the text.
var textAlignment: SRTextPosition.Alignment?
var textAlignment: NSTextAlignment
/// The font used by the label.
let font: UIFont?
/// Flag that determines if font should be scaled
var fontScalingEnabled: Bool
/// Text obfuscator for masking text.
let textObfuscator: TextObfuscating

let wireframeRect: CGRect
var wireframeRect: CGRect {
attributes.frame
}

func buildWireframes(with builder: WireframesBuilder) -> [SRWireframe] {
return [
builder.createTextWireframe(
id: wireframeID,
frame: attributes.frame,
frame: wireframeRect,
text: textObfuscator.mask(text: text),
textFrame: wireframeRect,
textAlignment: textAlignment,
textAlignment: .init(systemTextAlignment: textAlignment),
textColor: textColor,
font: font,
fontScalingEnabled: fontScalingEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal struct UIPickerViewRecorder: NodeRecorder {
UILabelRecorder(
builderOverride: { builder in
var builder = builder
builder.textAlignment = .init(horizontal: .center, vertical: .center)
builder.textAlignment = .center
builder.fontScalingEnabled = true
return builder
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,13 @@ internal struct UITextFieldWireframesBuilder: NodeWireframesBuilder {
let textObfuscator: TextObfuscating

func buildWireframes(with builder: WireframesBuilder) -> [SRWireframe] {
let horizontalAlignment: SRTextPosition.Alignment.Horizontal? = {
switch textAlignment {
case .left: return .left
case .center: return .center
case .right: return .right
default: return nil
}
}()

return [
builder.createTextWireframe(
id: wireframeID,
frame: wireframeRect,
text: textObfuscator.mask(text: text),
textFrame: wireframeRect,
textAlignment: .init(horizontal: horizontalAlignment, vertical: .center),
textAlignment: .init(systemTextAlignment: textAlignment),
textColor: isPlaceholderText ? SystemColors.placeholderText : textColor,
font: font,
fontScalingEnabled: fontScalingEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal struct UITextViewRecorder: NodeRecorder {
wireframeID: context.ids.nodeID(for: textView),
attributes: attributes,
text: textView.text,
textAlignment: textView.textAlignment,
textColor: textView.textColor?.cgColor ?? UIColor.black.cgColor,
font: textView.font,
textObfuscator: textObfuscator(context, isSensitiveText),
Expand All @@ -49,6 +50,8 @@ internal struct UITextViewWireframesBuilder: NodeWireframesBuilder {
let attributes: ViewAttributes
/// The text inside text field.
let text: String
/// The alignment of the text.
var textAlignment: NSTextAlignment
/// The color of the text.
let textColor: CGColor?
/// The font used by the text field.
Expand Down Expand Up @@ -90,6 +93,7 @@ internal struct UITextViewWireframesBuilder: NodeWireframesBuilder {
id: wireframeID,
frame: relativeIntersectedRect,
text: textObfuscator.mask(text: text),
textAlignment: .init(systemTextAlignment: textAlignment, vertical: .top),
clip: clip,
textColor: textColor,
font: font,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 UIKit

extension SRTextPosition.Alignment {
/// Custom initializer that allows transforming UIKit's `NSTextAlignment` into `SRTextPosition.Alignment`.
init(
systemTextAlignment: NSTextAlignment,
vertical: SRTextPosition.Alignment.Vertical = .center
) {
self.vertical = vertical
switch systemTextAlignment {
case .left:
self.horizontal = .left
case .center:
self.horizontal = .center
case .right:
self.horizontal = .right
case .justified:
self.horizontal = .left
case .natural:
self.horizontal = .left
@unknown default:
self.horizontal = .left
}
}
}
4 changes: 2 additions & 2 deletions Sources/Datadog/Logging/RemoteLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ internal final class RemoteLogger: LoggerProtocol {
var internalAttributes: [String: Encodable] = [:]
let contextAttributes = context.featuresAttributes

if self.rumContextIntegration, let attributes: [String: String] = contextAttributes["rum"]?.ids {
let attributes = attributes.compactMapValues(AnyEncodable.init)
if self.rumContextIntegration, let attributes: [String: AnyCodable?] = contextAttributes["rum"]?.ids {
let attributes = attributes.compactMapValues { $0 }
internalAttributes.merge(attributes) { $1 }
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/Datadog/Tracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class Tracer: OTTracer {

internal let activeSpansPool = ActiveSpansPool()

internal let sampler: Sampler

/// Tracer Attributes shared with other Feature registered in core.
internal struct Attributes {
internal static let traceID = "dd.trace_id"
Expand Down Expand Up @@ -146,6 +148,7 @@ public class Tracer: OTTracer {
self.dateProvider = dateProvider
self.rumIntegration = rumIntegration
self.loggingIntegration = loggingIntegration
self.sampler = Sampler(samplingRate: configuration.samplingRate)
}

// MARK: - Open Tracing interface
Expand Down
5 changes: 5 additions & 0 deletions Sources/Datadog/TracerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ extension Tracer {
/// - Parameter enabled: `true` by default
public var bundleWithRUM: Bool

/// TRhe sampling rate for Traces, as a Float between 0 and 100.
public var samplingRate: Float

/// Initializes the Datadog Tracer configuration.
/// - Parameter serviceName: the service name that will appear in traces (if not provided or `nil`, the SDK default `serviceName` will be used).
/// - Parameter sendNetworkInfo: adds network connection info to every span and span logs (`false` by default).
Expand All @@ -37,11 +40,13 @@ extension Tracer {
serviceName: String? = nil,
sendNetworkInfo: Bool = false,
bundleWithRUM: Bool = true,
samplingRate: Float = 100,
globalTags: [String: Encodable]? = nil
) {
self.serviceName = serviceName
self.sendNetworkInfo = sendNetworkInfo
self.bundleWithRUM = bundleWithRUM
self.samplingRate = samplingRate
self.globalTags = globalTags
}
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/Datadog/Tracing/DDSpan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ internal class DDSpan: OTSpan {
if let activity = activityReference {
ddTracer.removeSpan(activityReference: activity)
}
sendSpan(finishTime: time)
sendSpan(finishTime: time, sampler: ddTracer.sampler)
}
}

// MARK: - Writing SpanEvent

/// Sends span event for given `DDSpan`.
private func sendSpan(finishTime: Date) {
private func sendSpan(finishTime: Date, sampler: Sampler) {
guard let tracing = ddTracer.core.v1.scope(for: TracingFeature.self) else {
return
}
Expand Down Expand Up @@ -160,6 +160,8 @@ internal class DDSpan: OTSpan {
operationName: self.unsafeOperationName,
startTime: self.startTime,
finishTime: finishTime,
samplingRate: sampler.samplingRate / 100.0,
isKept: sampler.sample(),
tags: self.unsafeTags,
baggageItems: baggageItems,
logFields: self.unsafeLogFields
Expand Down
4 changes: 4 additions & 0 deletions Sources/Datadog/Tracing/Span/SpanEventBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ internal struct SpanEventBuilder {
operationName: String,
startTime: Date,
finishTime: Date,
samplingRate: Float,
isKept: Bool,
tags: [String: Encodable],
baggageItems: [String: String],
logFields: [[String: Encodable]]
Expand Down Expand Up @@ -60,6 +62,8 @@ internal struct SpanEventBuilder {
isError: tagsReducer.extractedIsError ?? false,
source: context.source,
origin: context.ciAppOrigin,
samplingRate: samplingRate,
isKept: isKept,
tracerVersion: context.sdkVersion,
applicationVersion: context.version,
networkConnectionInfo: sendNetworkInfo ? context.networkConnectionInfo : nil,
Expand Down
Loading