1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package newrelic
import (
"net/http"
"github.com/newrelic/go-agent/v3/internal/cat"
)
// InboundHTTPRequest adds the inbound request metadata to the txnCrossProcess.
func (txp *txnCrossProcess) InboundHTTPRequest(hdr http.Header) error {
return txp.handleInboundRequestHeaders(httpHeaderToMetadata(hdr))
}
// appDataToHTTPHeader encapsulates the given appData value in the correct HTTP
// header.
func appDataToHTTPHeader(appData string) http.Header {
header := http.Header{}
if appData != "" {
header.Add(cat.NewRelicAppDataName, appData)
}
return header
}
// httpHeaderToAppData gets the appData value from the correct HTTP header.
func httpHeaderToAppData(header http.Header) string {
if header == nil {
return ""
}
return header.Get(cat.NewRelicAppDataName)
}
// httpHeaderToMetadata gets the cross process metadata from the relevant HTTP
// headers.
func httpHeaderToMetadata(header http.Header) crossProcessMetadata {
if header == nil {
return crossProcessMetadata{}
}
return crossProcessMetadata{
ID: header.Get(cat.NewRelicIDName),
TxnData: header.Get(cat.NewRelicTxnName),
Synthetics: header.Get(cat.NewRelicSyntheticsName),
}
}
// metadataToHTTPHeader creates a set of HTTP headers to represent the given
// cross process metadata.
func metadataToHTTPHeader(metadata crossProcessMetadata) http.Header {
header := http.Header{}
if metadata.ID != "" {
header.Add(cat.NewRelicIDName, metadata.ID)
}
if metadata.TxnData != "" {
header.Add(cat.NewRelicTxnName, metadata.TxnData)
}
if metadata.Synthetics != "" {
header.Add(cat.NewRelicSyntheticsName, metadata.Synthetics)
}
return header
}
|