Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/gin-gonic/gin: Extract parent span info from HTTP Headers #279

Merged
merged 1 commit into from
Jul 25, 2018

Conversation

samsaggace
Copy link
Contributor

Use propagation features to try to get some span context in the incoming
request headers.

If the headers are not set, the comportment is the same as before

If a span is already present in the request's context, it will be
used primarily as the parent span.

Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you read our contributing guidelines? Generally you should open an issue before committing to any work.

@@ -16,7 +16,12 @@ import (
func Middleware(service string) gin.HandlerFunc {
return func(c *gin.Context) {
resource := c.HandlerName()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this empty line please.

@@ -16,7 +16,12 @@ import (
func Middleware(service string) gin.HandlerFunc {
return func(c *gin.Context) {
resource := c.HandlerName()

// try to get a span context from request headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment, it doesn't add anything.

@@ -16,7 +16,12 @@ import (
func Middleware(service string) gin.HandlerFunc {
return func(c *gin.Context) {
resource := c.HandlerName()

// try to get a span context from request headers
sctx, _ := tracer.Extract(tracer.HTTPHeadersCarrier(c.Request.Header))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't ignore the error, it is there for a reason. You can get inspired from here on how to accomplish this: https://github.com/DataDog/dd-trace-go/blob/v1/contrib/internal/httputil/trace.go#L25-L27


// try to get a span context from request headers
sctx, _ := tracer.Extract(tracer.HTTPHeadersCarrier(c.Request.Header))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this empty line too please.

@samsaggace
Copy link
Contributor Author

Thanks @gbbr for the review.
I'll apply your comments.

Sorry for not respecting the guidelines, I read them too quickly...
Do you want me to open an issue now ?

Thanks

@gbbr
Copy link
Contributor

gbbr commented Jul 25, 2018

Yes, please always open an issue and link to it from the PR. It helps us keep track of change logs and manage things better. Many thanks!

@samsaggace
Copy link
Contributor Author

FIxes #280

@gbbr
Copy link
Contributor

gbbr commented Jul 25, 2018

Thanks. It's looking good. Will do another review soon.

Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience. This is looking good. Just a last round of comments.

@@ -167,3 +167,27 @@ func TestGetSpanNotInstrumented(t *testing.T) {
response := w.Result()
assert.Equal(response.StatusCode, 200)
}

func TestExtractSpan(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please call this TestPropagation? "Propagation" is the terminology we use throughout and will make it more obvious.

span, ok := tracer.SpanFromContext(c.Request.Context())
assert.True(ok)

//Ensure current span if a child of the span injected in the HTTP request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment and the empty line above it.

})

router.ServeHTTP(w, r)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a problem here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a newline, should be fixed now

Use propagation features to try to get some span context in the incoming
request headers.

If the headers are not set, the comportment is the same as before

If a span is already present in the request's context, it will be
used primarily as the parent span.

Fixes DataDog#280
Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Thanks!

@gbbr gbbr merged commit 36658f2 into DataDog:v1 Jul 25, 2018
@samsaggace samsaggace deleted the gin-extract branch July 25, 2018 14:23
@samsaggace
Copy link
Contributor Author

Thank you

mingrammer pushed a commit to mingrammer/dd-trace-go that referenced this pull request Dec 22, 2020
…taDog#279)

Use propagation features to try to get some span context in the incoming
request headers.

If the headers are not set, the comportment is the same as before

If a span is already present in the request's context, it will be
used primarily as the parent span.

Fixes DataDog#280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants