> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Request Headers

export const Compatibility = ({versions = [], label = "Available in"}) => {
  if (!Array.isArray(versions) || versions.length === 0) {
    return null;
  }
  const defaultPillStyle = {
    borderColor: "#d4d4d8",
    background: "#f4f4f5",
    color: "#3f3f46"
  };
  const pillStyles = {
    "AppSignal for Elixir": {
      background: "#f3e8ff",
      borderColor: "#d8b4fe",
      color: "#6b21a8"
    },
    "AppSignal for Front-end": {
      background: "#fef9c3",
      borderColor: "#fde047",
      color: "#854d0e"
    },
    "AppSignal for Go": {
      background: "#ccfbf1",
      borderColor: "#5eead4",
      color: "#115e59"
    },
    "AppSignal for JavaScript": {
      background: "#fef9c3",
      borderColor: "#fde047",
      color: "#854d0e"
    },
    "AppSignal for Node.js": {
      background: "#dcfce7",
      borderColor: "#86efac",
      color: "#166534"
    },
    "AppSignal for Python": {
      background: "#dbeafe",
      borderColor: "#93c5fd",
      color: "#1e40af"
    },
    "AppSignal for Ruby": {
      background: "#fee2e2",
      borderColor: "#fca5a5",
      color: "#991b1b"
    },
    "AppSignal for Rust": {
      background: "#ffedd5",
      borderColor: "#fdba74",
      color: "#9a3412"
    }
  };
  const getPillStyle = name => ({
    ...defaultPillStyle,
    ...pillStyles[name] || ({})
  });
  return <div className="not-prose my-4 rounded-lg border border-zinc-200 bg-zinc-50 px-4 py-3 text-sm dark:border-white/10 dark:bg-white/5">
      <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
        <span className="font-semibold text-zinc-700 dark:text-zinc-200">
          {label}:
        </span>
        {versions.map((v, i) => <span key={`${v.name}-${v.version}-${i}`} className="inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-medium" style={getPillStyle(v.name)}>
            <span>{v.name}</span>
            <span className="opacity-70">
              {v.version}
              {v.exact ? "" : "+"}
            </span>
          </span>)}
      </div>
    </div>;
};

<Compatibility
  versions={[
{ name: "AppSignal for Ruby", version: "4.0.0" },
{ name: "AppSignal for Elixir", version: "1.0.0" },
{ name: "AppSignal for Node.js", version: "3.0.0" },
{ name: "AppSignal for Python", version: "0.3.0" },
{ name: "AppSignal Collector", version: "0.6.0" },
{ name: "AppSignal for PHP", version: "0.5.0" },
]}
/>

By default, the AppSignal integrations track request HTTP headers for web applications in supported libraries.

You can set custom request headers on a transaction or span. Modifying the request headers will overwrite the data set by the AppSignal instrumentations.

[All request headers are filtered](/guides/filter-data/filter-headers) by our integrations before being sent to our servers.

<Warning>
  🔐 Do not send <strong>Personal Identifiable Information (PII)</strong> to AppSignal. Filter PII (e.g., names, emails) and use an ID, hash, or pseudonymized identifier instead. <br /> <br /> Use [Link Templates](https://docs.appsignal.com/application/link-templates) to link them back in your app.
</Warning>

See the table below for a list of accepted value types for request headers.

| Language | Accepted header name | Accepted header value |
| -------- | -------------------- | --------------------- |
| Ruby     | String               | String                |
| Elixir   | String               | String                |
| Node.js  | String               | String                |
| Python   | String               | String                |
| Go       | String               | String, String slice  |
| Java     | String               | String, String array  |
| PHP      | String               | String, String array  |

The below code sample shows how to set custom request headers:

<CodeGroup>
  ```ruby Ruby theme={null}
  # Call `add_headers` multiple times to set more headers
  Appsignal.add_headers("REQUEST_METHOD" => "GET", "REQUEST_PATH" => "/some-path")
  Appsignal.add_headers("PATH_INFO" => "/a-path")
  Appsignal.add_headers("PATH_INFO" => "/some-path")
  # Headers:
  # {
  #   "REQUEST_METHOD" => "GET",
  #   "REQUEST_PATH" => "/some-path",
  #   "PATH_INFO" => "/some-path"
  # }
  ```

  ```elixir Elixir theme={null}
  Appsignal.Span.set_sample_data(
    Appsignal.Tracer.root_span,
    "environment",
    %{
      "request_method" => "GET",
      "path_info" => "/some-path"
    }
  )
  ```

  ```javascript Node.js theme={null}
  import { setHeader } from "@appsignal/nodejs";

  setHeader("request_method", "GET");
  setHeader("path_info", "/some-path");
  ```

  ```python Python theme={null}
  from appsignal import set_header

  set_header("request_method", "GET");
  set_header("path_info", "/some-path");
  ```

  ```go Go theme={null}
  // Additional setup is required to first fetch or create a new span
  span.SetAttributes(attribute.StringSlice("http.request.header.content-type", []string{"application/json"}))
  span.SetAttributes(attribute.StringSlice("http.request.header.custom-header"), []string{"abc", "def"})
  ```

  ```java Java theme={null}
  import io.opentelemetry.api.trace.Span;
  import io.opentelemetry.api.common.AttributeKey;
  import java.util.Arrays;

  // Additional setup is required to first fetch or create a new span
  Span span = Span.current();

  // Set single header values
  span.setAttribute("http.request.header.request-method", "GET");
  span.setAttribute("http.request.header.path-info", "/some-path");
  span.setAttribute("http.request.header.content-type", "application/json");

  // Set header with multiple values (array)
  span.setAttribute(
      AttributeKey.stringArrayKey("http.request.header.custom-header"),
      Arrays.asList("value1", "value2")
  );
  ```

  ```php PHP theme={null}
  <?php
  use Appsignal\Appsignal;

  // Set single header values
  Appsignal::addHeaders([
      'request-method' => 'GET',
      'path-info' => '/some-path',
      'content-type' => 'application/json',
  ]);

  // Set header with multiple values (array)
  Appsignal::addHeaders([
      'custom-header' => ['value1', 'value2'],
  ]);
  ```
</CodeGroup>

For certain languages, additional setup is required.
Please follow the instructions for these languages:

* [Go](/go/custom-instrumentation)
* [Java](/java/custom-instrumentation)

<img src="https://mintcdn.com/appsignal-715f5a51/MS9b5WO71lSfD5jG/assets/images/screenshots/sample_data/environment.png?fit=max&auto=format&n=MS9b5WO71lSfD5jG&q=85&s=a49d2e57199a1a6cedce022104387b96" alt="environment" width="756" height="621" data-path="assets/images/screenshots/sample_data/environment.png" />

## Limitations

Only the last value for a request header is stored if the application sets a request header multiple times.

For Elixir, if the helper is called multiple times, only the last set of request headers (environment) is stored.
