Skip to content

Convenience functions for spans and events #91

@Doohl

Description

@Doohl

Currently, the experience for instrumenting custom spans and events with the ADOT SDK on Swift is a little cubersome and code-heavy. It shouldn't be too much effort to ship convenience functions for instrumenting apps with custom telemetry.

For example, customers could have the following experience:

// Simple span
AwsOpenTelemetryAgent.span("load_user_profile") { span in
    let user = database.getUser(userId: userId)
    processUser(user)
}

// Span with attributes
AwsOpenTelemetryAgent.span("checkout", attributes: [
    "cart.items": .int(3),
    "cart.total": .double(49.99)
]) { span in
    processCheckout()
}

// Async span with return value
let products = try await AwsOpenTelemetryAgent.span("fetch_products") { span in
    let result = try await api.getProducts()
    span.setAttribute(key: "count", value: result.count)
    return result
}

// Simple event
AwsOpenTelemetryAgent.event("button_clicked")

// Event with details
AwsOpenTelemetryAgent.event(
    "purchase_completed",
    body: "User completed checkout",
    attributes: [
        "order.id": .string("12345"),
        "order.total": .double(99.99)
    ]
)

ADOT Android SDK has this already: https://github.com/aws-observability/aws-otel-android/blob/main/core/src/main/kotlin/software/amazon/opentelemetry/android/features/CustomSpanClient.kt

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions