Skip to content

Commit

Permalink
Merge pull request #387 from pace/sentry-debug
Browse files Browse the repository at this point in the history
tracing: Fix bugs and clean up code
  • Loading branch information
monstermunchkin authored Nov 28, 2024
2 parents 4597413 + 6775de6 commit 8c94a5a
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 165 deletions.
12 changes: 9 additions & 3 deletions http/jsonapi/generator/generate_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,16 @@ func (g *Generator) buildHandler(method string, op *openapi3.Operation, pattern

g.Add(auth)
// set tracing context

ctxStmt := jen.Id("r").Dot("Context").Call()

if auth != nil {
ctxStmt = jen.Id("ctx")
}

g.Line().Comment("Trace the service function handler execution")
g.Id("span").Op(":=").Qual(pkgSentry, "StartSpan").Call(
jen.Id("r").Dot("Context").Call(), jen.Lit("http.server"), jen.Qual(pkgSentry, "WithDescription").Call(jen.Lit(handler)))
ctxStmt, jen.Lit("http.server"), jen.Qual(pkgSentry, "WithDescription").Call(jen.Lit(handler)))
g.Defer().Id("span").Dot("Finish").Call()
g.Line().Empty()

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

// request
g.Id("request").Op(":=").Id(route.requestType).
Block(jen.Id("Request").Op(":").Id("r").Dot("WithContext").Call(jen.Id("ctx")).Op(","))
Block(jen.Id("Request").Op(":").Id("r").Op(","))

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

r.Line().Id("r").Op("=").Id("r.WithContext").Call(jen.Id("ctx"))
return r, nil
}

Expand Down
8 changes: 4 additions & 4 deletions http/jsonapi/generator/internal/articles/open-api_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions http/jsonapi/generator/internal/fueling/open-api_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions http/jsonapi/generator/internal/pay/open-api_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8c94a5a

Please sign in to comment.