upgrade otel to v1.0.0 for compatibility

This commit is contained in:
John Guo
2022-03-25 11:06:23 +08:00
parent cc60bc9dab
commit a2823a501e
13 changed files with 143 additions and 137 deletions

View File

@ -11,11 +11,13 @@ import (
"bytes"
"context"
"fmt"
"github.com/gogf/gf/debug/gdebug"
"github.com/gogf/gf/internal/utils"
"go.opentelemetry.io/otel/trace"
"path/filepath"
"time"
"go.opentelemetry.io/otel/trace"
"github.com/gogf/gf/debug/gdebug"
"github.com/gogf/gf/internal/utils"
)
const (
@ -43,23 +45,35 @@ func SetEnabled(enabled bool) {
// Print prints `v` with newline using fmt.Println.
// The parameter `v` can be multiple variables.
func Print(ctx context.Context, v ...interface{}) {
if !isGFDebug {
return
}
doPrint(ctx, fmt.Sprint(v...), false)
}
// Printf prints `v` with format `format` using fmt.Printf.
// The parameter `v` can be multiple variables.
func Printf(ctx context.Context, format string, v ...interface{}) {
if !isGFDebug {
return
}
doPrint(ctx, fmt.Sprintf(format, v...), false)
}
// Error prints `v` with newline using fmt.Println.
// The parameter `v` can be multiple variables.
func Error(ctx context.Context, v ...interface{}) {
if !isGFDebug {
return
}
doPrint(ctx, fmt.Sprint(v...), true)
}
// Errorf prints `v` with format `format` using fmt.Printf.
func Errorf(ctx context.Context, format string, v ...interface{}) {
if !isGFDebug {
return
}
doPrint(ctx, fmt.Sprintf(format, v...), true)
}
@ -94,7 +108,7 @@ func doPrint(ctx context.Context, content string, stack bool) {
return
}
buffer := bytes.NewBuffer(nil)
buffer.WriteString(now())
buffer.WriteString(time.Now().Format("2006-01-02 15:04:05.000"))
buffer.WriteString(" [INTE] ")
buffer.WriteString(file())
buffer.WriteString(" ")
@ -104,7 +118,7 @@ func doPrint(ctx context.Context, content string, stack bool) {
buffer.WriteString(content)
buffer.WriteString("\n")
if stack {
buffer.WriteString(gdebug.StackWithFilter(stackFilterKey))
buffer.WriteString(gdebug.StackWithFilter([]string{stackFilterKey}))
}
fmt.Print(buffer.String())
}
@ -121,13 +135,8 @@ func traceIdStr(ctx context.Context) string {
return ""
}
// now returns current time string.
func now() string {
return time.Now().Format("2006-01-02 15:04:05.000")
}
// file returns caller file name along with its line number.
func file() string {
_, p, l := gdebug.CallerWithFilter(stackFilterKey)
_, p, l := gdebug.CallerWithFilter([]string{stackFilterKey})
return fmt.Sprintf(`%s:%d`, filepath.Base(p), l)
}