Skip to main content

Traces

Overview

Embrace’s Traces solution gives you complete visibility into any customized operation you’d like to track, enabling you to identify, prioritize, and resolve any performance issue. With our tool, you can quickly spot any bottlenecks in your app’s architecture, pinpoint areas you need to troubleshoot with high precision, and ultimately deliver a truly optimized user

Feature Support

The Embrace Traces API allows you to:

  • Create real-time performance timers or record past operations.
    • For real-time tracing, we use a “Stopwatch” concept that enables you to start and stop the timing of a span manually
    • To record a past operation, you can pass in start and end times during span creation.
  • Create child spans that can be attached to a parent.
  • Add attributes and events to each span
    • Attributes have String keys and String values
    • Events also have a set of attributes that have String keys and values.

There is no limit on the duration of spans, but if a crash occurs during a span that is in progress, that span will not be recorded.

Limits

TypeLimit
Max number of span per session100
Max number of spans per Root Span10
Max number of attributes per span50
Max number of events per span10
Max number of attributes per event10
Length of attribute keys50 characters
Length of attribute values200 characters
Length of Span names50 characters
Length of Event names100 characters
Exceeding Limits

If you exceed the listed limits, the operation with the limit-exceeding call will fail and return a value indicating that. See the API documentation for details.

Naming Conventions

  • Span Names are case-sensitive and are a max of 50 characters.
  • Key Names are case-sensitive, have a max of 50 characters, and are alpha-numeric
Internal Prefixes

The emb- and emb. prefixes are reserved for internal Embrace span names and attribute keys. You should never create a name with emb- and emb. prefixes

Integration Steps

Minimum SDK Version

We recommend using at least iOS SDK v5.23.1 and updating to new versions as they come out to ensure you get the latest updates for this developing feature.

To use this feature:

  1. Ensure you’re using a version of the Embrace SDK that supports Traces.
  2. Instrument your app using the reference guide in this sections to start adding spans to your operations.
  3. See the spans in the Traces section of the Embrace dashboard.

Create Span

let span = Embrace.sharedInstance().createSpanNamed("process-image")

Start Span

let span = Embrace.sharedInstance().createSpanNamed("custom-name")

// start span at current time
span.start()

Adding a Child Span

// Create a root span with a custom name
let span = Embrace.sharedInstance().createSpanNamed("process-batch")

// Create a child span by including the parent parameter
let childSpan = Embrace.sharedInstance().createSpanNamed("process-item", parent: span)

Adding Events and Attributes

// Add attributes to spans to provide context
span.addAttribute(withKey: "product.id", value: "ABC123")

// Add span events to mark checkpoints
span.addEventNamed("image-render-complete", time: UInt(Date().timeIntervalSince1970 * pow(10, 9)))

End Span

// Stop span at current time, considered successful
span.stop()

// Stop span at current time with explicit error code
span.stopWith(.Failure)

Recording a Completed Span

let startAt = Date()
let endAt = startAt.addingTimeInterval(4.0)

// manually record operation timing after it occurs
Embrace.sharedInstance().recordCompletedSpanNamed(
"deserialize-data-blob",
parent: nil,
startTimeNanos: Int(startAt.timeIntervalSince1970 * pow(10, 9)),
endTimeNanos: Int(endAt.timeIntervalSince1970 * pow(10, 9)),
attributes: nil,
events: nil,
errorCode: .None
)

Support

If you have any questions or if something is not working as intended, please get in touch with your Customer Success Manager.