Skip to content

Commit 5d858b3

Browse files
Merge pull request #2449 from DataDog/simaoseica/RUM-9494/remove-locales
RUM-9494: Discard locales from span events
2 parents bad2097 + 09410c0 commit 5d858b3

10 files changed

Lines changed: 26 additions & 17 deletions

File tree

DatadogCore/Tests/Datadog/CrashReporting/CrashContext/CrashContextProviderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class CrashContextProviderTests: XCTestCase {
308308
XCTAssertEqual(crashContext.env, sdkContext.env, file: file, line: line)
309309
XCTAssertEqual(crashContext.version, sdkContext.version, file: file, line: line)
310310
XCTAssertEqual(crashContext.buildNumber, sdkContext.buildNumber, file: file, line: line)
311-
DDAssertReflectionEqual(crashContext.device, sdkContext.normalizedDevice, file: file, line: line)
311+
DDAssertReflectionEqual(crashContext.device, sdkContext.normalizedDevice(), file: file, line: line)
312312
DDAssertReflectionEqual(crashContext.os, sdkContext.os, file: file, line: line)
313313
XCTAssertEqual(crashContext.sdkVersion, sdkContext.sdkVersion, file: file, line: line)
314314
XCTAssertEqual(crashContext.source, sdkContext.source, file: file, line: line)

DatadogCore/Tests/Datadog/TracerTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class TracerTests: XCTestCase {
8585
"brand": "Apple",
8686
"brightness_level": 0,
8787
"locale": "en-US",
88-
"locales": ["en"],
8988
"model": "iPhone10,1",
9089
"name": "iPhone",
9190
"power_saving_mode": 0,

DatadogInternal/Sources/Context/DeviceInfo.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,24 +227,34 @@ extension DatadogExtension where ExtendedType == _UIDevice {
227227

228228
extension DatadogContext {
229229
/// Current device information to send in the events.
230-
public var normalizedDevice: Device {
230+
///
231+
/// - Parameter addLocales: Temporary boolean to remove locales from events that don't support array parameters.
232+
/// NOTE: RUM-9494 only basic types (boolean, string, number) are supported for `meta.*` attributes.
233+
///
234+
/// - Returns: The device model for the events.
235+
public func normalizedDevice(addLocales: Bool = true) -> Device {
231236
var battery: Double?
232237
if let batteryLevel = batteryStatus?.level {
233238
battery = Double(batteryLevel)
234239
}
235240

236-
var brightness: Double? = nil
241+
var brightness: Double?
237242
if let brightnessLevel = brightnessLevel {
238243
brightness = Double(brightnessLevel)
239244
}
240245

246+
var locales: [String]?
247+
if addLocales {
248+
locales = localeInfo.locales
249+
}
250+
241251
return .init(
242252
architecture: device.architecture,
243253
batteryLevel: battery,
244254
brand: device.brand,
245255
brightnessLevel: brightness,
246256
locale: localeInfo.currentLocale,
247-
locales: localeInfo.locales,
257+
locales: locales,
248258
model: device.model,
249259
name: device.name,
250260
powerSavingMode: isLowPowerModeEnabled,

DatadogInternal/Sources/Models/CrashReporting/CrashContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public struct CrashContext: Codable, Equatable {
141141
self.env = context.env
142142
self.version = context.version
143143
self.buildNumber = context.buildNumber
144-
self.device = context.normalizedDevice
144+
self.device = context.normalizedDevice()
145145
self.os = context.os
146146
self.sdkVersion = context.sdkVersion
147147
self.source = context.source

DatadogLogs/Sources/Log/LogEventBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal struct LogEventBuilder {
8181
dd: LogEvent.Dd(
8282
device: .init(architecture: context.device.architecture)
8383
),
84-
device: context.normalizedDevice,
84+
device: context.normalizedDevice(),
8585
os: context.os,
8686
userInfo: context.userInfo ?? .empty,
8787
accountInfo: context.accountInfo,

DatadogRUM/Sources/RUMMonitor/Scopes/RUMResourceScope.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ internal class RUMResourceScope: RUMScope {
189189
container: nil,
190190
context: .init(contextInfo: command.globalAttributes.merging(parent.attributes) { $1 }.merging(attributes) { $1 }),
191191
date: resourceStartTime.addingTimeInterval(serverTimeOffset).timeIntervalSince1970.toInt64Milliseconds,
192-
device: context.normalizedDevice,
192+
device: context.normalizedDevice(),
193193
display: nil,
194194
os: context.os,
195195
resource: .init(
@@ -304,7 +304,7 @@ internal class RUMResourceScope: RUMScope {
304304
container: nil,
305305
context: .init(contextInfo: command.globalAttributes.merging(parent.attributes) { $1 }.merging(attributes) { $1 }),
306306
date: command.time.addingTimeInterval(serverTimeOffset).timeIntervalSince1970.toInt64Milliseconds,
307-
device: context.normalizedDevice,
307+
device: context.normalizedDevice(),
308308
display: nil,
309309
error: .init(
310310
binaryImages: nil,

DatadogRUM/Sources/RUMMonitor/Scopes/RUMUserActionScope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ internal class RUMUserActionScope: RUMScope, RUMContextProvider {
181181
container: nil,
182182
context: .init(contextInfo: command.globalAttributes.merging(parent.attributes) { $1 }.merging(attributes) { $1 }),
183183
date: actionStartTime.addingTimeInterval(serverTimeOffset).timeIntervalSince1970.toInt64Milliseconds,
184-
device: context.normalizedDevice,
184+
device: context.normalizedDevice(),
185185
display: nil,
186186
os: context.os,
187187
service: context.service,

DatadogRUM/Sources/RUMMonitor/Scopes/RUMViewScope.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ extension RUMViewScope {
551551
container: nil,
552552
context: .init(contextInfo: commandAttributes),
553553
date: viewStartTime.addingTimeInterval(serverTimeOffset).timeIntervalSince1970.toInt64Milliseconds,
554-
device: context.normalizedDevice,
554+
device: context.normalizedDevice(),
555555
display: nil,
556556
os: context.os,
557557
service: context.service,
@@ -679,7 +679,7 @@ extension RUMViewScope {
679679
container: nil,
680680
context: .init(contextInfo: localAttributes),
681681
date: viewStartTime.addingTimeInterval(serverTimeOffset).timeIntervalSince1970.toInt64Milliseconds,
682-
device: context.normalizedDevice,
682+
device: context.normalizedDevice(),
683683
display: nil,
684684
featureFlags: .init(featureFlagsInfo: featureFlags),
685685
os: context.os,
@@ -825,7 +825,7 @@ extension RUMViewScope {
825825
container: nil,
826826
context: .init(contextInfo: commandAttributes),
827827
date: command.time.addingTimeInterval(serverTimeOffset).timeIntervalSince1970.toInt64Milliseconds,
828-
device: context.normalizedDevice,
828+
device: context.normalizedDevice(),
829829
display: nil,
830830
error: .init(
831831
binaryImages: binaryImages,
@@ -912,7 +912,7 @@ extension RUMViewScope {
912912
container: nil,
913913
context: .init(contextInfo: commandAttributes),
914914
date: (command.time - command.duration).addingTimeInterval(serverTimeOffset).timeIntervalSince1970.toInt64Milliseconds,
915-
device: context.normalizedDevice,
915+
device: context.normalizedDevice(),
916916
display: nil,
917917
longTask: .init(
918918
blockingDuration: nil,

DatadogTrace/Sources/Span/SpanEventBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal struct SpanEventBuilder {
9797
applicationVersion: context.version,
9898
networkConnectionInfo: networkInfoEnabled ? context.networkConnectionInfo : nil,
9999
mobileCarrierInfo: networkInfoEnabled ? context.carrierInfo : nil,
100-
device: context.normalizedDevice,
100+
device: context.normalizedDevice(addLocales: false),
101101
os: context.os,
102102
userInfo: spanUserInfo,
103103
accountInfo: spanEventAccountInfo,

DatadogTrace/Sources/Span/SpanEventEncoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ internal struct SpanEventEncoder {
213213

214214
/// Encodes default `meta.*` attributes
215215
private func encodeDefaultMeta(_ span: SpanEvent, to container: inout KeyedEncodingContainer<StaticCodingKeys>) throws {
216-
// NOTE: RUMM-299 only string values are supported for `meta.*` attributes
216+
// NOTE: RUM-9494 only basic types (boolean, string, number) are supported for `meta.*` attributes
217217
try container.encode(span.source, forKey: .source)
218218
try container.encode(span.tracerVersion, forKey: .tracerVersion)
219219
try container.encode(span.applicationVersion, forKey: .applicationVersion)
@@ -270,7 +270,7 @@ internal struct SpanEventEncoder {
270270

271271
/// Encodes `meta.*` attributes coming from user
272272
private func encodeCustomMeta(_ span: SpanEvent, to container: inout KeyedEncodingContainer<DynamicCodingKey>) throws {
273-
// NOTE: RUMM-299 only string values are supported for `meta.*` attributes
273+
// NOTE: RUM-9494 only basic types (boolean, string, number) are supported for `meta.*` attributes
274274
try span.userInfo.extraInfo.forEach {
275275
let metaKey = "meta.usr.\($0.key)"
276276
try container.encode($0.value, forKey: DynamicCodingKey(metaKey))

0 commit comments

Comments
 (0)