

OpentelemetryPhoenix — Opentelemetry Phoenix v1.1.1

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/lib/opentelemetry_phoenix.ex#L1 "View Source")

OpentelemetryPhoenix

(Opentelemetry Phoenix v1.1.1)

============================================================================================================================================================================================================================================

OpentelemetryPhoenix uses [telemetry](https://hexdocs.pm/telemetry/) handlers to create [`OpenTelemetry`](https://hexdocs.pm/opentelemetry_api/1.1.1/OpenTelemetry.html) spans.

Current events which are supported include endpoint start/stop, router start/stop,

and router exceptions.

### 

[supported-options](#module-supported-options)

 Supported options

* `:endpoint_prefix` (list of [`atom/0`](https://hexdocs.pm/elixir/typespecs.html#basic-types)) - The endpoint prefix in your endpoint. The default value is `[:phoenix, :endpoint]`.

* `:adapter` - The phoenix server adapter being used. The default value is `nil`.

If you are using PlugCowboy as your adapter you can add `:opentelemetry_cowboy` to your project

and pass the `:adapter` option when calling setup. Setting this option will prevent a new

span from being started and the existing cowboy span to be continued. This is the recommended

setup for measuring accurate latencies.

`Bandit.PhoenixAdapter` is not currently supported.

[usage](#module-usage)

 Usage

------------------------------

In your application start:

```

def start(\_type, \_args) do

 :opentelemetry\_cowboy.setup()

 OpentelemetryPhoenix.setup(adapter: :cowboy2)

 children = [

 {Phoenix.PubSub, name: MyApp.PubSub},

 MyAppWeb.Endpoint

 ]

 opts = [strategy: :one\_for\_one, name: MyStore.Supervisor]

 Supervisor.start\_link(children, opts)

end

```

[Link to this section](#summary)

 Summary

==========================================

[Types](#types)

----------------

[adapter()](#t:adapter/0)

The phoenix server adapter being used. Optional

[endpoint\_prefix()](#t:endpoint_prefix/0)

The endpoint prefix in your endpoint. Defaults to `[:phoenix, :endpoint]`

[opts()](#t:opts/0)

Setup options

[Functions](#functions)

------------------------

[setup(opts \\ [])](#setup/1)

Initializes and configures the telemetry handlers.

[Link to this section](#types)

Types

=====================================

[Link to this type](#t:adapter/0 "Link to this type")

adapter()

=========

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/lib/opentelemetry_phoenix.ex#L67 "View Source")

```

@type adapter() :: {:adapter, :cowboy2 | [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()}

```

The phoenix server adapter being used. Optional

[Link to this type](#t:endpoint_prefix/0 "Link to this type")

endpoint\_prefix()

==================

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/lib/opentelemetry_phoenix.ex#L64 "View Source")

```

@type endpoint_prefix() :: {:endpoint_prefix, [[atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)()]}

```

The endpoint prefix in your endpoint. Defaults to `[:phoenix, :endpoint]`

[Link to this type](#t:opts/0 "Link to this type")

opts()

======

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/lib/opentelemetry_phoenix.ex#L61 "View Source")

```

@type opts() :: [[endpoint\_prefix](#t:endpoint_prefix/0)() | [adapter](#t:adapter/0)()]

```

Setup options

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#setup/1 "Link to this function")

setup(opts \\ [])

=================

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/lib/opentelemetry_phoenix.ex#L73 "View Source")

```

@spec setup([opts](#t:opts/0)()) :: :ok

```

Initializes and configures the telemetry handlers.





OpentelemetryPhoenix.Reason — Opentelemetry Phoenix v1.1.1

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/lib/opentelemetry_phoenix/reason.ex#L1 "View Source")

OpentelemetryPhoenix.Reason

(Opentelemetry Phoenix v1.1.1)

==========================================================================================================================================================================================================================================================

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[normalize(other)](#normalize/1)

[normalize(other, stacktrace)](#normalize/2)

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#normalize/1 "Link to this function")

normalize(other)

================

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/lib/opentelemetry_phoenix/reason.ex#L2 "View Source")

[Link to this function](#normalize/2 "Link to this function")

normalize(other, stacktrace)

============================

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/lib/opentelemetry_phoenix/reason.ex#L80 "View Source")





OpentelemetryPhoenix — Opentelemetry Phoenix v1.1.1

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/open-telemetry/opentelemetry-erlang-contrib/blob/main/instrumentation/opentelemetry_phoenix/README.md#L1 "View Source")

OpentelemetryPhoenix

==========================================================================================================================================================================================

[![EEF Observability WG project](https://img.shields.io/badge/EEF-Observability-black)](https://github.com/erlef/eef-observability-wg)

[![Hex.pm](https://img.shields.io/hexpm/v/opentelemetry_phoenix)](https://hex.pm/packages/opentelemetry_phoenix)

![Build Status](https://github.com/opentelemetry-beam/opentelemetry_phoenix/workflows/Tests/badge.svg)

Telemetry handler that creates Opentelemetry spans from Phoenix events.

After installing, setup the handler in your application behaviour before your

top-level supervisor starts.

```

OpentelemetryPhoenix.setup()

```

See the documentation for [`OpentelemetryPhoenix.setup/1`](OpentelemetryPhoenix.html#setup/1) for additional options that

may be supplied.

[installation](#installation)

 Installation

--------------------------------------------

```

def deps do

 [

 {:opentelemetry\_phoenix, "~> 1.1"}

 ]

end

```

[compatibility-matrix](#compatibility-matrix)

 Compatibility Matrix

--------------------------------------------------------------------

| OpentelemetryPhoenix Version | Otel Version | Notes |

| --- | --- | --- |

|  |  |  |

| v0.1.0 | <= v.0.5.0 |  |

| v1.0.0-rc.3 | v1.0.0-rc.1 |  |

|  | v1.0.0-rc.2 |  |

| v1.0.0-rc.4 | v1.0.0-rc.2 | Otel rc.3 will be a breaking change |

| v1.0.0-rc.5 | v1.0.0-rc.3 |  |

| v1.0.0-rc.6 | v1.0.0-rc.4 |  |

| v1.0 | v1.0 |  |

[note-on-phoenix-integration](#note-on-phoenix-integration)

 Note on phoenix integration

-----------------------------------------------------------------------------------------

[`OpentelemetryPhoenix`](OpentelemetryPhoenix.html) requires phoenix to use [`Plug.Telemetry`](https://hexdocs.pm/plug/1.14.0/Plug.Telemetry.html) in order to correctly trace endpoint calls.

The `endpoint.ex` file should look like:

```

defmodule MyApp.Endpoint do

  use Phoenix.Endpoint, otp_app: :my_app

  ...

  plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

  ...

end

```

The [Phoenix endpoint.ex template](https://github.com/phoenixframework/phoenix/blob/v1.6.0/installer/templates/phx_web/endpoint.ex#L39) can be used as a reference

[← Previous Page

 

API Reference](api-reference.html)

