* Add ForceFlush method to TracerProvider
The specification requires that a TracerProvider have a ForceFlush
method that can be set with a timeout, return any error to the caller,
and have all the registered span processors export their spans. This
updates the SpanProcessor.ForceFlush method to accept a context and
return an error and plumbs this method into a new ForceFlush method of
the SDK TracerProvider.
Additionally, this corrects the TracerProvider Shutdown method. This
method as well needs to return to the caller any failure it encounters
according to the specification. This returns an error if it cannot type
assert the spanProcessorStates or if shutting down a span processor
results in an error.
Resolves#1606
* Add changes to changelog
* Apply suggestions from code review
Co-authored-by: Steven E. Harris <seh@panix.com>
* Cancel export context when BSP stops
* Defer cancel call in BSP span processor funcs
Co-authored-by: Steven E. Harris <seh@panix.com>
* Store span data directly in the span
- Nesting only some of a span's data in a `data` field (with the rest
of the data living direclty in the `span` struct) is confusing.
- export.SpanData is meant to be an immutable *snapshot* of a span,
not the "authoritative" state of the span.
- Refactor attributesMap.toSpanData into toKeyValue and make it
return a []label.KeyValue which is clearer than modifying a struct
passed to the function.
- Read droppedCount from the attributesMap as a separate operation
instead of setting it from within attributesMap.toSpanData.
- Set a span's end time in the span itself rather than in the
SpanData to allow reading the span's end time after a span has
ended.
- Set a span's end time as soon as possible within span.End so that
we don't influence the span's end time with operations such as
fetching span processors and generating span data.
- Remove error handling for uninitialized spans. This check seems to
be necessary only because we used to have an *export.SpanData field
which could be nil. Now that we no longer have this field I think we
can safely remove the check. The error isn't used anywhere else so
remove it, too.
* Store parent as trace.SpanContext
The spec requires that the parent field of a Span be a Span, a
SpanContext or null.
Rather than extracting the parent's span ID from the trace.SpanContext
which we get from the tracer, store the trace.SpanContext as is and
explicitly extract the parent's span ID where necessary.
* Add ReadOnlySpan interface
Use this interface instead of export.SpanData in places where reading
information from a span is necessary. Use export.SpanData only when
exporting spans.
* Add ReadWriteSpan interface
Use this interface instead of export.SpanData in places where it is
necessary to read information from a span and write to it at the same
time.
* Rename export.SpanData to SpanSnapshot
SpanSnapshot represents the nature of this type as well as its
intended use more accurately.
Clarify the purpose of SpanSnapshot in the docs and emphasize what
should and should not be done with it.
* Rephrase attributesMap doc comment
"refreshes" is wrong for plural ("updates").
* Refactor span.End()
- Improve accuracy of span duration. Record span end time ASAP. We
want to measure a user operation as accurately as possible, which
means we want to mark the end time of a span as soon as possible
after span.End() is called. Any operations we do inside span.End()
before storing the end time affect the total duration of the span,
and although these operations are rather fast at the moment they
still seem to affect the duration of the span by "artificially"
adding time between the start and end timestamps. This is relevant
only in cases where the end time isn't explicitly specified.
- Remove redundant idempotence check. Now that IsRecording() is based
on the value of span.endTime, IsRecording() will always return
false after span.End() had been called because span.endTime won't
be zero. This means we no longer need span.endOnce.
- Improve TestEndSpanTwice so that it also ensures subsequent calls
to span.End() don't modify the span's end time.
* Update changelog
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Add parent context to SpanProcessor.OnStart
The spec requires doing so. Right now SpanProcessor implementations
aren't doing anything with this argument.
* Update changelog
* Fix typo in test name
* Add ForceFlush() method to SpanProcessor interface
* Add a stub implementation to SimpleSpanProcessor
* Add a working implementation to BatchSpanProcessor
* add CHANGELOG.md entry
* Eliminate sleep from BatchSpanProcessor.ForceFlush() test
* Generating test spans serially should reduce test flakiness
* Update License header for all source files
- Add Apache 2.0 header to source files that did not have one.
- Update all existing headers dated to 2019 to be 2020
- Remove comma from License header to comply with the Apache 2.0
guidelines.
* Update Copyright notice
Use the standard Copyright notices outlined by the
[CNCF](https://github.com/cncf/foundation/blob/master/copyright-notices.md#copyright-notices)
* setup sdk exporter package
* use sdk exporter package in sdk trace
* use sdk exporter package in all exporters
* empty the exporters list before testing Load
* move SpanData to the exporter package
* use the SpanProcessor registration, don't register exporters
* rename exporter structs to avoid stutter
* rename Syncer and Batcher to SpanSyncer and SpanBatcher
So it's explicit they are for spans, and we reduce the risk of name
conflict
* remove not moot todo
* rename sdk exporter to export
* only execute the SpanData if it is sampled
* add batch span processor.
* add blocking support.
* use With* function for options.
- also changed how Shutdown is handled.
* block Shutdown until queue is flushed.
* fix comment.