Skip to content

Cannot assign value of type 'Int64' to type 'UInt64' #1049

@gmantuanrosa

Description

@gmantuanrosa

Issue

I added the latest versions of URLSessionInstrumentation and OpenTelemetryProtocolExporterHTTP to my project via Swift Package Manager and once I try run the project I get the following build error Cannot assign value of type 'Int64' to type 'UInt64'.

The functions complaining with this issue are

/// func toProtoLogRecord(_)
if let observedTimestamp = logRecord.observedTimestamp {
    protoLogRecord.observedTimeUnixNano = observedTimestamp.timeIntervalSince1970.toNanoseconds
}
protoLogRecord.timeUnixNano = logRecord.timestamp.timeIntervalSince1970.toNanoseconds

/// func toProtoSpan(_)
protoSpan.startTimeUnixNano = spanData.startTime.timeIntervalSince1970.toNanoseconds
protoSpan.endTimeUnixNano = spanData.endTime.timeIntervalSince1970.toNanoseconds
    
/// func toProtoSpanEvent(_)
protoEvent.timeUnixNano = event.timestamp.timeIntervalSince1970.toNanoseconds

the .toNanoseconds extension is correctly converting to Int64

var toNanoseconds: Int64 {
    let nanoseconds = self * 1_000_000_000
    return Int64(withReportingOverflow: nanoseconds) ?? (self < 0 ? .min : .max)
}

but the generated logs.pb.swift and trace.pb.swift explicitly mentions UInt64

public var observedTimeUnixNano: UInt64 = 0

public var startTimeUnixNano: UInt64 {
    get {return _storage._startTimeUnixNano}
    set {_uniqueStorage()._startTimeUnixNano = newValue}
}
public var endTimeUnixNano: UInt64 {
    get {return _storage._endTimeUnixNano}
    set {_uniqueStorage()._endTimeUnixNano = newValue}
}
public var timeUnixNano: UInt64 = 0

Is there a way to fix this issue?

Environment:

iOS Version: 26
Swift version: 6
OpenTelemetry SDK Version: 2.3.0
OpenTelemetry Core SDK Version: 2.4.0

Also any version that I test I get the same error

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions