Adding Sample Data to a Request
You can add other types of metadata to a transaction or span besides tags. The helpers described on this page allow you to overwrite the metadata set by the AppSignal integration or add additional custom data.
Request parameters
By default, the AppSignal integrations track request parameters for web requests in supported libraries. These include query parameters and the POST request body. For background jobs, we store the job arguments in the parameters.
You can set custom parameters on a transaction or span. Modifying the parameters of a transaction will overwrite the data set by the AppSignal instrumentations.
All parameters are filtered by our integrations before being sent to our servers.
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 |
The below code sample shows how to set custom request parameters:
Appsignal.set_params( :post => { :title => "My new blog post!", :body => "Some long blog post text." } )
Appsignal.Span.set_sample_data( Appsignal.Tracer.root_span, "params", %{ post: %{ title: "My new blog post!", body: "Some long blog post text." } } )
import { setParams } from "@appsignal/nodejs"; setParams({ post: { title: "My new blog post!", body: "Some long blog post text.", }, });
from appsignal import set_params set_params({ post: { title: "My new blog post!", body: "Some long blog post text." } })
Only the last value is stored if the application sets parameters multiple times.
![params](/_next/image?url=%2Fassets%2Fimages%2Fscreenshots%2Fsample_data%2Fparams.png&w=1920&q=75)
Request headers
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 by our integrations before being sent to our servers.
See the table below for a list of accepted value types for request headers.
Language | Accepted header name | Accepted header value |
---|---|---|
All | String | String |
The below code sample shows how to set custom request headers:
Appsignal.set_headers( "REQUEST_METHOD" => "GET", "PATH_INFO" => "/some-path" )
Appsignal.Span.set_sample_data( Appsignal.Tracer.root_span, "environment", %{ "request_method" => "GET", "path_info" => "/some-path" } )
import { setHeader } from "@appsignal/nodejs"; setHeader("request_method", "GET"); setHeader("path_info", "/some-path");
from appsignal import set_header set_header("request_method", "GET"); set_header("path_info", "/some-path");
Only the last value for a request header is stored if the application sets request headers multiple times. If the helper is called multiple times, only the last set of request headers (environment) is stored for Ruby and Elixir.
![environment](/_next/image?url=%2Fassets%2Fimages%2Fscreenshots%2Fsample_data%2Fenvironment.png&w=1920&q=75)
Session data
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 by our integrations before being sent to our servers.
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 |
Appsignal.set_session_data(:user_id => "123", :menu => "open")
Appsignal.Span.set_sample_data( Appsignal.Tracer.root_span, "session_data", %{user_id: "123", menu: "open"} )
import { setSessionData } from "@appsignal/nodejs"; setSessionData({ user_id: "123", menu: "open" });
from appsignal import set_session_data set_session_data({"user_id": "123", "menu": "open"})
Only the last value for a request header is stored if the application sets session data multiple times.
![session_data](/_next/image?url=%2Fassets%2Fimages%2Fscreenshots%2Fsample_data%2Fsession-data.png&w=1920&q=75)
Custom data
You can use custom sample data to set more dynamic values than other types of sample data 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.).
Language | Accepted root values |
---|---|
Ruby | Arrays, Hashes |
JavaScript | Arrays, Objects |
Elixir | Lists, Maps |
Python | Lists, Maps |
It is impossible to filter or search on the data set as custom data. 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:
# AppSignal Ruby gem 3.10 and newer # Hash Appsignal.set_custom_data( :stroopwaffle => { :caramel => true, :origin => "market" } ) # Array Appsignal.set_custom_data([ "value 1", "value 2" ]) # AppSignal Ruby gem 3.9 and older # Hash Appsignal::Transaction.current.set_sample_data( "custom_data", :stroopwaffle => { :caramel => true, :origin => "market" } ) # Array Appsignal::Transaction.current.set_sample_data( "custom_data", [ "value 1", "value 2" ] )
# Map Appsignal.Span.set_sample_data( Appsignal.Tracer.root_span, "custom_data", %{ stroopwaffle: %{ caramel: true, origin: "market" } } ) # List Appsignal.Span.set_sample_data( Appsignal.Tracer.root_span, "custom_data", [ "value 1", "value 2" ] )
import { setCustomData } from "@appsignal/nodejs"; // Object setCustomData({ stroopwaffle: { caramel: true, origin: "market", }, }); // Array setCustomData(["value 1", "value 2"]);
from appsignal import set_custom_data # Map set_custom_data({ "stroopwaffle": { "caramel": true, "origin": "market" } }) # Array set_custom_data(["value 1", "value 2"])
Only the last value is stored if the application sets custom data multiple times.
![custom_data](/_next/image?url=%2Fassets%2Fimages%2Fscreenshots%2Fsample_data%2Fcustom-data.png&w=1920&q=75)