> For the complete documentation index, see [llms.txt](https://docs.luciq.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.luciq.ai/android/set-up-luciq-for-android/set-up-application-performance-monitoring/execution-traces.md).

# Execution Traces

{% hint style="warning" %}

### Execution Traces is now Flows!

Execution Traces will be deprecated soon, please upgrade your Execution Traces APIs to the new Flows APIs [here](/android/set-up-luciq-for-android/set-up-application-performance-monitoring/set-up-flows.md).
{% endhint %}

Custom App Traces give you the flexibility of monitoring the performance of specific logic in your app. Via our SDK's API, you define the start and end of a trace and Luciq reports on its latency.

For example, you can monitor how long it takes to process and present the data you received from your server, fetching data from your local database, or maybe the time it takes to compress a file.

### Create Trace

It is as simple as defining the trace's name, calling an API to start tracking and doing another call to stop tracking when the task is over.

Luciq automatically aggregates the data of occurrences that are sharing the same trace name. It is worth mentioning that:

* You can run several traces with different names in parallel.
* You can run several occurrences of the same trace (same trace name) in parallel.
* The SDK ignores any trace occurrence that doesn't end. For example, if you start a trace then the user kills the app before it reaches the relevant end statement, this occurrence is ignored to avoid skewing your numbers.

#### Start Trace

You can use the API below to mark the start of a trace occurrence. It takes as input a trace name that we use to aggregate the data of relevant occurrences together on your dashboard. Please note the following:

* Trace **name** can be up to **150 characters**. Any extra characters are truncated.
* Trace name can't be null or an empty string.
* Avoid adding any of these special characters \[, (, ), =, {, }, <, >, /, , ] (commas not included) as they will be replaced with \_.
* Starting a new trace has to be done after initializing the SDK.

Starting a trace occurrence returns an object that you can use later on to [**end the trace occurrence**](#end-trace) or [**add custom attributes**](#adding-trace-attributes).

{% tabs %}
{% tab title="Kotlin" %}
{% code overflow="wrap" %}

```kotlin
// Start a trace
val trace: ExecutionTrace? = APM.startExecutionTrace("name")
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code overflow="wrap" %}

```java
// Start a trace
ExecutionTrace trace = APM.startExecutionTrace("name");
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### End Trace

Use the API below to end a trace occurrence that you have already started:

{% tabs %}
{% tab title="Kotlin" %}
{% code overflow="wrap" %}

```kotlin
// End an existing trace
trace?.end()
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code overflow="wrap" %}

```java
// End an existing trace
trace.end();
```

{% endcode %}
{% endtab %}
{% endtabs %}

***

### Adding Trace Attributes

Luciq automatically augments any trace with some attributes like app version, os version, and device. You can leverage those attributes on your dashboard to segment, drill-down, and find insightful patterns. For example, you can easily spot if a performance problem is related to a specific device model.

You can use the API below to add your custom attributes to a trace. For example, if you are A/B testing, you can add an experiment attribute.

While setting a new attribute to a trace that you have already created, you pass the attribute's key and value:

* The attribute's **key** can be up to **30 characters**.
* The attribute's **value** can be up to **60 characters**.
* Avoid adding any of these special characters \[, (, ), =, {, }, <, >, /, , ] (commas not included) as they will be replaced with \_.
* You can add up to **20 unique custom attributes** to each trace.
* The attribute's key can't be an empty string or null.
* The attribute's value can't be an empty string.
* You can call the API twice with the same key to override a previous value.
* Setting the attribute's value as null clears and removes the attribute.

{% tabs %}
{% tab title="Kotlin" %}
{% code overflow="wrap" %}

```kotlin
// Add custom attributes to an existing trace
trace?.setAttribute("key", "value")
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code overflow="wrap" %}

```java
// Add custom attributes to an existing trace
trace.setAttribute("key", "value");
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.luciq.ai/android/set-up-luciq-for-android/set-up-application-performance-monitoring/execution-traces.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
