Adding sample data to a request

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

Warning: Do not use sample data 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 can use link templates in combination with tags to link them back to your own system.

Custom data

Custom data is a sample data "key" that can be used to set more dynamic values than tags allow. This includes nested objects (JavaScript), maps (Elixir) and hashes (Ruby). It is not possible to filter or search on data set on the "custom_data" key, it is only there to provide an additional area in the interface to list more metadata.

This "custom_data" sample data key accepts nested objects. This will result in the following block on a Incident Sample page for both Exception and Performance samples formatted as JSON.

custom_data

Ruby

custom_data

Set custom data on the sample to add additional debugging data about the sample error or performance issue.

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

Elixir

params

Store custom parameters with the params key on the sample data. This is usually set by integrations provided by AppSignal for libraries such as Plug and Phoenix. By modifying the params on the sample data the data set by the AppSignal library integrations will be overwritten.

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

Sample data with the following key/value pairs can be set on the root span:

const span = tracer.currentSpan();
span.setSampleData("key", { string: "value", number: 123 }); // sets additional sample data

The first argument to setSampleData takes a key, that can be one of the following:

session_data

Filled with session data by default, but can be overridden with the following call:

span.setSampleData("session_data", {
  _csrf_token: "Z11CWRVG+I2egpmiZzuIx/qbFb/60FZssui5eGA8a3g=",
});

This key accepts nested objects that will be rendered as JSON on a Incident Sample page for both Exception and Performance samples.

session_data

params

Filled with framework (such as Express) parameters by default, but can be overridden or filled with the following call:

span.setSampleData("params", { string: "value", number: 123 });

This key accepts nested objects and will show up as follows on a Incident Sample page for both Exception and Performance samples, formatted as JSON.

params

environment

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 following call:

span.setSampleData("environment", { CONTENT_LENGTH: "0" });

This call only accepts a one-level key/value object, nested values will be ignored. This will result the following block on a Incident Sample page for both Exception and Performance samples.

environment

custom_data

Set custom data on the sample to add additional debugging data about the sample error or performance issue.

span.setSampleData("custom_data", {
  i18n: {
    locale: "en_GB",
    default_locale: "en_US",
  },
});

Next steps


Want to help us improve this documentation page?

Create a pull request

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