Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Allow configuring ochttp.Handler for public servers #563

Conversation

semistrict
Copy link
Contributor

@semistrict semistrict commented Mar 12, 2018

No description provided.

@semistrict semistrict requested a review from rakyll March 12, 2018 21:00
@rakyll
Copy link
Contributor

rakyll commented Mar 12, 2018

I think we should similarly give user a way to label a public server instead of dropping default propagation support. By default, we don't want to drop the traces.

@semistrict semistrict changed the title Make no propagation the default for ochttp.Handler Allow configuring ochttp.Handler for public servers Mar 13, 2018
@semistrict semistrict force-pushed the ochttp-no-default-propagate branch 4 times, most recently from 8ed1dd7 to c996638 Compare March 13, 2018 22:26
@semistrict
Copy link
Contributor Author

@rakyll updated PTAL

Added a flag on ochttp.Handler that causes the incoming SpanContext
to be added as a link rather than a parent. This is useful if we don't
trust the metadata.
trace.SetDefaultSampler(trace.AlwaysSample())

cases := []struct {
Name string
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to export these fields.

name string


cases := []struct {
Name string
ServerMiddleware *Handler
Copy link
Contributor

Choose a reason for hiding this comment

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

handler

cases := []struct {
Name string
ServerMiddleware *Handler
ClientMiddleware *Transport
Copy link
Contributor

Choose a reason for hiding this comment

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

transport

Name string
ServerMiddleware *Handler
ClientMiddleware *Transport
ExpectSameTraceID bool
Copy link
Contributor

Choose a reason for hiding this comment

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

wantSameTraceID

ServerMiddleware *Handler
ClientMiddleware *Transport
ExpectSameTraceID bool
ExpectLinks bool // expect a link between client and server span
Copy link
Contributor

Choose a reason for hiding this comment

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

wantLinks

}

serverReturn <- time.Now().Add(time.Millisecond)
for _, c := range cases {
Copy link
Contributor

Choose a reason for hiding this comment

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

In Go, it is canonical to name cases tc, and specific case tt.

It improves readability to use tt because everyone knows it represents the current test case without having to jump to the declaration.

req = req.WithContext(ctx)
resp, err := c.ClientMiddleware.RoundTrip(req)
if err != nil {
t.Fatalf("unexpected error %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just t.Fatal(err)

t.Fatalf("unexpected error %s", err)
}
if resp.StatusCode != http.StatusOK {
t.Fatalf("unexpected stats: %d", resp.StatusCode)
Copy link
Contributor

Choose a reason for hiding this comment

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

t.Fatalf("resp.StatusCode = %v, ...)

The unexpected terminology doesn't exist in Go.

if err != nil {
t.Fatalf("unexpected read error: %#v", err)
}
if string(respBody) != "expected-response" {
Copy link
Contributor

Choose a reason for hiding this comment

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

if got, want := string(respBody), "expected"; got != want {
t.Fatalf("Response body = %q; want %q", got, want)
}

ctx := r.Context()
var span *trace.Span
if sc, ok := p.SpanContextFromRequest(r); ok {
sc, haveSC := h.extractSpanContext(r)
Copy link
Contributor

Choose a reason for hiding this comment

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

sc, ok := h..extractSpanContext(r)

@semistrict semistrict merged commit 0cb1ab3 into census-instrumentation:master Mar 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants