-
Notifications
You must be signed in to change notification settings - Fork 50
Tracing: Permit span start and end times to be supplied #273
Description
Please enable devs using opencensus tracing to supply the start and end times for spans themselves to override the (current default) of capturing the system time when the span is created/ended.
From the spec:
What is Span lifetime?
Span lifetime represents the process of recording the start and the end timestamps to the Span object:
The start time is recorded when the Span is created.
The end time needs to be recorded when the operation is ended.
The wording seems to prescribe that the timestamps are captured/applied (eg from system time) by the language bindings at the point in time when spans are created/ended.
That does seem to be the case for the go bindings:
- https://github.com/census-instrumentation/opencensus-go/blob/3fb168f674736c026e623310bfccb0691e6dec8a/trace/trace.go#L243
- https://github.com/census-instrumentation/opencensus-go/blob/3fb168f674736c026e623310bfccb0691e6dec8a/trace/trace.go#L284).
and similarly for the C++ bindings:
- https://github.com/census-instrumentation/opencensus-cpp/blob/ba631066779a534267fdb1321b19850eb2b0c000/opencensus/trace/internal/span_impl.cc#L81
- https://github.com/census-instrumentation/opencensus-cpp/blob/ba631066779a534267fdb1321b19850eb2b0c000/opencensus/trace/internal/span_impl.cc#L155
My use-case is that I have existing data from a system which already has start/end times. I want to convert this into spans for publication/analysis in opencensus-supported tracing systems by making opencensus spans corresponding to the data.
This is straightforward to do with opentracing APIs - for example, the opentracing Go bindings permit the start and end times to be supplied (using the go-idiomatic "options" patterns):
- https://github.com/opentracing/opentracing-go/blob/d34af3eaa63c4d08ab54863a4bdd0daa45212e12/tracer.go#L139
- https://github.com/opentracing/opentracing-go/blob/d34af3eaa63c4d08ab54863a4bdd0daa45212e12/span.go#L140
eg:
func callSstart(t opentracing.Tracer, parent opentracing.Span, name string, start time.Time) opentracing.Span {
return t.StartSpan(name, opentracing.ChildOf(parent.Context()), opentracing.StartTime(start))
}
func callFinish(s opentracing.Span, end time.Time) {
s.FinishWithOptions(opentracing.FinishOptions{
FinishTime: end,
})
}
Since this issue seems to be present in opencensus Go and C++ bindings (I haven't checked others), I have opened it against the spec instead of the specific opencensus language bindings as was suggested by the "new issue" template at https://github.com/census-instrumentation/opencensus-go/issues/new
Thanks.