feat:add trace db.statement、host.name

This commit is contained in:
houseme
2021-12-02 18:54:56 +08:00
parent 30a597cadc
commit 5ed5adc6df
2 changed files with 6 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
"go.opentelemetry.io/otel/trace"
"github.com/gogf/gf/v2"
@ -54,6 +55,7 @@ func (c *Core) addSqlToTracing(ctx context.Context, sql *Sql) {
labels = append(labels, gtrace.CommonLabels()...)
labels = append(labels,
attribute.String(tracingAttrDbType, c.db.GetConfig().Type),
attribute.String(string(semconv.DBStatementKey), sql.Format),
)
if c.db.GetConfig().Host != "" {
labels = append(labels, attribute.String(tracingAttrDbHost, c.db.GetConfig().Host))

View File

@ -12,16 +12,17 @@ import (
"os"
"strings"
"github.com/gogf/gf/v2/internal/command"
"github.com/gogf/gf/v2/util/gconv"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
"go.opentelemetry.io/otel/trace"
"github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/internal/command"
"github.com/gogf/gf/v2/net/gipv4"
"github.com/gogf/gf/v2/util/gconv"
)
const (
@ -68,6 +69,7 @@ func CommonLabels() []attribute.KeyValue {
return []attribute.KeyValue{
attribute.String(tracingCommonKeyIpHostname, hostname),
attribute.String(tracingCommonKeyIpIntranet, intranetIpStr),
semconv.HostNameKey.String(hostname),
}
}