@@ -82,14 +82,11 @@ public Object deserializeContext(Map<String, byte[]> context) {
8282
8383 @ Override
8484 public Object getCurrentContext () {
85- log .debug ("Getting current context" );
8685 Tracer currentTracer = GlobalTracer .get ();
8786 Span currentSpan = currentTracer .scopeManager ().activeSpan ();
8887 if (currentSpan != null ) {
8988 HashMapTextMap contextTextMap = new HashMapTextMap ();
9089 currentTracer .inject (currentSpan .context (), Format .Builtin .TEXT_MAP , contextTextMap );
91- log .debug (
92- "Retrieving current span data as current context: " + contextTextMap .getBackingMap ());
9390 return contextTextMap .getBackingMap ();
9491 } else {
9592 return null ;
@@ -98,11 +95,9 @@ public Object getCurrentContext() {
9895
9996 @ Override
10097 public void setCurrentContext (Object context ) {
101- log .debug ("Setting current context" );
10298 Tracer currentTracer = GlobalTracer .get ();
10399 Map <String , String > contextAsMap = (Map <String , String >) context ;
104100 if (contextAsMap != null ) {
105- log .debug ("setting current context to " + contextAsMap );
106101 HashMapTextMap contextTextMap = new HashMapTextMap (contextAsMap );
107102 setCurrentOpenTracingSpanContext (
108103 currentTracer .extract (Format .Builtin .TEXT_MAP , contextTextMap ));
@@ -111,7 +106,6 @@ public void setCurrentContext(Object context) {
111106
112107 @ Override
113108 public void setUp () {
114- log .debug ("Starting a new opentracing span" );
115109 Tracer openTracingTracer = GlobalTracer .get ();
116110 Tracer .SpanBuilder builder =
117111 openTracingTracer
@@ -123,7 +117,6 @@ public void setUp() {
123117 }
124118
125119 Span span = builder .start ();
126- log .debug ("New span: " + span );
127120 openTracingTracer .activateSpan (span );
128121 currentOpenTracingSpan .set (span );
129122 Scope scope = openTracingTracer .activateSpan (span );
@@ -133,24 +126,31 @@ public void setUp() {
133126 @ Override
134127 public void onError (Throwable t ) {
135128 Span span = currentOpenTracingSpan .get ();
136- Tags .ERROR .set (span , true );
137- Map <String , Object > errorData = new HashMap <>();
138- errorData .put (Fields .EVENT , "error" );
139- if (t != null ) {
140- errorData .put (Fields .ERROR_OBJECT , t );
141- errorData .put (Fields .MESSAGE , t .getMessage ());
142- }
143- span .log (errorData );
129+ if (span != null ) {
130+ Tags .ERROR .set (span , true );
131+ Map <String , Object > errorData = new HashMap <>();
132+ errorData .put (Fields .EVENT , "error" );
133+ if (t != null ) {
134+ errorData .put (Fields .ERROR_OBJECT , t );
135+ errorData .put (Fields .MESSAGE , t .getMessage ());
136+ }
137+ span .log (errorData );
138+ }
144139 }
145140
146141 @ Override
147142 public void finish (boolean successful ) {
148143 Scope currentScope = currentOpenTracingScope .get ();
149144 Span currentSpan = currentOpenTracingSpan .get ();
150145
151- log .debug ("Closing currently open span " + currentSpan .context ().toSpanId ());
152- currentScope .close ();
153- currentSpan .finish ();
146+ if (currentScope != null ) {
147+ currentScope .close ();
148+ }
149+
150+ if (currentSpan != null ) {
151+ currentSpan .finish ();
152+ }
153+
154154 currentOpenTracingScope .remove ();
155155 currentOpenTracingSpan .remove ();
156156 currentOpenTracingSpanContext .remove ();
0 commit comments