Adding Sample Data to a Request

Besides tags it's possible to add more metadata to a transaction or span. This allows you to overwrite metadata set by the AppSignal integration or add additonal custom data.

Do not use tagging to send personal data such as names or email addresses to AppSignal. If you want to identify a person, consider using a user ID, hash, or pseudonymized identifier instead. You could also use Link Templates to link them back to them in your application.

Custom Data

You can use the custom_data key to set more dynamic values than tags allow. Custom data can include nested objects (JavaScript), maps (Elixir), and hashes (Ruby). It is not possible to filter or search on the data set in the custom_data key. It only provides an additional area in the interface to list more metadata.

When using "custom_data" for nested objects you can view the object on the Incident Sample page for both Exception and Performance samples formatted as JSON, like in the example below:

custom_data

Ruby

custom_data

You can use the set_sample_data method to add additional custom_data related to the sample error or performance issue, like in the example below:

Appsignal::Transaction.current.set_sample_data(
  "custom_data",
  :i18n => {
    :locale => "en_GB",
    :default_locale => "en_US"
  }
)

Elixir

params

You can store custom parameters with the params key in the sample data. This is usually set by integrations provided by AppSignal for libraries such as Plug and Phoenix. By modifying the params of the sample data, You can change the params in sample data to overwrite the data set by the AppSignal library integrations.

The code sample below shows how this can be done in Elixir.

Appsignal.Span.set_sample_data(
  Appsignal.Tracer.root_span,
  "params",
  %{
    i18n: %{
      locale: "en_GB",
      default_locale: "en_US"
    }
  }
)

custom_data

Set custom_data on the sample to add additional debugging data about the sample error or performance issue:

Appsignal.Span.set_sample_data(
  Appsignal.Tracer.root_span,
  "custom_data",
  %{
    i18n: %{
      locale: "en_GB",
      default_locale: "en_US"
    }
  }
)

Node.js

Our Node.js helper functions allow you to set various data types on the active span.

setSessionData

The setSessionData helper function allows you to set session data on the active span.

import { setSessionData } from "@appsignal/nodejs";
 
setSessionData(_csrf_token: "Z11CWRVG+I2egpmiZzuIx/qbFb/60FZssui5eGA8a3g=");

This helper function accepts nested objects that will be rendered as JSON on an Incident Sample page for both Exception and Performance samples, like in the example below.

session_data

setParams

The setParams helper function allows you to set parameter data on the active span. The parameters set must be serializable to JSON.

import { setParams } from "@appsignal/nodejs";
 
setParams({ action: "show", controller: "homepage" });

This helper function accepts nested objects and will show up as follows on an Incident Sample page for both Exception and Performance samples, formatted as JSON, like in the example below.

params

setHeader

Environment variables from a request/background job (typically filled by the default http integration, but can be further augmented by other integrations), but can be filled/overridden with the setParams helper function.

import { setHeader } from "@appsignal/nodejs";
 
setHeader("CONTENT_LENGTH", 0);

Using this call will result in the following block on an Incident Sample page for both Exception and Performance samples:

environment

setCustomData

The setCustomData helper function allows you to set custom data on the active span. The data set must be serializable to JSON.

import { setCustomData } from "@appsignal/nodejs";
 
setCustomData({ stroopwaffle: "true", coffee: "false" });

Need more help?

Contact us and speak directly with the engineers working on AppSignal. They will help you get set up, tweak your code and make sure you get the most out of using AppSignal.

Contact us

Start a trial - 30 days free

AppSignal is a great way to monitor your Ruby, Elixir & Node.js applications. Works great with Rails, Phoenix, Express and other frameworks, with support for background jobs too. Let's improve your apps together.

Start a trial