Skip to content

Crash with latest version and OTel export #474

@mmarczell-graphisoft

Description

@mmarczell-graphisoft

If I create a brand new SwiftUI app with Xcode, and initialize Embrace SDK 6.15.1 the following way, using opentelemetry-swift 2.2.1, both from SwiftPM:

import EmbraceIO
import OpenTelemetryProtocolExporterCommon
import OpenTelemetryProtocolExporterHttp
import SwiftUI

@main
struct swiftui_ios_sandboxApp: App {
    init() {
        do {
            let otelConfig = OtlpConfiguration(
                exportAsJson: false
            )
            let otel = OpenTelemetryExport(
                spanExporter: OtlpHttpTraceExporter(
                    endpoint: URL(string: "https://opentelemetry.my-company.com/v1/traces")!,
                    config: otelConfig
                ),
                logExporter: OtlpHttpLogExporter(
                    endpoint: URL(string: "https://opentelemetry.my-company.com/v1/logs")!,
                    config: otelConfig
                )
            )
            
            let embrace = try Embrace.setup(options: Embrace.Options(export: otel)).start()
        } catch let e {
            print("Error starting Embrace \(e.localizedDescription)")
        }
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

I get a crash on launch at this line:

https://github.com/open-telemetry/opentelemetry-swift/blob/8ab241c09c5daa2ad21cc8445fb881020c99608c/Sources/Exporters/OpenTelemetryProtocolCommon/trace/SpanAdapter.swift#L56

with the error message Fatal error: Negative value is not representable

It seems to me that the problem is that the hydrateSpan function at

attributes[SpanSemantics.keySessionId] = .string(sessionId)
inserts a new attribute but doesn't update the totalAttributeCount

Metadata

Metadata

Assignees

No one assigned

    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