8
8
import static datadog .trace .bootstrap .instrumentation .decorator .http .HttpResourceDecorator .HTTP_RESOURCE_DECORATOR ;
9
9
10
10
import datadog .appsec .api .blocking .BlockingException ;
11
+ import datadog .context .Context ;
12
+ import datadog .context .InferredProxyContext ;
13
+ import datadog .context .propagation .Propagators ;
11
14
import datadog .trace .api .Config ;
12
15
import datadog .trace .api .DDTags ;
13
16
import datadog .trace .api .DDTraceId ;
@@ -409,16 +412,6 @@ public void setRequestBlockingAction(Flow.Action.RequestBlockingAction rba) {
409
412
public Flow .Action .RequestBlockingAction getRequestBlockingAction () {
410
413
return serverSpan .getRequestBlockingAction ();
411
414
}
412
-
413
- @ Override
414
- public boolean isRequiresPostProcessing () {
415
- return serverSpan .isRequiresPostProcessing ();
416
- }
417
-
418
- @ Override
419
- public void setRequiresPostProcessing (boolean requiresPostProcessing ) {
420
- serverSpan .setRequiresPostProcessing (requiresPostProcessing );
421
- }
422
415
}
423
416
424
417
private static final Logger log = LoggerFactory .getLogger (HttpServerDecorator .class );
@@ -501,6 +494,8 @@ public AgentSpanContext.Extracted extract(REQUEST_CARRIER carrier) {
501
494
if (null == carrier || null == getter ) {
502
495
return null ;
503
496
}
497
+ Context c = Propagators .defaultPropagator ().extract (Context .root (), carrier , getter );
498
+ c .attach ();
504
499
return extractContextAndGetSpanContext (carrier , getter );
505
500
}
506
501
@@ -514,36 +509,63 @@ public AgentSpan startSpan(
514
509
String instrumentationName , REQUEST_CARRIER carrier , AgentSpanContext .Extracted context ) {
515
510
AgentSpan apiGtwSpan = null ;
516
511
if (Config .get ().isInferredProxyPropagationEnabled ()) {
517
- System .out .println ("inferred proxy to be crearted " );
512
+ System .out .println ("inferred proxy to be created " );
518
513
// create the apigtw span
519
514
apiGtwSpan =
520
515
tracer ().startSpan ("inferred_proxy" , "aws.apigateway" , callIGCallbackStart (context ));
516
+ InferredProxyContext inferredProxy = InferredProxyContext .fromContext (Context .current ());
517
+ System .out .println ("inferredProxy matt way: " + inferredProxy );
518
+ System .out .println ("inferredProxy matt way map: " + inferredProxy .getInferredProxyContext ());
521
519
522
520
// WILL NEED CONTEXT TRACKING API TO GET TAGS FROM CONTEXT
523
521
// set tags from Context
524
522
// System.out.println("here");
525
523
// InferredProxyContext inferredProxyContext =
526
- // Context.root().get(InferredProxyContext.CONTEXT_KEY);
524
+ // Context.root().get(InferredProxyContext.CONTEXT_KEY);
527
525
// System.out.println("hello inferred context obj: " + inferredProxyContext);
528
526
// Map<String, String> contextMap = inferredProxyContext.getInferredProxyContext();
529
527
// System.out.println("hello inferred map: " + contextMap);
530
528
// //get(InferredProxyPropagator.INFERRED_PROXY_KEY);
531
529
// if (contextMap != null) {
532
530
// apiGtwSpan.setAllTags(inferredProxyContext.getInferredProxyContext());
533
531
// }
534
-
532
+ System .out .println ("gateway span after context: " + apiGtwSpan );
533
+ /*
534
+ inferredProxy matt way map:
535
+ {x-dd-proxy-request-time-ms=123,
536
+ x-dd-proxy-path=/api/hello,
537
+ x-dd-proxy-httpmethod=GET,
538
+ x-dd-proxy-domain-name=example.com,
539
+ x-dd-proxy=true,
540
+ x-dd-proxy-stage=dev}
541
+ */
542
+ Map <String , String > inferredProxyTagInfo = inferredProxy .getInferredProxyContext ();
535
543
// mocking tags
536
544
apiGtwSpan .setTag (Tags .COMPONENT , "aws.apigateway" );
537
- apiGtwSpan .setTag (DDTags .RESOURCE_NAME , "GET /api/hello" );
538
- apiGtwSpan .setTag (DDTags .TRACE_START_TIME , "123" );
539
- apiGtwSpan .setTag (DDTags .SERVICE_NAME , "example.com" );
545
+ // "GET /api/hello"
546
+ apiGtwSpan .setTag (
547
+ DDTags .RESOURCE_NAME ,
548
+ inferredProxyTagInfo .get ("x-dd-proxy-httpmethod" )
549
+ + " "
550
+ + inferredProxyTagInfo .get ("x-dd-proxy-path" ));
551
+ // 123
552
+ apiGtwSpan .setTag (
553
+ DDTags .TRACE_START_TIME , inferredProxyTagInfo .get ("x-dd-proxy-request-time-ms" ));
554
+ // example.com
555
+ apiGtwSpan .setTag (DDTags .SERVICE_NAME , inferredProxyTagInfo .get ("x-dd-proxy-domain-name" ));
540
556
apiGtwSpan .setTag (DDTags .SPAN_TYPE , "web" );
541
- apiGtwSpan .setTag (Tags .HTTP_METHOD , "GET" );
542
- apiGtwSpan .setTag (Tags .HTTP_URL , "example.com/api/hello" );
543
- apiGtwSpan .setHttpStatusCode (200 );
557
+ // GET
558
+ apiGtwSpan .setTag (Tags .HTTP_METHOD , inferredProxyTagInfo .get ("x-dd-proxy-httpmethod" ));
559
+ // "example.com/api/hello"
560
+ apiGtwSpan .setTag (
561
+ Tags .HTTP_URL ,
562
+ inferredProxyTagInfo .get ("x-dd-proxy-domain-name" )
563
+ + inferredProxyTagInfo .get ("x-dd-proxy-path" ));
564
+ // apiGtwSpan.setHttpStatusCode(200);
544
565
apiGtwSpan .setTag ("stage" , "dev" );
545
566
apiGtwSpan .setTag ("_dd.inferred_span" , "1" );
546
567
}
568
+
547
569
AgentSpan span =
548
570
tracer ()
549
571
.startSpan (
@@ -560,6 +582,8 @@ public AgentSpan startSpan(
560
582
tracer ().getDataStreamsMonitoring ().setCheckpoint (span , fromTags (SERVER_PATHWAY_EDGE_TAGS ));
561
583
}
562
584
System .out .println ("starting http server span" );
585
+ System .out .println (apiGtwSpan );
586
+ System .out .println (span );
563
587
return new InferredProxySpanGroup (apiGtwSpan , span );
564
588
}
565
589
0 commit comments