Skip to content

Commit 9abec59

Browse files
committed
refactor code, remove debugging printlns
1 parent ddbc584 commit 9abec59

File tree

2 files changed

+54
-64
lines changed

2 files changed

+54
-64
lines changed

components/context/src/main/java/datadog/context/propagation/InferredProxyPropagator.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ public <C> Context extract(Context context, C carrier, CarrierVisitor<C> visitor
4646
if (extractedContext == null) {
4747
return context;
4848
}
49-
System.out.println("extracted Context:");
50-
System.out.println(extractedContext);
51-
System.out.println("after Extracted");
52-
System.out.println(extractedContext.getInferredProxyContext());
5349
return extractedContext.storeInto(context);
5450
}
5551

@@ -61,7 +57,6 @@ public static class InferredProxyContextExtractor implements BiConsumer<String,
6157

6258
private Map<String, String> parseInferredProxyHeaders(String input) {
6359
Map<String, String> parsedHeaders = new HashMap<>();
64-
System.out.println("parsing input: " + input);
6560
return parsedHeaders;
6661
}
6762

@@ -73,8 +68,6 @@ private Map<String, String> parseInferredProxyHeaders(String input) {
7368
*/
7469
@Override
7570
public void accept(String key, String value) {
76-
System.out.println("hello: " + key);
77-
System.out.println(value);
7871
if (key == null || key.isEmpty() || !key.startsWith(INFERRED_PROXY_KEY)) {
7972
return;
8073
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/HttpServerDecorator.java

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -507,63 +507,10 @@ public AgentSpan startSpan(REQUEST_CARRIER carrier, AgentSpanContext.Extracted c
507507

508508
public AgentSpan startSpan(
509509
String instrumentationName, REQUEST_CARRIER carrier, AgentSpanContext.Extracted context) {
510+
boolean addInferredProxy = Config.get().isInferredProxyPropagationEnabled();
510511
AgentSpan apiGtwSpan = null;
511-
if (Config.get().isInferredProxyPropagationEnabled()) {
512-
System.out.println("inferred proxy to be created");
513-
// create the apigtw span
514-
apiGtwSpan =
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());
519-
520-
// WILL NEED CONTEXT TRACKING API TO GET TAGS FROM CONTEXT
521-
// set tags from Context
522-
// System.out.println("here");
523-
// InferredProxyContext inferredProxyContext =
524-
// Context.root().get(InferredProxyContext.CONTEXT_KEY);
525-
// System.out.println("hello inferred context obj: " + inferredProxyContext);
526-
// Map<String, String> contextMap = inferredProxyContext.getInferredProxyContext();
527-
// System.out.println("hello inferred map: " + contextMap);
528-
// //get(InferredProxyPropagator.INFERRED_PROXY_KEY);
529-
// if (contextMap != null) {
530-
// apiGtwSpan.setAllTags(inferredProxyContext.getInferredProxyContext());
531-
// }
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();
543-
// mocking tags
544-
apiGtwSpan.setTag(Tags.COMPONENT, "aws.apigateway");
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"));
556-
apiGtwSpan.setTag(DDTags.SPAN_TYPE, "web");
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);
565-
apiGtwSpan.setTag("stage", "dev");
566-
apiGtwSpan.setTag("_dd.inferred_span", "1");
512+
if (addInferredProxy) {
513+
apiGtwSpan = startSpanWithInferredProxy(instrumentationName, carrier, context);
567514
}
568515

569516
AgentSpan span =
@@ -581,10 +528,60 @@ public AgentSpan startSpan(
581528
if (null != carrier && null != getter) {
582529
tracer().getDataStreamsMonitoring().setCheckpoint(span, fromTags(SERVER_PATHWAY_EDGE_TAGS));
583530
}
531+
532+
// errors
533+
System.out.println(span);
534+
System.out.println("gtw status code before is: " + apiGtwSpan.getHttpStatusCode());
535+
apiGtwSpan.setHttpStatusCode(span.getHttpStatusCode());
536+
537+
System.out.println("gtw status code after is: " + apiGtwSpan.getHttpStatusCode());
538+
539+
System.out.println("span status code is: " + span.getHttpStatusCode());
540+
584541
System.out.println("starting http server span");
585542
System.out.println(apiGtwSpan);
586543
System.out.println(span);
587-
return new InferredProxySpanGroup(apiGtwSpan, span);
544+
if (addInferredProxy) {
545+
return new InferredProxySpanGroup(apiGtwSpan, span);
546+
} else {
547+
return span;
548+
}
549+
}
550+
551+
private AgentSpan startSpanWithInferredProxy(
552+
String instrumentationName, REQUEST_CARRIER carrier, AgentSpanContext.Extracted context) {
553+
// create the apigtw span
554+
555+
AgentSpan apiGtwSpan =
556+
tracer().startSpan("inferred_proxy", "aws.apigateway", callIGCallbackStart(context));
557+
InferredProxyContext inferredProxy = InferredProxyContext.fromContext(Context.current());
558+
559+
Map<String, String> inferredProxyTagInfo = inferredProxy.getInferredProxyContext();
560+
// mocking tags
561+
apiGtwSpan.setTag(Tags.COMPONENT, "aws.apigateway");
562+
// "GET /api/hello"
563+
apiGtwSpan.setTag(
564+
DDTags.RESOURCE_NAME,
565+
inferredProxyTagInfo.get("x-dd-proxy-httpmethod")
566+
+ " "
567+
+ inferredProxyTagInfo.get("x-dd-proxy-path"));
568+
// 123
569+
apiGtwSpan.setTag(
570+
DDTags.TRACE_START_TIME, inferredProxyTagInfo.get("x-dd-proxy-request-time-ms"));
571+
// example.com
572+
apiGtwSpan.setTag(DDTags.SERVICE_NAME, inferredProxyTagInfo.get("x-dd-proxy-domain-name"));
573+
apiGtwSpan.setTag(DDTags.SPAN_TYPE, "web");
574+
// GET
575+
apiGtwSpan.setTag(Tags.HTTP_METHOD, inferredProxyTagInfo.get("x-dd-proxy-httpmethod"));
576+
// "example.com/api/hello"
577+
apiGtwSpan.setTag(
578+
Tags.HTTP_URL,
579+
inferredProxyTagInfo.get("x-dd-proxy-domain-name")
580+
+ inferredProxyTagInfo.get("x-dd-proxy-path"));
581+
// apiGtwSpan.setHttpStatusCode(200);
582+
apiGtwSpan.setTag("stage", "dev");
583+
apiGtwSpan.setTag("_dd.inferred_span", "1");
584+
return apiGtwSpan;
588585
}
589586

590587
public AgentSpan onRequest(

0 commit comments

Comments
 (0)