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
|
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package internal
import (
"bytes"
"time"
)
// MarshalJSON is used for testing.
func (e *ErrorEvent) MarshalJSON() ([]byte, error) {
buf := bytes.NewBuffer(make([]byte, 0, 256))
e.WriteJSON(buf)
return buf.Bytes(), nil
}
// WriteJSON prepares JSON in the format expected by the collector.
// https://source.datanerd.us/agents/agent-specs/blob/master/Error-Events.md
func (e *ErrorEvent) WriteJSON(buf *bytes.Buffer) {
w := jsonFieldsWriter{buf: buf}
buf.WriteByte('[')
buf.WriteByte('{')
w.stringField("type", "TransactionError")
w.stringField("error.class", e.Klass)
w.stringField("error.message", e.Msg)
w.floatField("timestamp", timeToFloatSeconds(e.When))
w.stringField("transactionName", e.FinalName)
sharedTransactionIntrinsics(&e.TxnEvent, &w)
sharedBetterCATIntrinsics(&e.TxnEvent, &w)
buf.WriteByte('}')
buf.WriteByte(',')
userAttributesJSON(e.Attrs, buf, destError, e.ErrorData.ExtraAttributes)
buf.WriteByte(',')
agentAttributesJSON(e.Attrs, buf, destError)
buf.WriteByte(']')
}
type errorEvents struct {
*analyticsEvents
}
func newErrorEvents(max int) *errorEvents {
return &errorEvents{
analyticsEvents: newAnalyticsEvents(max),
}
}
func (events *errorEvents) Add(e *ErrorEvent, priority Priority) {
events.addEvent(analyticsEvent{priority, e})
}
func (events *errorEvents) MergeIntoHarvest(h *Harvest) {
h.ErrorEvents.mergeFailed(events.analyticsEvents)
}
func (events *errorEvents) Data(agentRunID string, harvestStart time.Time) ([]byte, error) {
return events.CollectorJSON(agentRunID)
}
func (events *errorEvents) EndpointMethod() string {
return cmdErrorEvents
}
|