fix: inject propagator header

feat: set error tag as true
fix: unit test issue
fix: deep source check error
This commit is contained in:
hezhaoyang 2022-04-18 20:55:55 +08:00
parent 684d4e030b
commit d98ab11096
3 changed files with 10 additions and 6 deletions

View File

@ -3,7 +3,7 @@
- [fix prometheus CVE-2022-21698](https://github.com/beego/beego/pull/4878)
- [upgrade to Go 1.18](https://github.com/beego/beego/pull/4896)
- [make `PatternLogFormatter` handling the arguments](https://github.com/beego/beego/pull/4914/files)
- [Add httplib OpenTelemetry Filter](https://github.com/beego/beego/pull/4888)
- [Add httplib OpenTelemetry Filter](https://github.com/beego/beego/pull/4888, https://github.com/beego/beego/pull/4915)
- [Support NewBeegoRequestWithCtx in httplib](https://github.com/beego/beego/pull/4895)
# v2.0.2

View File

@ -20,6 +20,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
"github.com/beego/beego/v2/client/httplib"
@ -49,6 +50,8 @@ func (builder *OtelFilterChainBuilder) FilterChain(next httplib.Filter) httplib.
spanCtx, span := otel.Tracer("beego").Start(ctx, operationName)
defer span.End()
otel.GetTextMapPropagator().Inject(spanCtx, propagation.HeaderCarrier(req.GetRequest().Header))
resp, err := next(spanCtx, req)
if resp != nil {
@ -66,6 +69,7 @@ func (builder *OtelFilterChainBuilder) FilterChain(next httplib.Filter) httplib.
}
if err != nil {
span.SetAttributes(attribute.Bool("error", true))
span.RecordError(err)
} else if resp != nil && !(resp.StatusCode < 300 && resp.StatusCode >= 200) {
span.SetAttributes(attribute.Bool("error", true))

View File

@ -25,7 +25,7 @@ import (
type CustomFormatter struct{}
func (c *CustomFormatter) Format(lm *LogMsg) string {
func (*CustomFormatter) Format(lm *LogMsg) string {
return "hello, msg: " + lm.Msg
}
@ -49,15 +49,15 @@ func (t *TestLogger) WriteMsg(lm *LogMsg) error {
return nil
}
func (t *TestLogger) Destroy() {
func (*TestLogger) Destroy() {
panic("implement me")
}
func (t *TestLogger) Flush() {
func (*TestLogger) Flush() {
panic("implement me")
}
func (t *TestLogger) SetFormatter(f LogFormatter) {
func (*TestLogger) SetFormatter(_ LogFormatter) {
panic("implement me")
}
@ -77,7 +77,7 @@ func TestPatternLogFormatter(t *testing.T) {
Pattern: "%F:%n|%w%t>> %m",
WhenFormat: "2006-01-02",
}
when := time.Now()
when, _ := time.Parse(tes.WhenFormat, "2022-04-17")
testCases := []struct {
msg *LogMsg
want string