-
Notifications
You must be signed in to change notification settings - Fork 316
RFC: far fewer types (but comparable portability) #40
Changes from all commits
7ba7985
41f5970
1c71173
347c361
56cca52
cc02d3f
eb53dfe
27effd4
048371a
b8b5353
ca5c92c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ demonstrating some important use cases. | |
|
||
The simplest starting point is `./default_tracer.go`. As early as possible, call | ||
|
||
``` | ||
```go | ||
import ".../opentracing-go" | ||
import ".../some_tracing_impl" | ||
|
||
|
@@ -37,7 +37,7 @@ If you prefer direct control to singletons, manage ownership of the | |
|
||
#### Starting an empty trace by creating a "root span" | ||
|
||
``` | ||
```go | ||
func xyz() { | ||
... | ||
sp := opentracing.StartTrace("span_name") | ||
|
@@ -49,7 +49,7 @@ If you prefer direct control to singletons, manage ownership of the | |
|
||
#### Creating a Span given an existing Span | ||
|
||
``` | ||
```go | ||
func xyz(parentSpan opentracing.Span, ...) { | ||
... | ||
sp := opentracing.JoinTrace("span_name", parentSpan) | ||
|
@@ -64,10 +64,11 @@ If you prefer direct control to singletons, manage ownership of the | |
Additionally, this example demonstrates how to get a `context.Context` | ||
associated with any `opentracing.Span` instance. | ||
|
||
``` | ||
```go | ||
func xyz(goCtx context.Context, ...) { | ||
... | ||
sp, goCtx := opentracing.JoinTrace("span_name", goCtx).AddToGoContext(goCtx) | ||
goCtx, sp := opentracing.ContextWithSpan( | ||
goCtx, opentracing.JoinTrace("span_name", goCtx)) | ||
defer sp.Finish() | ||
sp.LogEvent("xyz_called") | ||
... | ||
|
@@ -76,16 +77,16 @@ associated with any `opentracing.Span` instance. | |
|
||
#### Serializing to the wire | ||
|
||
``` | ||
```go | ||
func makeSomeRequest(ctx context.Context) ... { | ||
if span := opentracing.SpanFromGoContext(ctx); span != nil { | ||
if span := opentracing.SpanFromContext(ctx); span != nil { | ||
httpClient := &http.Client{} | ||
httpReq, _ := http.NewRequest("GET", "http://myservice/", nil) | ||
|
||
// Transmit the span's TraceContext as an HTTP header on our | ||
// outbound request. | ||
opentracing.AddTraceContextToHeader( | ||
span.TraceContext(), | ||
opentracing.GlobalTracer().PropagateSpanInHeader( | ||
span, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important difference: we propagate |
||
httpReq.Header, | ||
opentracing.DefaultTracer()) | ||
|
||
|
@@ -98,23 +99,16 @@ associated with any `opentracing.Span` instance. | |
|
||
#### Deserializing from the wire | ||
|
||
``` | ||
```go | ||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { | ||
// Grab the TraceContext from the HTTP header using the | ||
// opentracing helper. | ||
reqTraceCtx, err := opentracing.TraceContextFromHeader( | ||
req.Header, opentracing.GlobalTracer()) | ||
var serverSpan opentracing.Span | ||
var goCtx context.Context = ... | ||
// Join the trace in the HTTP header using the opentracing helper. | ||
serverSpan, err := opentracing.GlobalTracer().JoinTraceFromHeader( | ||
"serverSpan", req.Header, opentracing.GlobalTracer()) | ||
if err != nil { | ||
// Just make a root span. | ||
serverSpan, goCtx = opentracing.StartTrace("serverSpan").AddToGoContext(goCtx) | ||
} else { | ||
// Make a new server-side span that's a child of the span/context sent | ||
// over the wire. | ||
serverSpan, goCtx = opentracing.JoinTrace( | ||
"serverSpan", reqTraceCtx).AddToGoContext(goCtx) | ||
serverSpan = opentracing.StartTrace("serverSpan") | ||
} | ||
var goCtx context.Context = ... | ||
goCtx, _ = opentracing.ContextWithSpan(goCtx, serverSpan) | ||
defer serverSpan.Finish() | ||
... | ||
} | ||
|
@@ -127,14 +121,4 @@ synchronization. | |
|
||
## API pointers for those implementing a tracing system | ||
|
||
There should be no need for most tracing system implementors to worry about the | ||
`opentracing.Span` or `opentracing.Tracer` interfaces directly: | ||
`standardtracer.New(...)` should work well enough in most circumstances. | ||
|
||
In order to integrate with `standardtracer`, tracing system authors are | ||
expected to provide implementations of: | ||
- `opentracing.TraceContext` | ||
- `opentracing.TraceContextSource` | ||
- `standardtracer.Recorder` | ||
|
||
For a small working example, see `../examples/dapperish/*.go`. | ||
Tracing system implementors may be able to reuse or copy-paste-modify the `./standardtracer` package. In particular, see `standardtracer.New(...)`. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import ( | |
"bufio" | ||
"bytes" | ||
"fmt" | ||
"html" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
@@ -19,10 +18,10 @@ import ( | |
func client() { | ||
reader := bufio.NewReader(os.Stdin) | ||
for { | ||
span := opentracing.StartTrace("getInput") | ||
ctx := opentracing.BackgroundGoContextWithSpan(span) | ||
ctx, span := opentracing.BackgroundContextWithSpan( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this file gives a sense of how user code differs... mainly just that |
||
opentracing.StartTrace("getInput")) | ||
// Make sure that global trace tag propagation works. | ||
span.TraceContext().SetTraceAttribute("User", os.Getenv("USER")) | ||
span.SetTraceAttribute("User", os.Getenv("USER")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't mean to distract the issue, but I will 📦 I really like Tag Sets where propagation is simply a property of a tag. The "Trace" part of the name "TraceAttribute" has resulted in heaps of discussion, notably as no-one can guess by its name that it a propagation tag, but also the common "is it a part of the trace?" Ex. in zipkin trace id, id, parent id, and sampled decision are "trace attributes", ie only one field has anything to do with the trace. I really would rather we be able to deconflate this whole thing by saying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. "TraceAttribute" implies something that applies to the root, or to all parent Spans as well as child Spans. Another suggestion for naming:
It's an attribute that child tags will also inherit, regardless of network/process boundaries. I find the whole "Distributed Context Propagation" at the API level, has grown into an unneeded (psychological) schema. To the user of the API it can be simplified just as an attribute the casades, even over the network/process boundaries. ( The "Distributed Context Propagation" schema is still valuable in Specification though. ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I, too, am unnerved by the naming around "Trace Attributes"... if we pursue the basic model of this PR, something like @adriancole @michaelsembwever @yurishkuro thoughts on something like the following three methods on Span?
Some problems right off the bat:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 -- However, I'm not sure folding It makes sense to think of the relevant part of I realize this is arguably scope question currently being debated in #33 as well, but clarity is the goal of this line of discussion and I think it will be clearer if we don't conflate these two concepts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (/me files a motion to decouple this important, unfinished discussion from the current PR) |
||
span.LogEventWithPayload("ctx", ctx) | ||
fmt.Print("\n\nEnter text (empty string to exit): ") | ||
text, _ := reader.ReadString('\n') | ||
|
@@ -36,8 +35,8 @@ func client() { | |
|
||
httpClient := &http.Client{} | ||
httpReq, _ := http.NewRequest("POST", "http://localhost:8080/", bytes.NewReader([]byte(text))) | ||
opentracing.AddTraceContextToHeader( | ||
span.TraceContext(), httpReq.Header, opentracing.GlobalTracer()) | ||
opentracing.PropagateSpanInHeader( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing tracers send via multiple headers, but I guess this is named PropagateSpanInHeader vs PropagateSpanInHeaders bc in go, headers are in an object named Header? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I don't like it, but that's what the Go maintainers decided, apparently. |
||
span, httpReq.Header, opentracing.GlobalTracer()) | ||
resp, err := httpClient.Do(httpReq) | ||
if err != nil { | ||
span.LogEventWithPayload("error", err) | ||
|
@@ -51,28 +50,19 @@ func client() { | |
|
||
func server() { | ||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { | ||
reqCtx, err := opentracing.TraceContextFromHeader( | ||
req.Header, opentracing.GlobalTracer()) | ||
serverSpan, err := opentracing.JoinTraceFromHeader( | ||
"serverSpan", req.Header, opentracing.GlobalTracer()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
serverSpan := opentracing.JoinTrace( | ||
"serverSpan", reqCtx, | ||
).SetTag("component", "server") | ||
serverSpan.SetTag("component", "server") | ||
defer serverSpan.Finish() | ||
|
||
fullBody, err := ioutil.ReadAll(req.Body) | ||
if err != nil { | ||
serverSpan.LogEventWithPayload("body read error", err) | ||
} | ||
serverSpan.LogEventWithPayload("got request with body", string(fullBody)) | ||
contextIDMap, tagsMap := opentracing.TraceContextToText(reqCtx) | ||
fmt.Fprintf( | ||
w, | ||
"Hello: %v // %v // %q", | ||
contextIDMap, | ||
tagsMap, | ||
html.EscapeString(req.URL.Path)) | ||
}) | ||
|
||
log.Fatal(http.ListenAndServe(":8080", nil)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I was just tinkering with whether
Span
really needed thatAddToGoContext
helper method... the change here is not related to the main event in this PR.