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. 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.).

LanguageAccepted root values
RubyArrays, Hashes
JavaScriptArrays, Objects
ElixirLists, Maps

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:

ruby
# Hash Appsignal::Transaction.current.set_sample_data( "custom_data", :i18n => { :locale => "en_GB", :default_locale => "en_US" } ) # Array Appsignal::Transaction.current.set_sample_data( "custom_data", [ "value 1", "value 2" ] )

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.

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:

elixir
# Map Appsignal.Span.set_sample_data( Appsignal.Tracer.root_span, "custom_data", %{ i18n: %{ locale: "en_GB", default_locale: "en_US" } } ) # List Appsignal.Span.set_sample_data( Appsignal.Tracer.root_span, "custom_data", [ "value 1", "value 2" ] )

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.

javascript
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.

javascript
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.

javascript
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.

javascript
import { setCustomData } from "@appsignal/nodejs"; // Object setCustomData({ stroopwaffle: "true", coffee: "false" }); // Array setCustomData(["value 1", "value 2"]);

Python

Our Python helper methods allow you to set various data types on the active span.

set_session_data

The set_session_data helper method allows you to set session data on the active span.

python
from appsignal import set_session_data set_session_data({"_csrf_token": "Z11CWRVG+I2egpmiZzuIx/qbFb/60FZssui5eGA8a3g="})

This helper method 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

set_params

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

python
from appsignal import set_params set_params({"action": "show", "controller": "homepage"})

This helper method 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

set_header

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 set_params helper method.

python
from appsignal import set_header set_header("content_length", 0);

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

environment

set_custom_data

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

python
from appsignal import set_custom_data # Map set_custom_data({"stroopwaffle": "true", "coffee": "false"}) # Array set_custom_data(["value 1", "value 2"])