Skip to content

Commit 8c94a5a

Browse files
Merge pull request #387 from pace/sentry-debug
tracing: Fix bugs and clean up code
2 parents 4597413 + 6775de6 commit 8c94a5a

File tree

13 files changed

+131
-165
lines changed

13 files changed

+131
-165
lines changed

http/jsonapi/generator/generate_handler.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,16 @@ func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern
597597

598598
g.Add(auth)
599599
// set tracing context
600+
601+
ctxStmt := jen.Id("r").Dot("Context").Call()
602+
603+
if auth != nil {
604+
ctxStmt = jen.Id("ctx")
605+
}
606+
600607
g.Line().Comment("Trace the service function handler execution")
601608
g.Id("span").Op(":=").Qual(pkgSentry, "StartSpan").Call(
602-
jen.Id("r").Dot("Context").Call(), jen.Lit("http.server"), jen.Qual(pkgSentry, "WithDescription").Call(jen.Lit(handler)))
609+
ctxStmt, jen.Lit("http.server"), jen.Qual(pkgSentry, "WithDescription").Call(jen.Lit(handler)))
603610
g.Defer().Id("span").Dot("Finish").Call()
604611
g.Line().Empty()
605612

@@ -626,7 +633,7 @@ func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern
626633

627634
// request
628635
g.Id("request").Op(":=").Id(route.requestType).
629-
Block(jen.Id("Request").Op(":").Id("r").Dot("WithContext").Call(jen.Id("ctx")).Op(","))
636+
Block(jen.Id("Request").Op(":").Id("r").Op(","))
630637

631638
// vars in case parameters are given
632639
g.Line().Comment("Scan and validate incoming request parameters")
@@ -773,7 +780,6 @@ func generateAuthorization(op *openapi3.Operation, secSchemes map[string]*openap
773780
return nil, err
774781
}
775782

776-
r.Line().Id("r").Op("=").Id("r.WithContext").Call(jen.Id("ctx"))
777783
return r, nil
778784
}
779785

http/jsonapi/generator/internal/articles/open-api_test.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

http/jsonapi/generator/internal/fueling/open-api_test.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

http/jsonapi/generator/internal/pay/open-api_test.go

+10-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)