in elasticapm/traces.py [0:0]
def autofill_resource_context(self) -> None:
"""Automatically fills "resource" fields based on other fields"""
if self.context:
resource = nested_key(self.context, "destination", "service", "resource")
if not resource and (self.leaf or any(k in self.context for k in ("destination", "db", "message", "http"))):
type_info = self.subtype or self.type
instance = nested_key(self.context, "db", "instance")
queue_name = nested_key(self.context, "message", "queue", "name")
http_url = nested_key(self.context, "http", "url")
if instance:
resource = f"{type_info}/{instance}"
elif queue_name:
resource = f"{type_info}/{queue_name}"
elif http_url:
resource = url_to_destination_resource(http_url)
else:
resource = type_info
if "destination" not in self.context:
self.context["destination"] = {}
if "service" not in self.context["destination"]:
self.context["destination"]["service"] = {}
self.context["destination"]["service"]["resource"] = resource
# set fields that are deprecated, but still required by APM Server API
if "name" not in self.context["destination"]["service"]:
self.context["destination"]["service"]["name"] = ""
if "type" not in self.context["destination"]["service"]:
self.context["destination"]["service"]["type"] = ""