lib/opencensus/trace/span_context.rb in opencensus-0.2.2 vs lib/opencensus/trace/span_context.rb in opencensus-0.3.0

- old
+ new

@@ -165,23 +165,25 @@ # be set using the SpanBuilder methods. # The span will be started automatically with the current timestamp. # However, you are responsible for finishing the span yourself. # # @param [String] name Name of the span + # @param [Symbol] kind Kind of span. Defaults to unspecified. # @param [Sampler] sampler Span-scoped sampler. If not provided, # defaults to the trace configuration's default sampler. # # @return [SpanBuilder] A SpanBuilder object that you can use to # set span attributes and create children. # - def start_span name, skip_frames: 0, sampler: nil + def start_span name, kind: nil, skip_frames: 0, sampler: nil child_context = create_child sampler ||= OpenCensus::Trace.config.default_sampler sampled = sampler.call span_context: self span = SpanBuilder.new child_context, sampled, skip_frames: skip_frames + 1 span.name = name + span.kind = kind if kind span.start! @trace_data.span_map[child_context.span_id] = span end ## @@ -192,15 +194,17 @@ # The span will be started automatically with the current timestamp. The # SpanBuilder will then be passed to the block you provide. The span will # be finished automatically at the end of the block. # # @param [String] name Name of the span + # @param [Symbol] kind Kind of span. Defaults to unspecified. # @param [Sampler] sampler Span-scoped sampler. If not provided, # defaults to the trace configuration's default sampler. # - def in_span name, skip_frames: 0, sampler: nil - span = start_span name, skip_frames: skip_frames + 1, sampler: sampler + def in_span name, kind: nil, skip_frames: 0, sampler: nil + span = start_span name, kind: kind, skip_frames: skip_frames + 1, + sampler: sampler begin yield span ensure end_span span end @@ -230,13 +234,13 @@ def this_span get_span @span_id end ## - # Builds all finished spans under this context, and returns an array of - # built `Span` objects. Ignores any unfinished spans. The order of the - # generated spans is undefined. + # Builds spans under this context, and returns an array of built `Span` + # objects. Builds only spans that are both finished and sampled, and + # ignores others. The order of the generated spans is undefined. # # Does not build any ancestor spans. If you want the entire span tree # built, call this method on the `#root` context. # # @param [Integer, nil] max_attributes The maximum number of attributes @@ -258,10 +262,13 @@ max_stack_frames: nil, max_annotations: nil, max_message_events: nil, max_links: nil, max_string_length: nil - contained_span_builders.find_all(&:finished?).map do |sb| + sampled_span_builders = contained_span_builders.find_all do |sb| + sb.finished? && sb.sampled + end + sampled_span_builders.map do |sb| sb.to_span max_attributes: max_attributes, max_stack_frames: max_stack_frames, max_annotations: max_annotations, max_message_events: max_message_events, max_links: max_links,