@@ -144,34 +144,43 @@ public void annotationIndex(Span span) {
144
144
145
145
146
146
public void durationIndex (Span span ) {
147
- List <Annotation > alist = span .getAnnotations ();
148
- Annotation cs = getCsAnnotation (alist );
149
- Annotation cr = getCrAnnotation (alist );
150
- if (cs != null ) {
151
- long duration = cs .getTimestamp () - cr .getTimestamp ();
152
- String rowkey = cs .getHost ().getServiceName () + ":" + cs .getTimestamp ();
153
- Put put = new Put (rowkey .getBytes ());
154
- //rowkey:serviceId:csTime
155
- //每列的timestamp为duration
156
- //每列列名为traceId,值为1(用来区分1ms内的跟踪)
157
- put .add (duration_index_family_column .getBytes (), long2ByteArray (span .getTraceId ()), duration , "1" .getBytes ());
158
- HTableInterface htable = null ;
159
- try {
160
- htable = POOL .getTable (duration_index );
161
- htable .put (put );
162
- } catch (IOException e ) {
163
- e .printStackTrace ();
164
- }finally {
165
- if (htable != null ){
166
- try {
167
- htable .close ();
168
- } catch (IOException e ) {
169
- e .printStackTrace ();
147
+ if (isRootSpan (span )) {
148
+ List <Annotation > alist = span .getAnnotations ();
149
+ Annotation cs = getCsAnnotation (alist );
150
+ Annotation cr = getCrAnnotation (alist );
151
+ if (cs != null ) {
152
+ long duration = cr .getTimestamp () - cs .getTimestamp ();
153
+ String rowkey = cs .getHost ().getServiceName () + ":" + cs .getTimestamp ();
154
+ Put put = new Put (rowkey .getBytes ());
155
+ //rowkey:serviceId:csTime
156
+ //每列的timestamp为duration
157
+ //每列列名为traceId,值为1(用来区分1ms内的跟踪)
158
+ put .add (duration_index_family_column .getBytes (), long2ByteArray (span .getTraceId ()), duration , "1" .getBytes ());
159
+ HTableInterface htable = null ;
160
+ try {
161
+ htable = POOL .getTable (duration_index );
162
+ System .out .println (1 );
163
+ htable .put (put );
164
+ } catch (IOException e ) {
165
+ e .printStackTrace ();
166
+ }catch (Exception e ) {
167
+ e .printStackTrace ();
168
+ }finally {
169
+ if (htable != null ){
170
+ try {
171
+ htable .close ();
172
+ } catch (IOException e ) {
173
+ e .printStackTrace ();
174
+ }
170
175
}
171
176
}
172
177
}
173
178
}
174
179
}
175
180
181
+ private boolean isRootSpan (Span span ) {
182
+ return span .getParentId () == null ;
183
+ }
184
+
176
185
177
186
}
0 commit comments