# `Appsignal.Tracer`
[🔗](https://github.com/appsignal/appsignal-elixir/blob/v2.17.0/lib/appsignal/tracer.ex#L1)

# `option`

```elixir
@type option() :: {:pid, pid()} | {:start_time, integer()}
```

# `options`

```elixir
@type options() :: [option()]
```

# `close_span`

```elixir
@spec close_span(Appsignal.Span.t() | nil) :: :ok | nil
```

Closes a span and deregisters it.

## Example
    Appsignal.Tracer.current_span()
    |> Appsignal.Tracer.close_span()

# `close_span`

```elixir
@spec close_span(Appsignal.Span.t() | nil, list()) :: :ok | nil
```

Closes a span and deregisters it. Takes an options list, which currently only
accepts a `List` with an `:end_time` integer.

## Example
    Appsignal.Tracer.current_span()
    |> Appsignal.Tracer.close_span(end_time: :os.system_time())

# `create_span`

```elixir
@spec create_span(String.t()) :: Appsignal.Span.t() | nil
```

Creates a new root span.

## Example
    Appsignal.Tracer.create_span("http_request")

# `create_span`

```elixir
@spec create_span(String.t(), Appsignal.Span.t() | nil) :: Appsignal.Span.t() | nil
```

Creates a new child span.

## Example
    parent = Appsignal.Tracer.current_span()

    Appsignal.Tracer.create_span("http_request", parent)

# `create_span`

```elixir
@spec create_span(String.t(), Appsignal.Span.t() | nil, options()) ::
  Appsignal.Span.t() | nil
```

Creates a new span, with an optional parent or pid.

## Example
    parent = Appsignal.Tracer.current_span()

    Appsignal.Tracer.create_span("http_request", parent, [start_time: :os.system_time(), pid: self()])

# `current_span`

```elixir
@spec current_span() :: Appsignal.Span.t() | nil
```

Returns the current span in the current process.

# `current_span`

```elixir
@spec current_span(pid()) :: Appsignal.Span.t() | nil
```

Returns the current span in the passed pid's process.

# `custom_on_create_fun`

```elixir
@spec custom_on_create_fun(Appsignal.Span.t() | nil) :: any()
```

This function can be defined by the user and will be executed on the
creation of the span after create_span/3 is executed. It can be used to add
custom_data to the span.

Example in your own application:
```ex
defmodule MyApp.Appsignal do
  def custom_on_create_fun(span) do
    Appsignal.Span.set_sample_data(span, "custom_data", %{"foo": "bar"})
  end
end
```

This can be added to the config with:
```ex
config :appsignal, custom_on_create_fun: &MyApp.Appsignal.custom_on_create_fun/1
```

# `delete`

```elixir
@spec delete(pid()) :: :ok
```

Removes the process' spans from the registry.

# `ignore`

```elixir
@spec ignore() :: :ok
```

Ignores the current process.

# `ignore`

```elixir
@spec ignore(pid()) :: :ok
```

Ignores the given process.

# `lookup`

```elixir
@spec lookup(pid()) :: list() | []
```

Finds the span in the registry table.

# `root_span`

```elixir
@spec root_span() :: Appsignal.Span.t() | nil
```

Returns the root span in the current process.

# `root_span`

```elixir
@spec root_span(pid()) :: Appsignal.Span.t() | nil
```

Returns the root span in the passed pid's process.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
