9
9
import io .lumigo .core .parsers .v1 .AwsSdkV1ParserFactory ;
10
10
import io .lumigo .core .parsers .v2 .AwsSdkV2ParserFactory ;
11
11
import io .lumigo .core .utils .AwsUtils ;
12
+ import io .lumigo .core .utils .EnvUtil ;
12
13
import io .lumigo .core .utils .JsonUtils ;
14
+ import io .lumigo .core .utils .SecretScrubber ;
13
15
import io .lumigo .core .utils .StringUtils ;
14
16
import io .lumigo .models .HttpSpan ;
17
+ import io .lumigo .models .Reportable ;
15
18
import io .lumigo .models .Span ;
16
19
import java .io .*;
17
20
import java .util .*;
@@ -38,14 +41,14 @@ public class SpansContainer {
38
41
private static final String AMZN_TRACE_ID = "_X_AMZN_TRACE_ID" ;
39
42
private static final String FUNCTION_SPAN_TYPE = "function" ;
40
43
private static final String HTTP_SPAN_TYPE = "http" ;
44
+ private static final SecretScrubber secretScrubber = new SecretScrubber (new EnvUtil ().getEnv ());
41
45
42
46
private Span baseSpan ;
43
47
private Span startFunctionSpan ;
44
48
private Long rttDuration ;
45
49
private Span endFunctionSpan ;
46
50
private Reporter reporter ;
47
51
private List <HttpSpan > httpSpans = new LinkedList <>();
48
-
49
52
private static final SpansContainer ourInstance = new SpansContainer ();
50
53
51
54
public static SpansContainer getInstance () {
@@ -68,6 +71,7 @@ private SpansContainer() {}
68
71
public void init (Map <String , String > env , Reporter reporter , Context context , Object event ) {
69
72
this .clear ();
70
73
this .reporter = reporter ;
74
+
71
75
int javaVersion = AwsUtils .parseJavaVersion (System .getProperty ("java.version" ));
72
76
if (javaVersion > 11 ) {
73
77
awsTracerId = System .getProperty ("com.amazonaws.xray.traceHeader" );
@@ -214,8 +218,8 @@ public Span getStartFunctionSpan() {
214
218
return startFunctionSpan ;
215
219
}
216
220
217
- public List <Object > getAllCollectedSpans () {
218
- List <Object > spans = new LinkedList <>();
221
+ public List <Reportable > getAllCollectedSpans () {
222
+ List <Reportable > spans = new LinkedList <>();
219
223
spans .add (endFunctionSpan );
220
224
spans .addAll (httpSpans );
221
225
return spans ;
@@ -518,63 +522,22 @@ protected static <T> T callIfVerbose(Callable<T> method) {
518
522
}
519
523
}
520
524
521
- private Object prepareToSend (Object span , boolean hasError ) {
522
- return reduceSpanSize (span , hasError );
525
+ private Reportable prepareToSend (Reportable span , boolean hasError ) {
526
+ return reduceSpanSize (span . scrub ( secretScrubber ) , hasError );
523
527
}
524
528
525
- private List <Object > prepareToSend (List <Object > spans , boolean hasError ) {
526
- for (Object span : spans ) {
527
- reduceSpanSize (span , hasError );
529
+ private List <Reportable > prepareToSend (List <Reportable > spans , boolean hasError ) {
530
+ for (Reportable span : spans ) {
531
+ reduceSpanSize (span . scrub ( secretScrubber ) , hasError );
528
532
}
529
533
return spans ;
530
534
}
531
535
532
- public Object reduceSpanSize (Object span , boolean hasError ) {
536
+ public Reportable reduceSpanSize (Reportable span , boolean hasError ) {
533
537
int maxFieldSize =
534
538
hasError
535
539
? Configuration .getInstance ().maxSpanFieldSizeWhenError ()
536
540
: Configuration .getInstance ().maxSpanFieldSize ();
537
- if (span instanceof Span ) {
538
- Span functionSpan = (Span ) span ;
539
- functionSpan .setEnvs (
540
- StringUtils .getMaxSizeString (
541
- functionSpan .getEnvs (),
542
- Configuration .getInstance ().maxSpanFieldSize ()));
543
- functionSpan .setReturn_value (
544
- StringUtils .getMaxSizeString (functionSpan .getReturn_value (), maxFieldSize ));
545
- functionSpan .setEvent (
546
- StringUtils .getMaxSizeString (functionSpan .getEvent (), maxFieldSize ));
547
- } else if (span instanceof HttpSpan ) {
548
- HttpSpan httpSpan = (HttpSpan ) span ;
549
- httpSpan .getInfo ()
550
- .getHttpInfo ()
551
- .getRequest ()
552
- .setHeaders (
553
- StringUtils .getMaxSizeString (
554
- httpSpan .getInfo ().getHttpInfo ().getRequest ().getHeaders (),
555
- maxFieldSize ));
556
- httpSpan .getInfo ()
557
- .getHttpInfo ()
558
- .getRequest ()
559
- .setBody (
560
- StringUtils .getMaxSizeString (
561
- httpSpan .getInfo ().getHttpInfo ().getRequest ().getBody (),
562
- maxFieldSize ));
563
- httpSpan .getInfo ()
564
- .getHttpInfo ()
565
- .getResponse ()
566
- .setHeaders (
567
- StringUtils .getMaxSizeString (
568
- httpSpan .getInfo ().getHttpInfo ().getResponse ().getHeaders (),
569
- maxFieldSize ));
570
- httpSpan .getInfo ()
571
- .getHttpInfo ()
572
- .getResponse ()
573
- .setBody (
574
- StringUtils .getMaxSizeString (
575
- httpSpan .getInfo ().getHttpInfo ().getResponse ().getBody (),
576
- maxFieldSize ));
577
- }
578
- return span ;
541
+ return span .reduceSize (maxFieldSize );
579
542
}
580
543
}
0 commit comments