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

Clean up ocgrpc: remove NewXXXStatsHandler methods #539

Merged

Conversation

semistrict
Copy link
Contributor

Since we provide options on the ClientHandler and ServerHandler structs
and the NewXXX methods were trivial, it is better to have users use a
struct literal.

@semistrict semistrict changed the title Clean up ocgrpc: remote NewXXXStatsHandler methods. Clean up ocgrpc: remove NewXXXStatsHandler methods. Mar 8, 2018
@semistrict semistrict changed the title Clean up ocgrpc: remove NewXXXStatsHandler methods. Clean up ocgrpc: remove NewXXXStatsHandler methods Mar 8, 2018
@semistrict semistrict requested a review from odeke-em March 9, 2018 01:27
@@ -44,7 +44,7 @@ func main() {

// Set up a connection to the server with the OpenCensus
// stats handler to enable stats and tracing.
conn, err := grpc.Dial(address, grpc.WithStatsHandler(ocgrpc.NewClientStatsHandler()), grpc.WithInsecure())
conn, err := grpc.Dial(address, grpc.WithStatsHandler(new(ocgrpc.ClientHandler)), grpc.WithInsecure())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a common style in Go for inline code.

It is somewhat encouraged with var for zero values:

var hander = new(ocgrpc.ClientHandler)

Use &ocgrpc.ClientHandler{} instead.

@@ -59,7 +59,7 @@ func main() {

// Set up a new server with the OpenCensus
// stats handler to enable stats and tracing.
s := grpc.NewServer(grpc.StatsHandler(ocgrpc.NewServerStatsHandler()))
s := grpc.NewServer(grpc.StatsHandler(new(ocgrpc.ServerHandler)))
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

te := &traceExporter{}
trace.RegisterExporter(te)
func TestClientHandler(t *testing.T) {
var (
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the var grouping here.

te := &traceExporter{}
trace.RegisterExporter(te)
func TestServerHandler(t *testing.T) {
var (
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@semistrict
Copy link
Contributor Author

@rakyll PTAL

span := trace.NewSpan("/foo", nil, trace.StartOptions{
Sampler: trace.AlwaysSample(),
})
ctx = trace.WithSpan(ctx, span)

var handler ServerHandler
Copy link
Contributor

Choose a reason for hiding this comment

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

handler := &ServerHandler{}

te := &traceExporter{}
trace.RegisterExporter(te)
if err := ServerRequestCountView.Subscribe(); err != nil {
t.Fatal(err)
}

// Ensure we start tracing
Copy link
Contributor

Choose a reason for hiding this comment

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

// Ensure we start tracing.

End with full stop. In Go, block comments are proper English sentences, side comments can be non-proper sentences. For example:

ctx = trace.WithSpan(ctx, span) // span in the context

Since we provide options on the ClientHandler and ServerHandler structs
and the NewXXX methods were trivial, it is better to have users use a
struct literal.
@semistrict semistrict merged commit ac82455 into census-instrumentation:master Mar 12, 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