census-instrumentation / opencensus-specs

Apache License 2.0
188 stars 50 forks source link

Tracing: Permit span start and end times to be supplied #273

Open somersf opened 3 years ago

somersf commented 3 years ago

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:

and similarly for the C++ bindings:

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):

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.