88import static datadog .trace .bootstrap .instrumentation .decorator .http .HttpResourceDecorator .HTTP_RESOURCE_DECORATOR ;
99
1010import datadog .appsec .api .blocking .BlockingException ;
11+ import datadog .context .Context ;
12+ import datadog .context .InferredProxyContext ;
13+ import datadog .context .propagation .Propagators ;
1114import datadog .trace .api .Config ;
1215import datadog .trace .api .DDTags ;
1316import datadog .trace .api .DDTraceId ;
@@ -409,16 +412,6 @@ public void setRequestBlockingAction(Flow.Action.RequestBlockingAction rba) {
409412 public Flow .Action .RequestBlockingAction getRequestBlockingAction () {
410413 return serverSpan .getRequestBlockingAction ();
411414 }
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- }
422415 }
423416
424417 private static final Logger log = LoggerFactory .getLogger (HttpServerDecorator .class );
@@ -501,6 +494,8 @@ public AgentSpanContext.Extracted extract(REQUEST_CARRIER carrier) {
501494 if (null == carrier || null == getter ) {
502495 return null ;
503496 }
497+ Context c = Propagators .defaultPropagator ().extract (Context .root (), carrier , getter );
498+ c .attach ();
504499 return extractContextAndGetSpanContext (carrier , getter );
505500 }
506501
@@ -514,36 +509,63 @@ public AgentSpan startSpan(
514509 String instrumentationName , REQUEST_CARRIER carrier , AgentSpanContext .Extracted context ) {
515510 AgentSpan apiGtwSpan = null ;
516511 if (Config .get ().isInferredProxyPropagationEnabled ()) {
517- System .out .println ("inferred proxy to be crearted " );
512+ System .out .println ("inferred proxy to be created " );
518513 // create the apigtw span
519514 apiGtwSpan =
520515 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 ());
521519
522520 // WILL NEED CONTEXT TRACKING API TO GET TAGS FROM CONTEXT
523521 // set tags from Context
524522 // System.out.println("here");
525523 // InferredProxyContext inferredProxyContext =
526- // Context.root().get(InferredProxyContext.CONTEXT_KEY);
524+ // Context.root().get(InferredProxyContext.CONTEXT_KEY);
527525 // System.out.println("hello inferred context obj: " + inferredProxyContext);
528526 // Map<String, String> contextMap = inferredProxyContext.getInferredProxyContext();
529527 // System.out.println("hello inferred map: " + contextMap);
530528 // //get(InferredProxyPropagator.INFERRED_PROXY_KEY);
531529 // if (contextMap != null) {
532530 // apiGtwSpan.setAllTags(inferredProxyContext.getInferredProxyContext());
533531 // }
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 ();
535543 // mocking tags
536544 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" ));
540556 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);
544565 apiGtwSpan .setTag ("stage" , "dev" );
545566 apiGtwSpan .setTag ("_dd.inferred_span" , "1" );
546567 }
568+
547569 AgentSpan span =
548570 tracer ()
549571 .startSpan (
@@ -560,6 +582,8 @@ public AgentSpan startSpan(
560582 tracer ().getDataStreamsMonitoring ().setCheckpoint (span , fromTags (SERVER_PATHWAY_EDGE_TAGS ));
561583 }
562584 System .out .println ("starting http server span" );
585+ System .out .println (apiGtwSpan );
586+ System .out .println (span );
563587 return new InferredProxySpanGroup (apiGtwSpan , span );
564588 }
565589
0 commit comments