# APM Server - not all variables are working for Indicies templates

**URL:** <https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847>\
**Category:** APM\
**Tags:** server\
**Created:** [August 13, 2020, 9:55am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847 "2020-08-13T09:55:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheVintik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thevintik/32/60494_2.png) [@TheVintik](https://discuss.elastic.co/u/TheVintik)\
**Post date:** [August 13, 2020, 9:55am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/1 "2020-08-13T09:55:12Z")

</div>

Hello!

I have APM Server with default config and all is working fine. Now I want to split ES indices from APM by project or hostname ore something else and get a problem. I am using this part of config for this:

`  
output.elasticsearch:  
...

index: "apm-%{[observer.version]}-ident-%{+yyyy.MM.dd}"  
indices:  
- index: "apm-%{[observer.version]}-sourcemap"  
when.contains:  
processor.event: "sourcemap"

```
...

- index: "apm-%{[observer.version]}-span-%{[source.ip]}-int-%{+yyyy.MM.dd}"

```

`

And my issues is - all "variables", like a %{[source.ip]} is empty for me ☹  
When I tried, for example, %{[observer.hostname]} - I got a new index with hostname in the name.

I tried at least all variables from this list - [https://www.elastic.co/guide/en/apm/server/master/exported-fields-apm.html#\_process](https://www.elastic.co/guide/en/apm/server/master/exported-fields-apm.html#_process)

but all of them are empty (or not defined).

How I turn on them? Or maybe there is some other way to get hostname or application name from receiving data to add it to indice name?

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [August 14, 2020, 1:56am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/2 "2020-08-14T01:56:14Z")

</div>

Not all fields are set for all events. Specifically, `source.ip` is only set for _some_ transaction docs - and no spans at all, currently.

> How I turn on them? Or maybe there is some other way to get hostname or application name from receiving data to add it to indice name?

You can use `host.name` for the hostname of the instrumented service, or `service.name` for the service name.

---

<div class="post-metadata">

**Author:** ![TheVintik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thevintik/32/60494_2.png) [@TheVintik](https://discuss.elastic.co/u/TheVintik)\
**Post date:** [August 14, 2020, 10:58am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/3 "2020-08-14T10:58:13Z")

</div>

@axw should I use it like:

```
 index: "apm-%{[observer.version]}-ident-%{+yyyy.MM.dd}"
  indices:
- index: "apm-%{[observer.version]}-sourcemap"
  when.contains:
    processor.event: "sourcemap"

- index: "apm-%{[observer.version]}-error-%{[host.name]}-%{[service.name]}-%{+yyyy.MM.dd}"
  when.contains:
    processor.event: "error"

- index: "apm-%{[observer.version]}-%{[host.name]}-%{[service.name]}-transaction-%{+yyyy.MM.dd}"
  when.contains:
    processor.event: "transaction"

- index: "apm-%{[observer.version]}-span-%{[host.name]}-%{[service.name]}-int-%{+yyyy.MM.dd}"
  when.contains:
    processor.event: "span"

- index: "apm-%{[observer.version]}-metric-%{[host.name]}-%{[service.name]}-%{+yyyy.MM.dd}"
  when.contains:
    processor.event: "metric"

- index: "apm-%{[observer.version]}-onboarding-%{[host.name]}-%{[service.name]}-%{+yyyy.MM.dd}"
  when.contains:
    processor.event: "onboarding"

```

?

If so - it does not work ☹

I have indexes with names like `apm-7.6.1-transaction-2020.08.12` - so, looks like `host.name` and `service.name` are blank too for me ☹

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [August 17, 2020, 2:03am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/4 "2020-08-17T02:03:06Z")

</div>

@TheVintik that looks right, except for the `onboarding` one: those docs do not have a `service.name`. Can you please share your complete apm-server.yml config? (With any passwords redacted of course.)

---

<div class="post-metadata">

**Author:** ![jalvz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jalvz/32/45613_2.png) [@jalvz](https://discuss.elastic.co/u/jalvz)\
**Post date:** [August 17, 2020, 11:29am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/5 "2020-08-17T11:29:40Z")

</div>

Hello,

Additionally to what @axw asked, might I ask what agent are you using (language and version)?

---

<div class="post-metadata">

**Author:** ![TheVintik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thevintik/32/60494_2.png) [@TheVintik](https://discuss.elastic.co/u/TheVintik)\
**Post date:** [August 17, 2020, 12:06pm UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/6 "2020-08-17T12:06:25Z")

</div>

@axw I am using Ruby on Rails application with `elastic-apm` (latest version). There is no any additional settings from Rails side except secret key to send data to APM.

---

<div class="post-metadata">

**Author:** ![TheVintik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thevintik/32/60494_2.png) [@TheVintik](https://discuss.elastic.co/u/TheVintik)\
**Post date:** [August 17, 2020, 12:42pm UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/7 "2020-08-17T12:42:32Z")

</div>

@axw

Here is my config:

```auto
[centos@XXX ~]$ sudo cat /etc/apm-server/apm-server.yml | grep -v '#'

apm-server:
  host: "XXXX:8200"
  secret_token: XXXXX

  kibana:
    enabled: true
    host: "XXXXX:5601"
    protocol: "https"

setup.template.name: "apm-%{[observer.version]}-custom"
setup.template.pattern: "apm-%{[observer.version]}-*"
setup.template.overwrite: true

output.elasticsearch:
  hosts: ["XXXX:9200"]

  enabled: true

  index: "apm-%{[observer.version]}-ident-%{+yyyy.MM.dd}"
  indices:
    - index: "apm-%{[observer.version]}-sourcemap"
      when.contains:
        processor.event: "sourcemap"
  
    - index: "apm-%{[observer.version]}-error-%{[host.name]}-%{[service.name]}-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "error"
  
    - index: "apm-%{[observer.version]}-%{[host.name]}-%{[service.name]}-transaction-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "transaction"
  
    - index: "apm-%{[observer.version]}-span-%{[host.name]}-%{[service.name]}-int-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "span"
  
    - index: "apm-%{[observer.version]}-metric-%{[host.name]}-%{[service.name]}-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "metric"
  
    - index: "apm-%{[observer.version]}-onboarding-%{[host.name]}-%{[service.name]}-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "onboarding"

```

---

<div class="post-metadata">

**Author:** ![TheVintik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thevintik/32/60494_2.png) [@TheVintik](https://discuss.elastic.co/u/TheVintik)\
**Post date:** [August 17, 2020, 12:55pm UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/8 "2020-08-17T12:55:32Z")

</div>

> that looks right, except for the `onboarding` one: those docs do not have a `service.name` .

The main goal for me - I need to split indices with APM metric data, and, as I know - they are located in `span` indexes (these indexes most huge as I can see)

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [August 18, 2020, 1:27am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/9 "2020-08-18T01:27:57Z")

</div>

The config looks fine. I copy & pasted it, and it worked when I ran it in Docker, placing the config file in /usr/share/apm-server.

```auto
GET /_cat/indices/apm-*

yellow open apm-7.6.1-goat-foo-transaction-2020.08.18 sMqPHbvDRY2PLKk2oRyAbA 1 1 1 0 230b 230b

```

(my `host.name` is "goat", and `service.name` is "foo")

Can you please share the apm-server log?

---

<div class="post-metadata">

**Author:** ![TheVintik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thevintik/32/60494_2.png) [@TheVintik](https://discuss.elastic.co/u/TheVintik)\
**Post date:** [August 18, 2020, 8:24am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/10 "2020-08-18T08:24:45Z")

</div>

@axw looks like something was wrong with my stack of ES + Kibana + APM, because after reinstall all of this - I get necessary indices splitted by project, so, the config is really correct.

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [August 19, 2020, 2:30am UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/11 "2020-08-19T02:30:48Z")

</div>

Great, glad to hear you sorted it out!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 8, 2020, 10:30pm UTC](https://discuss.elastic.co/t/apm-server-not-all-variables-are-working-for-indicies-templates/244847/12 "2020-09-08T22:30:52Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
