github.com/newrelic/go-agent@v3.26.0+incompatible/internal/tools/rules/main.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package main 5 6 import ( 7 "encoding/json" 8 "fmt" 9 "io/ioutil" 10 "os" 11 12 "github.com/newrelic/go-agent/internal" 13 ) 14 15 func fail(reason string) { 16 fmt.Println(reason) 17 os.Exit(1) 18 } 19 20 func main() { 21 if len(os.Args) < 3 { 22 fail("improper usage: ./rules path/to/reply_file input") 23 } 24 25 connectReplyFile := os.Args[1] 26 name := os.Args[2] 27 28 data, err := ioutil.ReadFile(connectReplyFile) 29 if nil != err { 30 fail(fmt.Sprintf("unable to open '%s': %s", connectReplyFile, err)) 31 } 32 33 var reply internal.ConnectReply 34 err = json.Unmarshal(data, &reply) 35 if nil != err { 36 fail(fmt.Sprintf("unable unmarshal reply: %s", err)) 37 } 38 39 // Metric Rules 40 out := reply.MetricRules.Apply(name) 41 fmt.Println("metric rules applied:", out) 42 43 // Url Rules + Txn Name Rules + Segment Term Rules 44 45 out = internal.CreateFullTxnName(name, &reply, true) 46 fmt.Println("treated as web txn name:", out) 47 48 out = internal.CreateFullTxnName(name, &reply, false) 49 fmt.Println("treated as backround txn name:", out) 50 }