-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreporter.go
47 lines (42 loc) · 1.08 KB
/
reporter.go
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
package nrgorm
import (
"github.com/jinzhu/gorm"
"github.com/newrelic/go-agent"
)
type reporter interface {
Report(startTime *newrelic.SegmentStartTime, tableName string, sql string, op operation) error
}
type repoImpl struct {
product newrelic.DatastoreProduct
dbName string
}
func newReporter(db *gorm.DB, dbName string) reporter {
var product newrelic.DatastoreProduct
switch db.Dialect().GetName() {
case "postgres":
product = newrelic.DatastorePostgres
case "mysql":
product = newrelic.DatastoreMySQL
case "sqlite3":
product = newrelic.DatastoreSQLite
case "mssql":
product = newrelic.DatastoreMSSQL
default:
// TODO: Should return an error
}
return &repoImpl{
product: product,
dbName: dbName,
}
}
func (r *repoImpl) Report(startTime *newrelic.SegmentStartTime, tableName string, sql string, op operation) error {
seg := newrelic.DatastoreSegment{
StartTime: *startTime,
Product: r.product,
Collection: tableName,
Operation: op.Name(sql),
ParameterizedQuery: sql,
DatabaseName: r.dbName,
}
return seg.End()
}