apm-agent-nodejs
apm-agent-nodejs copied to clipboard
disable tracestate and traceparent headers from http request
Is your feature request related to a problem? Please describe. Similar to this one https://discuss.elastic.co/t/how-to-disable-tracestate-and-traceparent-headers/324164
Describe the solution you'd like Be able to disable tracestate and traceparent headers on HTTP outgoing requests
Describe alternatives you've considered disabling apm
Additional context this is breaking our HTTP outgoing requests
can I disable tracestate and traceparent for some domains and keep the others?
Hi @sibelius
I would like to have more context on this issue. In which way having extra headers on your request breaks the request to the external service?
it is similar to this one https://discuss.elastic.co/t/how-to-disable-tracestate-and-traceparent-headers/324164
bank APIs are very strict, if you add another header that is not expected the request is broken
I'd like to disable these headers for some requests, hostname, but not for all
what is the best way to add these options?
Hi @sibelius
the team discussed this internally and we will proceed to implement the same config option as the Java agent has. This will completely remove tracestate and traceparent headers of all outgoing requests.
Having such an advanced feature like filtering per domain/hostname is not planned since we are focusing on the Elastic Distribution of OpenTelemetery for Node.js.
Cheers
here is my patch
diff --git a/lib/instrumentation/http-shared.js b/lib/instrumentation/http-shared.js
index b01397c9238f9e899262a38a232a10769afe4b6c..286ac297e3c940e5702ade1ffbff4e4e912f83d9 100644
--- a/lib/instrumentation/http-shared.js
+++ b/lib/instrumentation/http-shared.js
@@ -275,12 +275,32 @@ exports.traceOutgoingRequest = function (agent, moduleName, method) {
parentRunContext.currTransaction();
if (parent) {
const headers = Object.assign({}, options.headers);
- parent.propagateTraceContextHeaders(
- headers,
- function (carrier, name, value) {
- carrier[name] = value;
- },
- );
+
+
+ if (!options?.hostname?.includes('domainToExclude')) {
+ parent.propagateTraceContextHeaders(
+ headers,
+ function(carrier, name, value) {
+ carrier[name] = value;
+ },
+ );
+ }
options.headers = headers;
}