[feature] upgrade opentelemetry version v1.0.0 map to string

This commit is contained in:
houseme
2021-09-22 14:54:42 +08:00
parent 45b45517c8
commit cbe704333a
3 changed files with 7 additions and 4 deletions

View File

@ -12,7 +12,6 @@ import (
"net/http"
"github.com/gogf/gf"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/internal/utils"
"github.com/gogf/gf/net/ghttp/internal/client"
"github.com/gogf/gf/net/ghttp/internal/httputil"
@ -85,7 +84,7 @@ func MiddlewareServerTracing(r *Request) {
)
span.AddEvent(tracingEventHttpResponse, trace.WithAttributes(
attribute.String(tracingEventHttpResponseHeaders, gjson.New(httputil.HeaderToMap(r.Response.Header())).MustToJsonString()),
attribute.String(tracingEventHttpResponseHeaders, gconv.String(httputil.HeaderToMap(r.Response.Header()))),
attribute.String(tracingEventHttpResponseBody, resBodyContent),
))
return

View File

@ -14,12 +14,12 @@ import (
// Carrier is the storage medium used by a TextMapPropagator.
type Carrier map[string]interface{}
// NewCarrier .
func NewCarrier(data ...map[string]interface{}) Carrier {
if len(data) > 0 && data[0] != nil {
return data[0]
} else {
return make(map[string]interface{})
}
return make(map[string]interface{})
}
// Get returns the value associated with the passed key.
@ -41,6 +41,7 @@ func (c Carrier) Keys() []string {
return keys
}
// MustMarshal .returns the JSON encoding of c
func (c Carrier) MustMarshal() []byte {
b, err := json.Marshal(c)
if err != nil {
@ -49,10 +50,12 @@ func (c Carrier) MustMarshal() []byte {
return b
}
// String .
func (c Carrier) String() string {
return string(c.MustMarshal())
}
// UnmarshalJSON .
func (c Carrier) UnmarshalJSON(b []byte) error {
carrier := NewCarrier(nil)
return json.UnmarshalUseNumber(b, carrier)

View File

@ -11,6 +11,7 @@ import (
"go.opentelemetry.io/otel/trace"
)
// Tracer .
type Tracer struct {
trace.Tracer
}