The below code sample shows how to set custom request headers:

Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
| Language | Accepted header name | Accepted header value |
|---|---|---|
| Ruby | String | String |
| Elixir | String | String |
| Node.js | String | String |
| Python | String | String |
| Go | String | String, String slice |
| Java | String | String, String array |
| PHP | String | String, String array |
# Call `add_headers` multiple times to set more headers
Appsignal.add_headers("REQUEST_METHOD" => "GET", "REQUEST_PATH" => "/some-path")
Appsignal.add_headers("PATH_INFO" => "/a-path")
Appsignal.add_headers("PATH_INFO" => "/some-path")
# Headers:
# {
# "REQUEST_METHOD" => "GET",
# "REQUEST_PATH" => "/some-path",
# "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");
// Additional setup is required to first fetch or create a new span
span.SetAttributes(attribute.StringSlice("http.request.header.content-type", []string{"application/json"}))
span.SetAttributes(attribute.StringSlice("http.request.header.custom-header"), []string{"abc", "def"})
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.common.AttributeKey;
import java.util.Arrays;
// Additional setup is required to first fetch or create a new span
Span span = Span.current();
// Set single header values
span.setAttribute("http.request.header.request-method", "GET");
span.setAttribute("http.request.header.path-info", "/some-path");
span.setAttribute("http.request.header.content-type", "application/json");
// Set header with multiple values (array)
span.setAttribute(
AttributeKey.stringArrayKey("http.request.header.custom-header"),
Arrays.asList("value1", "value2")
);
<?php
use Appsignal\Appsignal;
// Set single header values
Appsignal::addHeaders([
'request-method' => 'GET',
'path-info' => '/some-path',
'content-type' => 'application/json',
]);
// Set header with multiple values (array)
Appsignal::addHeaders([
'custom-header' => ['value1', 'value2'],
]);

Was this page helpful?