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

Fixing log attachment count bug #166

Merged
merged 2 commits into from
Jan 28, 2025
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
10 changes: 2 additions & 8 deletions Sources/EmbraceCore/Internal/Logs/LogController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ protocol LogControllable: LogBatcherDelegate {
attachment: Data?,
attachmentId: String?,
attachmentUrl: URL?,
attachmentSize: Int?,
attributes: [String: String],
stackTraceBehavior: StackTraceBehavior
)
Expand Down Expand Up @@ -73,7 +72,6 @@ class LogController: LogControllable {
attachment: Data? = nil,
attachmentId: String? = nil,
attachmentUrl: URL? = nil,
attachmentSize: Int? = nil,
attributes: [String: String] = [:],
stackTraceBehavior: StackTraceBehavior = .default
) {
Expand Down Expand Up @@ -107,8 +105,6 @@ class LogController: LogControllable {
// handle attachment data
if let attachment = attachment {

sessionController.increaseAttachmentCount()

let id = UUID().withoutHyphen
finalAttributes[LogSemantics.keyAttachmentId] = id

Expand All @@ -128,6 +124,8 @@ class LogController: LogControllable {
else {
upload?.uploadAttachment(id: id, data: attachment, completion: nil)
}

sessionController.increaseAttachmentCount()
}

// handle pre-uploaded attachment
Expand All @@ -136,10 +134,6 @@ class LogController: LogControllable {

finalAttributes[LogSemantics.keyAttachmentId] = attachmentId
finalAttributes[LogSemantics.keyAttachmentUrl] = attachmentUrl.absoluteString

if let attachmentSize = attachmentSize {
finalAttributes[LogSemantics.keyAttachmentSize] = String(attachmentSize)
}
}

otel.log(message, severity: severity, timestamp: timestamp, attributes: finalAttributes)
Expand Down
5 changes: 0 additions & 5 deletions Sources/EmbraceCore/Public/Embrace+OTel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ extension Embrace: EmbraceOpenTelemetry {
attachment: nil,
attachmentId: nil,
attachmentUrl: nil,
attachmentSize: nil,
attributes: attributes,
stackTraceBehavior: stackTraceBehavior
)
Expand Down Expand Up @@ -191,7 +190,6 @@ extension Embrace: EmbraceOpenTelemetry {
attachment: attachment,
attachmentId: nil,
attachmentUrl: nil,
attachmentSize: nil,
attributes: attributes,
stackTraceBehavior: stackTraceBehavior
)
Expand All @@ -205,7 +203,6 @@ extension Embrace: EmbraceOpenTelemetry {
/// - timestamp: Timestamp for the log.
/// - attachmentId: Identifier of the attachment
/// - attachmentUrl: URL to dowload the attachment data
/// - attachmentSize: Size of the attachment (optional)
/// - attributes: Attributes for the log.
/// - stackTraceBehavior: Defines if the stack trace information should be added to the log
public func log(
Expand All @@ -215,7 +212,6 @@ extension Embrace: EmbraceOpenTelemetry {
timestamp: Date = Date(),
attachmentId: String,
attachmentUrl: URL,
attachmentSize: Int? = nil,
attributes: [String: String],
stackTraceBehavior: StackTraceBehavior = .default
) {
Expand All @@ -227,7 +223,6 @@ extension Embrace: EmbraceOpenTelemetry {
attachment: nil,
attachmentId: attachmentId,
attachmentUrl: attachmentUrl,
attachmentSize: attachmentSize,
attributes: attributes,
stackTraceBehavior: stackTraceBehavior
)
Expand Down
1 change: 0 additions & 1 deletion Sources/EmbraceOTelInternal/EmbraceOpenTelemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public protocol EmbraceOpenTelemetry: AnyObject {
timestamp: Date,
attachmentId: String,
attachmentUrl: URL,
attachmentSize: Int?,
attributes: [String: String],
stackTraceBehavior: StackTraceBehavior
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private extension LogControllerTests {

func whenCreatingLogWithPreUploadedAttachment() {
let url = URL(string: "http//embrace.test.com/attachment/123", testName: testName)!
sut.createLog("test", severity: .info, attachmentId: UUID().withoutHyphen, attachmentUrl: url, attachmentSize: 12345)
sut.createLog("test", severity: .info, attachmentId: UUID().withoutHyphen, attachmentUrl: url)
}

func thenDoesntTryToUploadAnything() {
Expand Down Expand Up @@ -449,9 +449,8 @@ private extension LogControllerTests {

let attachmentIdFound = log!.attributes["emb.attachment_id"] != nil
let attachmentUrlFound = log!.attributes["emb.attachment_url"] != nil
let attachmentSizeFound = log!.attributes["emb.attachment_size"] != nil

return attachmentIdFound && attachmentUrlFound && attachmentSizeFound
return attachmentIdFound && attachmentUrlFound
}
}

Expand Down
1 change: 0 additions & 1 deletion Tests/TestSupport/Mocks/DummyLogControllable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class DummyLogControllable: LogControllable {
attachment: Data?,
attachmentId: String?,
attachmentUrl: URL?,
attachmentSize: Int?,
attributes: [String : String],
stackTraceBehavior: StackTraceBehavior
) { }
Expand Down
1 change: 0 additions & 1 deletion Tests/TestSupport/Mocks/MockEmbraceOpenTelemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public class MockEmbraceOpenTelemetry: NSObject, EmbraceOpenTelemetry {
timestamp: Date = Date(),
attachmentId: String,
attachmentUrl: URL,
attachmentSize: Int?,
attributes: [String : String] = [:],
stackTraceBehavior: StackTraceBehavior = .default
) {
Expand Down
Loading