stackimpact-go icon indicating copy to clipboard operation
stackimpact-go copied to clipboard

App Engine support

Open benguild opened this issue 8 years ago • 6 comments

Hey guys, I was looking into this and noticed that doesn’t seem to be App Engine compatible. On App Engine:

  1. the syscall library isn’t available.
  2. the standard HTTP client isn’t available, but requests can create and provide one while active using their context. — See here, for example: https://github.com/stripe/stripe-go#google-appengine

Is it possible that support could be added? There are a lot of Go applications running on App Engine.

benguild avatar Nov 14 '17 08:11 benguild

The agent is now compatible with App Engine, starting v2.2.3. However, the ppof panics in App Engine standard environment. We'll try to find out if profiling is possible at all. In App Engine flexible environment the agent works without any problems.

The agent can still be used App Engine standard local development environment. Because of the limitations on background tasks and context dependency of http client, the agent should be used in manual profiling and reporting mode (see readme), here is an example:

package hello

import (
	"fmt"
	"net/http"

	"google.golang.org/appengine"
	"google.golang.org/appengine/urlfetch"

	"github.com/stackimpact/stackimpact-go"
)

var agent *stackimpact.Agent

func init() {
	agent = stackimpact.Start(stackimpact.Options{
		AgentKey: "your agent key",
		AppName: "AppEngineStandardApp",
		DisableAutoProfiling: true,
	})

	http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
	span := agent.Profile()
	defer span.Stop()

	ctx := appengine.NewContext(r)
	client := urlfetch.Client(ctx)
	defer agent.ReportWithHTTPClient(client)

	fmt.Fprintln(w, "Hello, world!")
}

dmelikyan avatar Nov 16 '17 10:11 dmelikyan

So you're saying that the code above will not work in Standard on a live deployment?

benguild avatar Nov 16 '17 10:11 benguild

It didn't work for me, the pprof panics. I've also tried pprof CPU profiler directly, without the agent, same error.

dmelikyan avatar Nov 16 '17 10:11 dmelikyan

You can't CPU profile on App Engine Standard as far as I know. However, you can use heap profiling and some others.

benguild avatar Nov 16 '17 10:11 benguild

I'll see if any of the profilers works. If yes, then we could add a possibility to disable some profilers and keep only supported ones.

dmelikyan avatar Nov 16 '17 10:11 dmelikyan

Anything that uses syscall is banned, and probably some others. However the heap one definitely works.

benguild avatar Nov 16 '17 10:11 benguild