> ## 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 Session Data

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 will track request session data for web applications in supported libraries.

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

[All request session data is filtered](/guides/filter-data/filter-session-data) 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 root values per language. Each nested object can contain values that result in valid JSON (strings, integers, floats, booleans, nulls, etc.).

| Language   | Accepted root values   |
| ---------- | ---------------------- |
| Ruby       | Arrays, Hashes         |
| JavaScript | Arrays, Objects        |
| Elixir     | Lists, Maps            |
| Python     | Lists, Maps            |
| Go         | JSON serialized string |
| Java       | JSON serialized string |
| PHP        | Arrays, Objects        |

<CodeGroup>
  ```ruby Ruby theme={null}
  # Call `add_session_data` multiple times to set more session data
  Appsignal.add_session_data(
    :user_id => "123",
    :menu => { :type => "hamburger" }
  )
  Appsignal.add_session_data(:menu => { :state => "closed" })
  Appsignal.add_session_data(:menu => { :state => "open" })
  # Session data:
  # {
  #   :user_id => "123",
  #   :menu => { :state => "open" }
  # }
  ```

  ```elixir Elixir theme={null}
  Appsignal.Span.set_sample_data(
    Appsignal.Tracer.root_span,
    "session_data",
    %{user_id: "123", menu: "open"}
  )
  ```

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

  setSessionData({ user_id: "123", menu: "open" });
  ```

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

  set_session_data({"user_id": "123", "menu": "open"})
  ```

  ```go Go theme={null}
  // Additional setup is required to first fetch or create a new span
  import (
  	"encoding/json"

  	"go.opentelemetry.io/otel/attribute"
  	"go.opentelemetry.io/otel/trace"
  )

  session_data := map[string]interface{}{
  	"key1": "value1",
  	"key2": "value2",
  	"nested": map[string]interface{}{
  		"key3": "value3",
  		"key4": "value4",
  	},
  }
  json, _ := json.Marshal(session_data)
  span.SetAttributes(attribute.String("appsignal.request.session_data", string(json)))
  ```

  ```java Java theme={null}
  // Additional setup is required to first fetch or create a new span
  import io.opentelemetry.api.trace.Span;
  // We're using the Jackson JSON library
  // You may need to add it to your project as a dependency
  import com.fasterxml.jackson.databind.ObjectMapper;
  import java.util.HashMap;
  import java.util.Map;

  Map<String, Object> sessionData = new HashMap<>();
  sessionData.put("user_id", "123");
  sessionData.put("menu", "open");

  Map<String, String> nested = new HashMap<>();
  nested.put("key3", "value3");
  nested.put("key4", "value4");
  sessionData.put("nested", nested);

  try {
      ObjectMapper mapper = new ObjectMapper();
      String jsonString = mapper.writeValueAsString(sessionData);

      Span span = Span.current();
      span.setAttribute("appsignal.request.session_data", jsonString);
  } catch (Exception e) {
      // Add error handling here
  }
  ```

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

  $data = [
      'param1' => 'value1',
      'param2' => 'value2',
      'nested' => [
          'param3' => 'value3',
          'param4' => 'value4',
      ],
  ];

  Appsignal::setSessionData($data);
  ```
</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/session-data.png?fit=max&auto=format&n=MS9b5WO71lSfD5jG&q=85&s=33aa45b3b82dd9c45234e7ea4fbf2c19" alt="session_data" width="756" height="212" data-path="assets/images/screenshots/sample_data/session-data.png" />

## Limitations

If the application sets session data multiple times, the Ruby gem will merge values at the root level.
For other integrations, only the last set value is stored.
