Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Installation For New Relic Golang Agent #569

Open
ntcsteve opened this issue Sep 15, 2022 · 1 comment
Open

Update Installation For New Relic Golang Agent #569

ntcsteve opened this issue Sep 15, 2022 · 1 comment

Comments

@ntcsteve
Copy link

I was going through the docs and guided install for Golang, and saw go get isn’t working as instructed. You need to use go mod init XXX/newrelic, before go get. We should update our docs, and guided install. FYI - https://docs.newrelic.com/docs/apm/agents/go-agent/installation/install-new-relic-go.

@urvesh-educloud
Copy link

I am unable to monitor my go project with the new relic

I am able to monitor using JAVA

I have follows the documentation steps: https://docs.newrelic.com/docs/apm/agents/go-agent/installation/install-new-relic-go/

  1. From github.com/newrelic/go-agent, use your preferred process; for example:
    bash command go get github.com/newrelic/go-agent/v3/newrelic

  2. Import the github.com/newrelic/go-agent/v3/newrelic package in your application.
    import github.com/newrelic/go-agent/v3/newrelic

  3. Initialize the Go agent by adding the following in the main function or in an init block:

    app, err := newrelic.NewApplication(
        newrelic.ConfigAppName("Your Application Name"),
        newrelic.ConfigLicense("YOUR_NEW_RELIC_LICENSE_KEY")
    )
    

NOTE: I have follows all the trouble shooting as well.

main.go

package main

import (
	"fmt"
	"io"
	"net/http"

	"github.com/newrelic/go-agent/v3/newrelic"
)

var newrelicApp *newrelic.Application

func main() {
	app, err := newrelic.NewApplication(
		newrelic.ConfigAppName("MyAppMain"),
		newrelic.ConfigLicense("280d644a5b4fc4859d5fa75b8897f4422bb5NRAL"),
		newrelic.ConfigAppLogForwardingEnabled(true),
	)
	if err != nil {
		fmt.Printf("error is " + err.Error())
	} else {
		newrelicApp = app
		http.HandleFunc(newrelic.WrapHandleFunc(app, "/test", customEvent))
	}
}

func customEvent(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, "recording a custom event")

	newrelicApp.RecordCustomEvent("MyAppMainEvent", map[string]interface{}{
		"text":      "Hello VP",
		"env":       "go_local",
		"alertType": "error",
		"priority":  "Critical",
		"source":    "MyAppMain",
	})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants