File tree Expand file tree Collapse file tree 4 files changed +16
-1
lines changed
opentelemetry-api/src/opentelemetry/trace
src/opentelemetry/sdk/trace Expand file tree Collapse file tree 4 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
7
7
## [ Unreleased] ( https://github.com/open-telemetry/opentelemetry-python/compare/v0.17b0...HEAD )
8
8
9
+ ### Added
10
+ - Added ` end_on_exit ` argument to ` start_as_current_span `
11
+ ([ #1519 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/1519 )] )
12
+
9
13
## [ 0.17b0] ( https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.17b0 ) - 2021-01-20
10
14
11
15
### Added
Original file line number Diff line number Diff line change @@ -290,6 +290,7 @@ def start_as_current_span(
290
290
start_time : typing .Optional [int ] = None ,
291
291
record_exception : bool = True ,
292
292
set_status_on_exception : bool = True ,
293
+ end_on_exit : bool = True ,
293
294
) -> typing .Iterator ["Span" ]:
294
295
"""Context manager for creating a new span and set it
295
296
as the current span in this tracer's context.
@@ -396,6 +397,7 @@ def start_as_current_span(
396
397
start_time : typing .Optional [int ] = None ,
397
398
record_exception : bool = True ,
398
399
set_status_on_exception : bool = True ,
400
+ end_on_exit : bool = True ,
399
401
) -> typing .Iterator ["Span" ]:
400
402
# pylint: disable=unused-argument,no-self-use
401
403
yield INVALID_SPAN
Original file line number Diff line number Diff line change @@ -759,6 +759,7 @@ def start_as_current_span(
759
759
start_time : Optional [int ] = None ,
760
760
record_exception : bool = True ,
761
761
set_status_on_exception : bool = True ,
762
+ end_on_exit : bool = True ,
762
763
) -> Iterator [trace_api .Span ]:
763
764
span = self .start_span (
764
765
name = name ,
@@ -770,7 +771,7 @@ def start_as_current_span(
770
771
record_exception = record_exception ,
771
772
set_status_on_exception = set_status_on_exception ,
772
773
)
773
- with self .use_span (span , end_on_exit = True ) as span_context :
774
+ with self .use_span (span , end_on_exit = end_on_exit ) as span_context :
774
775
yield span_context
775
776
776
777
def start_span ( # pylint: disable=too-many-locals
Original file line number Diff line number Diff line change @@ -485,6 +485,14 @@ def func():
485
485
self .assertIsNotNone (root2 .end_time )
486
486
self .assertIsNot (root1 , root2 )
487
487
488
+ def test_start_as_current_span_no_end_on_exit (self ):
489
+ tracer = new_tracer ()
490
+
491
+ with tracer .start_as_current_span ("root" , end_on_exit = False ) as root :
492
+ self .assertIsNone (root .end_time )
493
+
494
+ self .assertIsNone (root .end_time )
495
+
488
496
def test_explicit_span_resource (self ):
489
497
resource = resources .Resource .create ({})
490
498
tracer_provider = trace .TracerProvider (resource = resource )
You can’t perform that action at this time.
0 commit comments