@@ -82,14 +82,11 @@ public Object deserializeContext(Map<String, byte[]> context) {
82
82
83
83
@ Override
84
84
public Object getCurrentContext () {
85
- log .debug ("Getting current context" );
86
85
Tracer currentTracer = GlobalTracer .get ();
87
86
Span currentSpan = currentTracer .scopeManager ().activeSpan ();
88
87
if (currentSpan != null ) {
89
88
HashMapTextMap contextTextMap = new HashMapTextMap ();
90
89
currentTracer .inject (currentSpan .context (), Format .Builtin .TEXT_MAP , contextTextMap );
91
- log .debug (
92
- "Retrieving current span data as current context: " + contextTextMap .getBackingMap ());
93
90
return contextTextMap .getBackingMap ();
94
91
} else {
95
92
return null ;
@@ -98,11 +95,9 @@ public Object getCurrentContext() {
98
95
99
96
@ Override
100
97
public void setCurrentContext (Object context ) {
101
- log .debug ("Setting current context" );
102
98
Tracer currentTracer = GlobalTracer .get ();
103
99
Map <String , String > contextAsMap = (Map <String , String >) context ;
104
100
if (contextAsMap != null ) {
105
- log .debug ("setting current context to " + contextAsMap );
106
101
HashMapTextMap contextTextMap = new HashMapTextMap (contextAsMap );
107
102
setCurrentOpenTracingSpanContext (
108
103
currentTracer .extract (Format .Builtin .TEXT_MAP , contextTextMap ));
@@ -111,7 +106,6 @@ public void setCurrentContext(Object context) {
111
106
112
107
@ Override
113
108
public void setUp () {
114
- log .debug ("Starting a new opentracing span" );
115
109
Tracer openTracingTracer = GlobalTracer .get ();
116
110
Tracer .SpanBuilder builder =
117
111
openTracingTracer
@@ -123,7 +117,6 @@ public void setUp() {
123
117
}
124
118
125
119
Span span = builder .start ();
126
- log .debug ("New span: " + span );
127
120
openTracingTracer .activateSpan (span );
128
121
currentOpenTracingSpan .set (span );
129
122
Scope scope = openTracingTracer .activateSpan (span );
@@ -133,24 +126,31 @@ public void setUp() {
133
126
@ Override
134
127
public void onError (Throwable t ) {
135
128
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
+ }
144
139
}
145
140
146
141
@ Override
147
142
public void finish (boolean successful ) {
148
143
Scope currentScope = currentOpenTracingScope .get ();
149
144
Span currentSpan = currentOpenTracingSpan .get ();
150
145
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
+
154
154
currentOpenTracingScope .remove ();
155
155
currentOpenTracingSpan .remove ();
156
156
currentOpenTracingSpanContext .remove ();
0 commit comments