@@ -93,6 +93,7 @@ def __init__(
9393 audit_log_fp = None ,
9494 default_content_encoding_header = "Identity" ,
9595 ):
96+ self ._host = host
9697 self ._audit_log_fp = audit_log_fp
9798
9899 def __enter__ (self ):
@@ -565,12 +566,20 @@ class DeveloperModeClient(SupportabilityMixin, BaseClient):
565566 def send_request (
566567 self , method = "POST" , path = "/agent_listener/invoke_raw_method" , params = None , headers = None , payload = None
567568 ):
568- request_id = self .log_request (
569- self ._audit_log_fp , "POST" , f"https://fake-collector.newrelic.com{ path } " , params , payload , headers
570- )
569+ # Pre-connect and OTLP endpoint requests will not have the fake- prefix, so we forcibly add it just to be sure.
570+ host = self ._host if self ._host .startswith ("fake-" ) else f"fake-{ self ._host } "
571+ url = f"https://{ host } { path } "
572+ request_id = self .log_request (self ._audit_log_fp , "POST" , url , params , payload , headers )
573+
574+ # Don't attempt to handle OTLP endpoint requests
575+ if host == "fake-otlp.nr-data.net" :
576+ return 200 , b""
577+
578+ # Requests to the collector must have a method parameter or they're invalid
571579 if not params or "method" not in params :
572580 return 400 , b"Missing method parameter"
573581
582+ # If we don't have a canned response for the method, return an error
574583 method = params ["method" ]
575584 if method not in self .RESPONSES :
576585 return 400 , b"Invalid method received"
@@ -592,8 +601,9 @@ def send_request(
592601 ):
593602 result = super ().send_request (method = method , path = path , params = params , headers = headers , payload = payload )
594603
595- if result [0 ] == 200 :
596- agent_method = params ["method" ]
604+ # Check for the presence of agent_method to ensure this isn't an OTLP request
605+ agent_method = params and params .get ("method" )
606+ if result [0 ] == 200 and agent_method :
597607 self .payload [agent_method ] = json_decode (payload .decode ("utf-8" ))
598608
599609 return result
0 commit comments