2 Star 8 Fork 6

user_499098 / imgproxy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
newrelic.go 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
DarthSim 提交于 2019-05-08 17:42 . Back to net/http
package main
import (
"context"
"net/http"
"time"
newrelic "github.com/newrelic/go-agent"
)
var (
newRelicEnabled = false
newRelicApp newrelic.Application
newRelicTransactionCtxKey = ctxKey("newRelicTransaction")
)
func initNewrelic() {
if len(conf.NewRelicKey) == 0 {
return
}
name := conf.NewRelicAppName
if len(name) == 0 {
name = "imgproxy"
}
var err error
config := newrelic.NewConfig(name, conf.NewRelicKey)
newRelicApp, err = newrelic.NewApplication(config)
if err != nil {
logFatal("Can't init New Relic agent: %s", err)
}
newRelicEnabled = true
}
func startNewRelicTransaction(ctx context.Context, rw http.ResponseWriter, r *http.Request) (context.Context, context.CancelFunc) {
txn := newRelicApp.StartTransaction("request", rw, r)
cancel := func() { txn.End() }
return context.WithValue(ctx, newRelicTransactionCtxKey, txn), cancel
}
func startNewRelicSegment(ctx context.Context, name string) context.CancelFunc {
txn := ctx.Value(newRelicTransactionCtxKey).(newrelic.Transaction)
segment := newrelic.StartSegment(txn, name)
return func() { segment.End() }
}
func sendErrorToNewRelic(ctx context.Context, err error) {
txn := ctx.Value(newRelicTransactionCtxKey).(newrelic.Transaction)
txn.NoticeError(err)
}
func sendTimeoutToNewRelic(ctx context.Context, d time.Duration) {
txn := ctx.Value(newRelicTransactionCtxKey).(newrelic.Transaction)
txn.NoticeError(newrelic.Error{
Message: "Timeout",
Class: "Timeout",
Attributes: map[string]interface{}{
"time": d.Seconds(),
},
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yunwisdoms/imgproxy.git
git@gitee.com:yunwisdoms/imgproxy.git
yunwisdoms
imgproxy
imgproxy
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891