# Resources

<!-- markdownlint-disable no-duplicate-heading -->


  {{__hugo_ctx pid=354}}

A [resource](/docs/concepts/resources/) represents the entity producing telemetry as
resource attributes. For example, an OTP Release producing telemetry that is
running in a container on Kubernetes has an OTP Release name, a pod name, a
namespace, and possibly a deployment name. All four of these attributes can be
included in the resource.

In your observability backend, you can use resource information to better
investigate interesting behavior. For example, if your trace or metrics data
indicate latency in your system, you can narrow it down to a specific container,
pod, or Kubernetes deployment.
{{__hugo_ctx/}}


## Using resource detectors

Resource detectors fetch resource attributes from various sources. The default
detectors use the OS environment variable `OTEL_RESOURCE_ATTRIBUTES` and the
`opentelemetry` OTP application environment variable `resource`.

The detectors to use is a list of module names and can be configured in the
Application configuration:

   <ul class="nav nav-tabs" id="tabs-1" role="tablist">
  <li class="nav-item">
      <button class="nav-link active"
          id="tabs-01-00-tab" data-bs-toggle="tab" data-bs-target="#tabs-01-00" role="tab"
          data-td-tp-persist="erlang" aria-controls="tabs-01-00" aria-selected="true">
        Erlang
      </button>
    </li><li class="nav-item">
      <button class="nav-link"
          id="tabs-01-01-tab" data-bs-toggle="tab" data-bs-target="#tabs-01-01" role="tab"
          data-td-tp-persist="elixir" aria-controls="tabs-01-01" aria-selected="false">
        Elixir
      </button>
    </li>
</ul>

<div class="tab-content" id="tabs-1-content">
    <div class="tab-body tab-pane fade show active"
        id="tabs-01-00" role="tabpanel" aria-labelled-by="tabs-01-00-tab" tabindex="1">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-erlang" data-lang="erlang"><span class="line"><span class="cl"><span class="c">%% sys.config
</span></span></span><span class="line"><span class="cl"><span class="p">{</span><span class="n">opentelemetry</span><span class="p">,</span> <span class="p">{</span><span class="n">resource_detectors</span><span class="p">,</span> <span class="p">[</span><span class="n">otel_resource_env_var</span><span class="p">,</span> <span class="n">otel_resource_app_env</span><span class="p">]}}</span>
</span></span></code></pre></div>
    </div>
    <div class="tab-body tab-pane fade"
        id="tabs-01-01" role="tabpanel" aria-labelled-by="tabs-01-01-tab" tabindex="1">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="c1">## runtime.exs</span>
</span></span><span class="line"><span class="cl"><span class="n">config</span> <span class="ss">:opentelemetry</span><span class="p">,</span> <span class="ss">resource_detectors</span><span class="p">:</span> <span class="p">[</span><span class="ss">:otel_resource_env_var</span><span class="p">,</span> <span class="ss">:otel_resource_app_env</span><span class="p">]</span>
</span></span></code></pre></div>
    </div>
</div>


Or through the environment variable `OTEL_RESOURCE_DETECTORS`:

```sh
OTEL_RESOURCE_DETECTORS=otel_resource_env_var,otel_resource_app_env
```

All resources detectors are protected with a timeout, in milliseconds, after
which they return an empty value. This allows for resource detectors to do
things like hit the network without potentially hanging the entire program
indefinitely. The default is 5000 milliseconds and can be set with environment
variable `OTEL_RESOURCE_DETECTOR_TIMEOUT` or Application variable
`otel_resource_detector_timeout`.

## Adding resources with OS and OTP application environment variables

With the two default resource detectors enabled you can set resource attributes
either with the OS environment variable `OTEL_RESOURCE_ATTRIBUTES`:

```sh
OTEL_RESOURCE_ATTRIBUTES="deployment.environment=development"
```

Alternatively, use the `resource` OTP application environment under the
`opentelemetry` Application configuration of `sys.config` or `runtime.exs`:

   <ul class="nav nav-tabs" id="tabs-2" role="tablist">
  <li class="nav-item">
      <button class="nav-link active"
          id="tabs-02-00-tab" data-bs-toggle="tab" data-bs-target="#tabs-02-00" role="tab"
          data-td-tp-persist="erlang" aria-controls="tabs-02-00" aria-selected="true">
        Erlang
      </button>
    </li><li class="nav-item">
      <button class="nav-link"
          id="tabs-02-01-tab" data-bs-toggle="tab" data-bs-target="#tabs-02-01" role="tab"
          data-td-tp-persist="elixir" aria-controls="tabs-02-01" aria-selected="false">
        Elixir
      </button>
    </li>
</ul>

<div class="tab-content" id="tabs-2-content">
    <div class="tab-body tab-pane fade show active"
        id="tabs-02-00" role="tabpanel" aria-labelled-by="tabs-02-00-tab" tabindex="2">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-erlang" data-lang="erlang"><span class="line"><span class="cl"><span class="c">%% sys.config
</span></span></span><span class="line"><span class="cl"><span class="p">{</span><span class="n">opentelemetry</span><span class="p">,</span> <span class="p">{</span><span class="n">resource</span><span class="p">,</span> <span class="p">#{</span><span class="n">deployment</span> <span class="o">=&gt;</span> <span class="p">#{</span><span class="n">environment</span> <span class="o">=&gt;</span> <span class="o">&lt;&lt;</span><span class="s">&#34;development&#34;</span><span class="o">&gt;&gt;</span><span class="p">}}}}</span>
</span></span></code></pre></div>
    </div>
    <div class="tab-body tab-pane fade"
        id="tabs-02-01" role="tabpanel" aria-labelled-by="tabs-02-01-tab" tabindex="2">
        <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-elixir" data-lang="elixir"><span class="line"><span class="cl"><span class="c1">## runtime.exs</span>
</span></span><span class="line"><span class="cl"><span class="n">config</span> <span class="ss">:opentelemetry</span><span class="p">,</span> <span class="ss">resource</span><span class="p">:</span> <span class="p">%{</span><span class="ss">deployment</span><span class="p">:</span> <span class="p">%{</span><span class="ss">environment</span><span class="p">:</span> <span class="s2">&#34;development&#34;</span> <span class="p">}}</span>
</span></span></code></pre></div>
    </div>
</div>


Resource attributes in the `resource` OTP application environment variable are
flattened and combined with `.`, so
`#{deployment => #{environment => <<"development">> }` is the same as
`#{'deployment.environment' => <<"development">>}`.

## Custom resource detectors

Custom resource detectors can be created by implementing the
[`otel_resource_detector` behaviour](https://hexdocs.pm/opentelemetry/1.3.0/otel_resource_detector.html#callbacks)
which contains a single callback `get_resource/1` that returns an
[`otel_resource`](https://hexdocs.pm/opentelemetry/1.3.0/otel_resource.html).

Note that there are [semantic conventions](/docs/specs/semconv/resource/)
defined for `resource` that should be followed if they apply when adding new
resource attributes.
