From 02c6deaec8b9b021cd6d4899dac03da6e44fa483 Mon Sep 17 00:00:00 2001 From: houseme Date: Sun, 19 Dec 2021 00:18:18 +0800 Subject: [PATCH 1/2] feat:modify trace-ID to TraceID --- net/ghttp/ghttp.go | 5 +++-- net/ghttp/ghttp_response.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/net/ghttp/ghttp.go b/net/ghttp/ghttp.go index 0dd27cda4..c386a0b7b 100644 --- a/net/ghttp/ghttp.go +++ b/net/ghttp/ghttp.go @@ -12,12 +12,13 @@ import ( "reflect" "time" + "github.com/gorilla/websocket" + "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gtype" "github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/os/gsession" "github.com/gogf/gf/v2/protocol/goai" - "github.com/gorilla/websocket" ) type ( @@ -132,7 +133,7 @@ const ( contentTypeHtml = "text/html" contentTypeJson = "application/json" swaggerUIPackedPath = "/goframe/swaggerui" - responseTraceIdHeader = "Trace-Id" + responseTraceIDHeader = "TraceID" ) var ( diff --git a/net/ghttp/ghttp_response.go b/net/ghttp/ghttp_response.go index d1f0d041c..eb6f89ef1 100644 --- a/net/ghttp/ghttp_response.go +++ b/net/ghttp/ghttp_response.go @@ -143,7 +143,7 @@ func (r *Response) ClearBuffer() { // Flush outputs the buffer content to the client and clears the buffer. func (r *Response) Flush() { - r.Header().Set(responseTraceIdHeader, gtrace.GetTraceID(r.Request.Context())) + r.Header().Set(responseTraceIDHeader, gtrace.GetTraceID(r.Request.Context())) if r.Server.config.ServerAgent != "" { r.Header().Set("Server", r.Server.config.ServerAgent) } From 25bdf10cc88adb51be90275d36d631dab78a4f98 Mon Sep 17 00:00:00 2001 From: houseme Date: Sun, 19 Dec 2021 00:44:31 +0800 Subject: [PATCH 2/2] feat:improve tracing --- database/gdb/gdb_core_tracing.go | 2 +- net/ghttp/ghttp.go | 2 +- net/gtrace/gtrace.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/database/gdb/gdb_core_tracing.go b/database/gdb/gdb_core_tracing.go index d92124e25..c94c0b0a3 100644 --- a/database/gdb/gdb_core_tracing.go +++ b/database/gdb/gdb_core_tracing.go @@ -55,7 +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), + semconv.DBStatementKey.String(sql.Format), ) if c.db.GetConfig().Host != "" { labels = append(labels, attribute.String(tracingAttrDbHost, c.db.GetConfig().Host)) diff --git a/net/ghttp/ghttp.go b/net/ghttp/ghttp.go index c386a0b7b..474463137 100644 --- a/net/ghttp/ghttp.go +++ b/net/ghttp/ghttp.go @@ -133,7 +133,7 @@ const ( contentTypeHtml = "text/html" contentTypeJson = "application/json" swaggerUIPackedPath = "/goframe/swaggerui" - responseTraceIDHeader = "TraceID" + responseTraceIDHeader = "Trace-ID" ) var ( diff --git a/net/gtrace/gtrace.go b/net/gtrace/gtrace.go index e5b55c819..5c005b8b0 100644 --- a/net/gtrace/gtrace.go +++ b/net/gtrace/gtrace.go @@ -12,7 +12,6 @@ import ( "os" "strings" - "github.com/gogf/gf/v2/net/gtrace/internal/provider" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/propagation" @@ -23,6 +22,7 @@ import ( "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/net/gtrace/internal/provider" "github.com/gogf/gf/v2/util/gconv" )