Skip to content

Commit

Permalink
synthetics done
Browse files Browse the repository at this point in the history
  • Loading branch information
nr-swilloughby committed Dec 14, 2023
1 parent 7896f19 commit 37461f9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion v3/internal/cat/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ const (
NewRelicTxnName = "X-Newrelic-Transaction"
NewRelicAppDataName = "X-Newrelic-App-Data"
NewRelicSyntheticsName = "X-Newrelic-Synthetics"
NewRelicSyntheticsInfo = "X-Newrelic-Synthecics-Info"
NewRelicSyntheticsInfo = "X-Newrelic-Synthetics-Info"
)
9 changes: 5 additions & 4 deletions v3/newrelic/cross_process_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func httpHeaderToMetadata(header http.Header) crossProcessMetadata {
}

return crossProcessMetadata{
ID: header.Get(cat.NewRelicIDName),
TxnData: header.Get(cat.NewRelicTxnName),
Synthetics: header.Get(cat.NewRelicSyntheticsName),
ID: header.Get(cat.NewRelicIDName),
TxnData: header.Get(cat.NewRelicTxnName),
Synthetics: header.Get(cat.NewRelicSyntheticsName),
SyntheticsInfo: header.Get(cat.NewRelicSyntheticsInfo),
}
}

Expand All @@ -67,7 +68,7 @@ func metadataToHTTPHeader(metadata crossProcessMetadata) http.Header {

// This header will only be present when the `X-NewRelic-Synthetics` header is present
if metadata.SyntheticsInfo != "" {

header.Add(cat.NewRelicSyntheticsInfo, metadata.SyntheticsInfo)
}
}

Expand Down
3 changes: 2 additions & 1 deletion v3/newrelic/txn_cross_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (txp *txnCrossProcess) CreateCrossProcessMetadata(txnName, appName string)
// outbound request headers.
if txp.IsSynthetics() {
metadata.Synthetics = txp.SyntheticsHeader
metadata.SyntheticsInfo = txp.SyntheticsInfoHeader
}

if txp.Enabled {
Expand Down Expand Up @@ -149,7 +150,7 @@ func (txp *txnCrossProcess) IsSynthetics() bool {
// pointer should be sufficient to determine if this is a synthetics
// transaction. Nevertheless, it's convenient to have the Type field be
// non-zero if any CAT behaviour has occurred.
return 0 != (txp.Type&txnCrossProcessSynthetics) && nil != txp.Synthetics
return (txp.Type&txnCrossProcessSynthetics) != 0 && txp.Synthetics != nil
}

// ParseAppData decodes the given appData value.
Expand Down
20 changes: 12 additions & 8 deletions v3/newrelic/txn_cross_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ func TestTxnCrossProcessCreateCrossProcessMetadata(t *testing.T) {
appName: "app",
expectedError: false,
expectedMetadata: crossProcessMetadata{
Synthetics: mustObfuscate(`[1,1,"resource","job","monitor"]`, "foo"),
Synthetics: mustObfuscate(`[1,1,"resource","job","monitor"]`, "foo"),
SyntheticsInfo: mustObfuscate(`{"version":1,"type":"scheduled","initiator":"cli"}`, "foo"),
},
},
{
Expand All @@ -267,7 +268,8 @@ func TestTxnCrossProcessCreateCrossProcessMetadata(t *testing.T) {
appName: "app",
expectedError: false,
expectedMetadata: crossProcessMetadata{
Synthetics: mustObfuscate(`[1,1,"resource","job","monitor"]`, "foo"),
Synthetics: mustObfuscate(`[1,1,"resource","job","monitor"]`, "foo"),
SyntheticsInfo: mustObfuscate(`{"version":1,"type":"scheduled","initiator":"cli"}`, "foo"),
},
},
{
Expand All @@ -292,9 +294,10 @@ func TestTxnCrossProcessCreateCrossProcessMetadata(t *testing.T) {
appName: "app",
expectedError: false,
expectedMetadata: crossProcessMetadata{
ID: mustObfuscate(`1#1`, "foo"),
TxnData: mustObfuscate(`["00000000",false,"00000000","b95be233"]`, "foo"),
Synthetics: mustObfuscate(`[1,1,"resource","job","monitor"]`, "foo"),
ID: mustObfuscate(`1#1`, "foo"),
TxnData: mustObfuscate(`["00000000",false,"00000000","b95be233"]`, "foo"),
Synthetics: mustObfuscate(`[1,1,"resource","job","monitor"]`, "foo"),
SyntheticsInfo: mustObfuscate(`{"version":1,"type":"scheduled","initiator":"cli"}`, "foo"),
},
},
{
Expand All @@ -319,9 +322,10 @@ func TestTxnCrossProcessCreateCrossProcessMetadata(t *testing.T) {
appName: "app",
expectedError: false,
expectedMetadata: crossProcessMetadata{
ID: mustObfuscate(`1#1`, "foo"),
TxnData: mustObfuscate(`["00000000",false,"abcdefgh","cbec2654"]`, "foo"),
Synthetics: mustObfuscate(`[1,1,"resource","job","monitor"]`, "foo"),
ID: mustObfuscate(`1#1`, "foo"),
TxnData: mustObfuscate(`["00000000",false,"abcdefgh","cbec2654"]`, "foo"),
Synthetics: mustObfuscate(`[1,1,"resource","job","monitor"]`, "foo"),
SyntheticsInfo: mustObfuscate(`{"version":1,"type":"scheduled","initiator":"cli"}`, "foo"),
},
},
} {
Expand Down
10 changes: 10 additions & 0 deletions v3/newrelic/txn_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package newrelic

import (
"bytes"
"fmt"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -113,6 +114,15 @@ func sharedTransactionIntrinsics(e *txnEvent, w *jsonFieldsWriter) {
w.stringField("nr.syntheticsResourceId", e.CrossProcess.Synthetics.ResourceID)
w.stringField("nr.syntheticsJobId", e.CrossProcess.Synthetics.JobID)
w.stringField("nr.syntheticsMonitorId", e.CrossProcess.Synthetics.MonitorID)
if e.CrossProcess.SyntheticsInfo != nil {
w.stringField("nr.syntheticsType", e.CrossProcess.SyntheticsInfo.Type)
w.stringField("nr.syntheticsInitiator", e.CrossProcess.SyntheticsInfo.Initiator)
for attrName, attrValue := range e.CrossProcess.SyntheticsInfo.Attributes {
if attrName != "" {
w.stringField(fmt.Sprintf("nr.synthetics%s%s", strings.ToUpper(attrName[0:1]), attrName[1:]), attrValue)
}
}
}
}
}

Expand Down

0 comments on commit 37461f9

Please sign in to comment.