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

RUM-4311: Add Logs event mapper to ObjC API #2008

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

- [FIX] Propagate global Tracer tags to OpenTelemetry span attributes. See [#2000][]
- [FEATURE] Add Logs event mapper to ObjC API. See [#2008][]
- [IMPROVEMENT] Send retry information with network requests (eg. retry_count, last_failure_status and idempotency key). See [#1991][]

# 2.16.0 / 20-08-2024
Expand Down Expand Up @@ -750,6 +751,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
[#1988]: https://github.com/DataDog/dd-sdk-ios/pull/1988
[#2000]: https://github.com/DataDog/dd-sdk-ios/pull/2000
[#1991]: https://github.com/DataDog/dd-sdk-ios/pull/1991
[#2008]: https://github.com/DataDog/dd-sdk-ios/pull/2008
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
[@hengyu]: https://github.com/Hengyu
Expand Down
6 changes: 6 additions & 0 deletions Datadog/Datadog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,8 @@
E2AA55E82C32C6D9002FEF28 /* ApplicationNotifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AA55E62C32C6D9002FEF28 /* ApplicationNotifications.swift */; };
E2AA55EA2C32C76A002FEF28 /* WatchKitExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AA55E92C32C76A002FEF28 /* WatchKitExtensions.swift */; };
E2AA55EC2C32C78B002FEF28 /* WatchKitExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AA55E92C32C76A002FEF28 /* WatchKitExtensions.swift */; };
F6E106542C75E0D000716DC6 /* LogsDataModels+objc.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6E106532C75E0D000716DC6 /* LogsDataModels+objc.swift */; };
F6E106552C75E0D000716DC6 /* LogsDataModels+objc.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6E106532C75E0D000716DC6 /* LogsDataModels+objc.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -3051,6 +3053,7 @@
E2AA55E62C32C6D9002FEF28 /* ApplicationNotifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationNotifications.swift; sourceTree = "<group>"; };
E2AA55E92C32C76A002FEF28 /* WatchKitExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WatchKitExtensions.swift; sourceTree = "<group>"; };
F637AED12697404200516F32 /* UIKitRUMUserActionsPredicate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitRUMUserActionsPredicate.swift; sourceTree = "<group>"; };
F6E106532C75E0D000716DC6 /* LogsDataModels+objc.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LogsDataModels+objc.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -6279,6 +6282,7 @@
isa = PBXGroup;
children = (
61133C0C2423983800786299 /* Logs+objc.swift */,
F6E106532C75E0D000716DC6 /* LogsDataModels+objc.swift */,
);
path = Logs;
sourceTree = "<group>";
Expand Down Expand Up @@ -8278,6 +8282,7 @@
9E55407C25812D1C00F6E3AD /* RUM+objc.swift in Sources */,
D2A434AA2A8E40A20028E329 /* SessionReplay+objc.swift in Sources */,
615A4A8D24A356A000233986 /* OTSpanContext+objc.swift in Sources */,
F6E106542C75E0D000716DC6 /* LogsDataModels+objc.swift in Sources */,
61133C112423983800786299 /* DatadogConfiguration+objc.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -9528,6 +9533,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F6E106552C75E0D000716DC6 /* LogsDataModels+objc.swift in Sources */,
D2CB6F9927C5217A00A62B57 /* Casting.swift in Sources */,
D2CB6F9A27C5217A00A62B57 /* RUMDataModels+objc.swift in Sources */,
D2CB6F9B27C5217A00A62B57 /* DDSpanContext+objc.swift in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions DatadogCore/Tests/DatadogObjc/DDLogsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@ class DDLogsTests: XCTestCase {
XCTAssertEqual(objcConfig.configuration.remoteSampleRate, 50)
XCTAssertNotNil(objcConfig.configuration.consoleLogFormat)
}

func testEventMapping() throws {
let logsConfiguration = DDLogsConfiguration()
logsConfiguration.setEventMapper { logEvent in
logEvent.message = "custom-log-message"
logEvent.attributes.userAttributes["custom-attribute"] = "custom-value"
return logEvent
}
DDLogs.enable(with: logsConfiguration)

let objcLogger = DDLogger.create()

objcLogger.debug("message")

let logMatchers = try core.waitAndReturnLogMatchers()
logMatchers[0].assertMessage(equals: "custom-log-message")
logMatchers[0].assertAttributes(equal: ["custom-attribute": "custom-value"])
}
}
// swiftlint:enable multiline_arguments_brackets
// swiftlint:enable compiler_protocol_init
12 changes: 12 additions & 0 deletions DatadogObjc/Sources/Logs/Logs+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ public class DDLogsConfiguration: NSObject {
customEndpoint: customEndpoint
)
}

/// Sets the custom mapper for `DDLogEvent`. This can be used to modify logs before they are send to Datadog.
///
/// The implementation should obtain a mutable version of the `DDLogEvent`, modify it and return it. Returning `nil` will result
/// with dropping the Log event entirely, so it won't be send to Datadog.
@objc
public func setEventMapper(_ mapper: @escaping (DDLogEvent) -> DDLogEvent?) {
configuration.eventMapper = { swiftEvent in
let objcEvent = DDLogEvent(swiftModel: swiftEvent)
return mapper(objcEvent)?.swiftModel
}
}
}

@objc
Expand Down
Loading