Prevent build up of duplicate Distributed Tracing headers #120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR prevents a build up of Distributed Tracing headers from being added to a request when using
file_get_contents
and reusing the stream context parameter.It does this by:
file_get_contents
, this triggers the modified detection logic in the trace endpointnr_php_file_get_contents_add_headers_internal
to detect if one of the DT headers are present in both the existing headers string and the headers that are about to be added. This change assumes that all of the DT headers are added as a group and that detecting one of them is sufficient.The flow goes roughly like this:
nr_php_file_get_contents_create_outbound_headers
callsnr_header_create_outbound_request_create
. The resulting headers are converted to a string.nr_php_file_get_contents_add_headers
tonr_php_file_get_contents_add_headers_internal
which concats the new headers to the existing headers.In this flow, the existing headers are already a string. This changes attempts to reparse the existing headers to reduce overhead. The simplest approach seems to be just looking for the presence of a key phrase when determining if the DT headers are already present and are about to be added.
W3C_TRACESTATE
was somewhat arbitrarily chosen.NEWRELIC
can be optionally excluded via configuration so it wasn't an option.W3C_TRACEPARENT
was the other option.A colon is included in the searched for string to avoid matching any content in the value portion of any of the headers.