66import re
77
88from ....log import logger
9- from ....singletons import tracer
109from .collectors import _storage_api
10+ from ....util .traceutils import get_tracer_tuple , tracing_is_off
1111
1212try :
1313 from google .cloud import storage
@@ -50,15 +50,11 @@ def _collect_tags(api_request):
5050
5151 def execute_with_instana (wrapped , instance , args , kwargs ):
5252 # batch requests are traced with finish_batch_with_instana()
53- if isinstance (instance , storage .Batch ):
54- return wrapped (* args , ** kwargs )
55-
56- parent_span = tracer .active_span
57-
58- # return early if we're not tracing
59- if parent_span is None :
53+ # also return early if we're not tracing
54+ if isinstance (instance , storage .Batch ) or tracing_is_off ():
6055 return wrapped (* args , ** kwargs )
6156
57+ tracer , parent_span , _ = get_tracer_tuple ()
6258 tags = _collect_tags (kwargs )
6359
6460 # don't trace if the call is not instrumented
@@ -79,12 +75,12 @@ def execute_with_instana(wrapped, instance, args, kwargs):
7975 return kv
8076
8177 def download_with_instana (wrapped , instance , args , kwargs ):
82- parent_span = tracer .active_span
83-
8478 # return early if we're not tracing
85- if parent_span is None :
79+ if tracing_is_off () :
8680 return wrapped (* args , ** kwargs )
8781
82+ tracer , parent_span , _ = get_tracer_tuple ()
83+
8884 with tracer .start_active_span ('gcs' , child_of = parent_span ) as scope :
8985 scope .span .set_tag ('gcs.op' , 'objects.get' )
9086 scope .span .set_tag ('gcs.bucket' , instance .bucket .name )
@@ -110,12 +106,12 @@ def download_with_instana(wrapped, instance, args, kwargs):
110106 return kv
111107
112108 def upload_with_instana (wrapped , instance , args , kwargs ):
113- parent_span = tracer .active_span
114-
115109 # return early if we're not tracing
116- if parent_span is None :
110+ if tracing_is_off () :
117111 return wrapped (* args , ** kwargs )
118112
113+ tracer , parent_span , _ = get_tracer_tuple ()
114+
119115 with tracer .start_active_span ('gcs' , child_of = parent_span ) as scope :
120116 scope .span .set_tag ('gcs.op' , 'objects.insert' )
121117 scope .span .set_tag ('gcs.bucket' , instance .bucket .name )
@@ -130,12 +126,12 @@ def upload_with_instana(wrapped, instance, args, kwargs):
130126 return kv
131127
132128 def finish_batch_with_instana (wrapped , instance , args , kwargs ):
133- parent_span = tracer .active_span
134-
135129 # return early if we're not tracing
136- if parent_span is None :
130+ if tracing_is_off () :
137131 return wrapped (* args , ** kwargs )
138132
133+ tracer , parent_span , _ = get_tracer_tuple ()
134+
139135 with tracer .start_active_span ('gcs' , child_of = parent_span ) as scope :
140136 scope .span .set_tag ('gcs.op' , 'batch' )
141137 scope .span .set_tag ('gcs.projectId' , instance ._client .project )
0 commit comments