99import io .lumigo .core .parsers .v1 .AwsSdkV1ParserFactory ;
1010import io .lumigo .core .parsers .v2 .AwsSdkV2ParserFactory ;
1111import io .lumigo .core .utils .AwsUtils ;
12+ import io .lumigo .core .utils .EnvUtil ;
1213import io .lumigo .core .utils .JsonUtils ;
14+ import io .lumigo .core .utils .SecretScrubber ;
1315import io .lumigo .core .utils .StringUtils ;
1416import io .lumigo .models .HttpSpan ;
17+ import io .lumigo .models .Reportable ;
1518import io .lumigo .models .Span ;
1619import java .io .*;
1720import java .util .*;
@@ -38,14 +41,14 @@ public class SpansContainer {
3841 private static final String AMZN_TRACE_ID = "_X_AMZN_TRACE_ID" ;
3942 private static final String FUNCTION_SPAN_TYPE = "function" ;
4043 private static final String HTTP_SPAN_TYPE = "http" ;
44+ private static final SecretScrubber secretScrubber = new SecretScrubber (new EnvUtil ().getEnv ());
4145
4246 private Span baseSpan ;
4347 private Span startFunctionSpan ;
4448 private Long rttDuration ;
4549 private Span endFunctionSpan ;
4650 private Reporter reporter ;
4751 private List <HttpSpan > httpSpans = new LinkedList <>();
48-
4952 private static final SpansContainer ourInstance = new SpansContainer ();
5053
5154 public static SpansContainer getInstance () {
@@ -68,6 +71,7 @@ private SpansContainer() {}
6871 public void init (Map <String , String > env , Reporter reporter , Context context , Object event ) {
6972 this .clear ();
7073 this .reporter = reporter ;
74+
7175 int javaVersion = AwsUtils .parseJavaVersion (System .getProperty ("java.version" ));
7276 if (javaVersion > 11 ) {
7377 awsTracerId = System .getProperty ("com.amazonaws.xray.traceHeader" );
@@ -214,8 +218,8 @@ public Span getStartFunctionSpan() {
214218 return startFunctionSpan ;
215219 }
216220
217- public List <Object > getAllCollectedSpans () {
218- List <Object > spans = new LinkedList <>();
221+ public List <Reportable > getAllCollectedSpans () {
222+ List <Reportable > spans = new LinkedList <>();
219223 spans .add (endFunctionSpan );
220224 spans .addAll (httpSpans );
221225 return spans ;
@@ -518,63 +522,22 @@ protected static <T> T callIfVerbose(Callable<T> method) {
518522 }
519523 }
520524
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 );
523527 }
524528
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 );
528532 }
529533 return spans ;
530534 }
531535
532- public Object reduceSpanSize (Object span , boolean hasError ) {
536+ public Reportable reduceSpanSize (Reportable span , boolean hasError ) {
533537 int maxFieldSize =
534538 hasError
535539 ? Configuration .getInstance ().maxSpanFieldSizeWhenError ()
536540 : 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 );
579542 }
580543}
0 commit comments