11package com .microsoft .cse .reference .spring .dal .controllers ;
22
3+ import com .microsoft .cse .reference .spring .dal .JaegerTracerHelper ;
34import com .microsoft .cse .reference .spring .dal .converters .IntegerToBoolean ;
45import com .microsoft .cse .reference .spring .dal .converters .EmptyStringToNull ;
56import com .microsoft .cse .reference .spring .dal .models .PrincipalWithName ;
1516import static java .util .Arrays .asList ;
1617import static org .springframework .data .mongodb .core .aggregation .Aggregation .*;
1718
19+ import io .opentracing .Span ;
20+ import io .opentracing .Tracer ;
21+
22+ import com .google .common .collect .ImmutableMap ;
23+
1824/**
1925 *
2026 * Create a custom controller so that when a user hits a URL that's not formatted like the search endpoint
@@ -25,9 +31,11 @@ public class CustomEndpointController {
2531 private IntegerToBoolean integerToBoolean = new IntegerToBoolean ();
2632 private EmptyStringToNull emptyStringToNull = new EmptyStringToNull ();
2733 private MongoTemplate mongoTemplate ;
34+ private final Tracer tracer ;
2835
2936 public CustomEndpointController (MongoTemplate mongoTemplate ) {
3037 this .mongoTemplate = mongoTemplate ;
38+ this .tracer = JaegerTracerHelper .initTracer ("custom-endpoint-controller" );
3139 }
3240
3341 /**
@@ -57,6 +65,9 @@ public CustomEndpointController(MongoTemplate mongoTemplate) {
5765 */
5866 @ RequestMapping (method = RequestMethod .GET , value = "/people/{nconst}/titles" )
5967 public List <Title > getAllTitles (@ PathVariable String nconst ) {
68+ Span span = tracer .buildSpan ("get-person-titles" ).start ();
69+ span .log (ImmutableMap .of ("event" , "query-person-titles" , "value" , nconst ));
70+
6071 MatchOperation filterByNconst = match (Criteria .where ("nconst" ).is (nconst ));
6172
6273 LookupOperation titleLookup = LookupOperation .newLookup ()
@@ -73,6 +84,8 @@ public List<Title> getAllTitles(@PathVariable String nconst) {
7384
7485 AggregationResults <Document > aggregationResults = mongoTemplate .aggregate (aggregation , "principals_mapping" , Document .class );
7586
87+ span .finish ();
88+
7689 return documentToTitleList (aggregationResults );
7790 }
7891
@@ -86,6 +99,9 @@ public List<Title> getAllTitles(@PathVariable String nconst) {
8699 */
87100 @ RequestMapping (method = RequestMethod .GET , value = "/titles/{tconst}/people" )
88101 public List <PrincipalWithName > getAllPeople (@ PathVariable String tconst ) {
102+ Span span = tracer .buildSpan ("get-people-from-title" ).start ();
103+ span .log (ImmutableMap .of ("event" , "query-people-from-title" , "value" , tconst ));
104+
89105 MatchOperation filterByNconst = match (Criteria .where ("tconst" ).is (tconst ));
90106 LookupOperation nameLookup = LookupOperation .newLookup ()
91107 .from ("names" )
@@ -106,6 +122,8 @@ public List<PrincipalWithName> getAllPeople(@PathVariable String tconst) {
106122 p .person .remove ("_id" );
107123 }
108124
125+ span .finish ();
126+
109127 return mappedResults ;
110128 }
111129
0 commit comments