diff --git a/elasticapm/instrumentation/packages/asyncio/aiohttp_client.py b/elasticapm/instrumentation/packages/asyncio/aiohttp_client.py index 34ab29710..a3cfbfd84 100644 --- a/elasticapm/instrumentation/packages/asyncio/aiohttp_client.py +++ b/elasticapm/instrumentation/packages/asyncio/aiohttp_client.py @@ -32,7 +32,7 @@ from elasticapm.conf import constants from elasticapm.instrumentation.packages.asyncio.base import AsyncAbstractInstrumentedModule from elasticapm.traces import DroppedSpan, execution_context -from elasticapm.utils import get_host_from_url, sanitize_url, url_to_destination +from elasticapm.utils import get_host_from_url, sanitize_url from elasticapm.utils.disttracing import TracingOptions @@ -45,7 +45,6 @@ async def call(self, module, method, wrapped, instance, args, kwargs): method = kwargs["method"] if "method" in kwargs else args[0] url = kwargs["url"] if "url" in kwargs else args[1] url = str(url) - destination = url_to_destination(url) signature = " ".join([method.upper(), get_host_from_url(url)]) url = sanitize_url(url) @@ -55,7 +54,7 @@ async def call(self, module, method, wrapped, instance, args, kwargs): signature, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: leaf_span = span diff --git a/elasticapm/instrumentation/packages/asyncio/aiomysql.py b/elasticapm/instrumentation/packages/asyncio/aiomysql.py index a6d31f5b0..af65a3e97 100644 --- a/elasticapm/instrumentation/packages/asyncio/aiomysql.py +++ b/elasticapm/instrumentation/packages/asyncio/aiomysql.py @@ -53,7 +53,7 @@ async def call(self, module, method, wrapped, instance, args, kwargs): "destination": { "address": instance.connection.host, "port": instance.connection.port, - "service": {"name": "mysql", "resource": "mysql", "type": "db"}, + "service": {"name": "", "resource": "mysql", "type": ""}, }, } action = "query" diff --git a/elasticapm/instrumentation/packages/asyncio/aioredis.py b/elasticapm/instrumentation/packages/asyncio/aioredis.py index 411b66a07..dc04aecc9 100644 --- a/elasticapm/instrumentation/packages/asyncio/aioredis.py +++ b/elasticapm/instrumentation/packages/asyncio/aioredis.py @@ -91,7 +91,7 @@ def call(self, module, method, wrapped, instance, args, kwargs): def _get_destination_info(connection): - destination_info = {"service": {"name": "aioredis", "resource": "redis", "type": "db"}} + destination_info = {"service": {"name": "", "resource": "redis", "type": ""}} if hasattr(connection, "_pool_or_conn"): destination_info["port"] = connection._pool_or_conn.address[1] diff --git a/elasticapm/instrumentation/packages/asyncio/asyncpg.py b/elasticapm/instrumentation/packages/asyncio/asyncpg.py index eec6a33e4..c8e2ef757 100644 --- a/elasticapm/instrumentation/packages/asyncio/asyncpg.py +++ b/elasticapm/instrumentation/packages/asyncio/asyncpg.py @@ -68,7 +68,7 @@ async def call(self, module, method, wrapped, instance, args, kwargs): destination_info = { "address": kwargs.get("host", "localhost"), "port": int(kwargs.get("port", default_ports.get("postgresql"))), - "service": {"name": "postgresql", "resource": "postgresql", "type": "db"}, + "service": {"name": "", "resource": "postgresql", "type": ""}, } context["destination"] = destination_info async with async_capture_span( diff --git a/elasticapm/instrumentation/packages/asyncio/httpcore.py b/elasticapm/instrumentation/packages/asyncio/httpcore.py index 7f7d50c91..469fa1cc7 100644 --- a/elasticapm/instrumentation/packages/asyncio/httpcore.py +++ b/elasticapm/instrumentation/packages/asyncio/httpcore.py @@ -32,7 +32,7 @@ from elasticapm.contrib.asyncio.traces import async_capture_span from elasticapm.instrumentation.packages.asyncio.base import AsyncAbstractInstrumentedModule from elasticapm.traces import DroppedSpan, execution_context -from elasticapm.utils import default_ports, url_to_destination +from elasticapm.utils import default_ports from elasticapm.utils.disttracing import TracingOptions @@ -82,7 +82,6 @@ async def call(self, module, method, wrapped, instance, args, kwargs): signature = "%s %s" % (method.upper(), host) url = "%s://%s%s" % (scheme, host, url) - destination = url_to_destination(url) transaction = execution_context.get_transaction() @@ -90,7 +89,7 @@ async def call(self, module, method, wrapped, instance, args, kwargs): signature, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: # if httpcore has been called in a leaf span, this span might be a DroppedSpan. diff --git a/elasticapm/instrumentation/packages/asyncio/httpx.py b/elasticapm/instrumentation/packages/asyncio/httpx.py index e3b33b230..0f2cf6065 100644 --- a/elasticapm/instrumentation/packages/asyncio/httpx.py +++ b/elasticapm/instrumentation/packages/asyncio/httpx.py @@ -30,7 +30,7 @@ from elasticapm.contrib.asyncio.traces import async_capture_span from elasticapm.instrumentation.packages.asyncio.base import AsyncAbstractInstrumentedModule -from elasticapm.utils import get_host_from_url, sanitize_url, url_to_destination +from elasticapm.utils import get_host_from_url, sanitize_url class HttpxAsyncClientInstrumentation(AsyncAbstractInstrumentedModule): @@ -45,13 +45,12 @@ async def call(self, module, method, wrapped, instance, args, kwargs): url = str(request.url) name = "{request_method} {host}".format(request_method=request_method, host=get_host_from_url(url)) url = sanitize_url(url) - destination = url_to_destination(url) async with async_capture_span( name, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: response = await wrapped(*args, **kwargs) diff --git a/elasticapm/instrumentation/packages/cassandra.py b/elasticapm/instrumentation/packages/cassandra.py index f8ca0c320..93645f7ba 100644 --- a/elasticapm/instrumentation/packages/cassandra.py +++ b/elasticapm/instrumentation/packages/cassandra.py @@ -75,7 +75,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): context["destination"] = { "address": host, "port": port, - "service": {"name": "cassandra", "resource": "cassandra", "type": "db"}, } with capture_span(name, span_type="db", span_subtype="cassandra", span_action=span_action, extra=context): diff --git a/elasticapm/instrumentation/packages/dbapi2.py b/elasticapm/instrumentation/packages/dbapi2.py index 39ab137a4..6cdcd5268 100644 --- a/elasticapm/instrumentation/packages/dbapi2.py +++ b/elasticapm/instrumentation/packages/dbapi2.py @@ -201,7 +201,7 @@ class CursorProxy(wrapt.ObjectProxy): def __init__(self, wrapped, destination_info=None): super(CursorProxy, self).__init__(wrapped) - self._self_destination_info = destination_info + self._self_destination_info = destination_info or {} def callproc(self, procname, params=None): return self._trace_sql(self.__wrapped__.callproc, procname, params, action=EXEC_ACTION) diff --git a/elasticapm/instrumentation/packages/elasticsearch.py b/elasticapm/instrumentation/packages/elasticsearch.py index 0b37b0c98..68a6665a1 100644 --- a/elasticapm/instrumentation/packages/elasticsearch.py +++ b/elasticapm/instrumentation/packages/elasticsearch.py @@ -91,7 +91,6 @@ def _update_context_by_request_data(self, context, instance, args, kwargs): context["destination"] = { "address": instance.host, - "service": {"name": "elasticsearch", "resource": "elasticsearch", "type": "db"}, } diff --git a/elasticapm/instrumentation/packages/httpcore.py b/elasticapm/instrumentation/packages/httpcore.py index eebcfa7ed..45da86464 100644 --- a/elasticapm/instrumentation/packages/httpcore.py +++ b/elasticapm/instrumentation/packages/httpcore.py @@ -31,7 +31,7 @@ from elasticapm.conf import constants from elasticapm.instrumentation.packages.base import AbstractInstrumentedModule from elasticapm.traces import DroppedSpan, capture_span, execution_context -from elasticapm.utils import default_ports, url_to_destination +from elasticapm.utils import default_ports from elasticapm.utils.disttracing import TracingOptions @@ -72,7 +72,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): signature = "%s %s" % (method.upper(), host) url = "%s://%s%s" % (scheme, host, url) - destination = url_to_destination(url) transaction = execution_context.get_transaction() @@ -80,7 +79,7 @@ def call(self, module, method, wrapped, instance, args, kwargs): signature, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: # if httpcore has been called in a leaf span, this span might be a DroppedSpan. diff --git a/elasticapm/instrumentation/packages/httplib2.py b/elasticapm/instrumentation/packages/httplib2.py index 5c254207e..224e51665 100644 --- a/elasticapm/instrumentation/packages/httplib2.py +++ b/elasticapm/instrumentation/packages/httplib2.py @@ -31,7 +31,7 @@ from elasticapm.conf import constants from elasticapm.instrumentation.packages.base import AbstractInstrumentedModule from elasticapm.traces import DroppedSpan, capture_span, execution_context -from elasticapm.utils import get_host_from_url, sanitize_url, url_to_destination +from elasticapm.utils import get_host_from_url, sanitize_url from elasticapm.utils.disttracing import TracingOptions @@ -72,13 +72,12 @@ def call(self, module, method, wrapped, instance, args, kwargs): signature = params.get("method", "GET").upper() signature += " " + get_host_from_url(params["url"]) url = sanitize_url(params["url"]) - destination = url_to_destination(url) transaction = execution_context.get_transaction() with capture_span( signature, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: # if httplib2 has been called in a leaf span, this span might be a DroppedSpan. diff --git a/elasticapm/instrumentation/packages/httpx.py b/elasticapm/instrumentation/packages/httpx.py index 71430542f..c0555b0fe 100644 --- a/elasticapm/instrumentation/packages/httpx.py +++ b/elasticapm/instrumentation/packages/httpx.py @@ -30,7 +30,7 @@ from elasticapm.instrumentation.packages.base import AbstractInstrumentedModule from elasticapm.traces import capture_span -from elasticapm.utils import get_host_from_url, sanitize_url, url_to_destination +from elasticapm.utils import get_host_from_url, sanitize_url class HttpxClientInstrumentation(AbstractInstrumentedModule): @@ -45,13 +45,12 @@ def call(self, module, method, wrapped, instance, args, kwargs): url = str(request.url) name = "{request_method} {host}".format(request_method=request_method, host=get_host_from_url(url)) url = sanitize_url(url) - destination = url_to_destination(url) with capture_span( name, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: response = wrapped(*args, **kwargs) diff --git a/elasticapm/instrumentation/packages/mysql.py b/elasticapm/instrumentation/packages/mysql.py index 3745c4b42..e3489d463 100644 --- a/elasticapm/instrumentation/packages/mysql.py +++ b/elasticapm/instrumentation/packages/mysql.py @@ -57,6 +57,5 @@ def call(self, module, method, wrapped, instance, args, kwargs): destination_info = { "address": args[0] if len(args) else kwargs.get("host", "localhost"), "port": args[4] if len(args) > 4 else int(kwargs.get("port", default_ports.get("mysql"))), - "service": {"name": "mysql", "resource": "mysql", "type": "db"}, } return MySQLConnectionProxy(wrapped(*args, **kwargs), destination_info=destination_info) diff --git a/elasticapm/instrumentation/packages/mysql_connector.py b/elasticapm/instrumentation/packages/mysql_connector.py index 78ddc988f..acd9089fb 100644 --- a/elasticapm/instrumentation/packages/mysql_connector.py +++ b/elasticapm/instrumentation/packages/mysql_connector.py @@ -58,6 +58,5 @@ def call(self, module, method, wrapped, instance, args, kwargs): destination_info = { "address": kwargs.get("host", "localhost"), "port": int(kwargs.get("port", default_ports.get("mysql"))), - "service": {"name": "mysql", "resource": "mysql", "type": "db"}, } return MySQLConnectionProxy(wrapped(*args, **kwargs), destination_info=destination_info) diff --git a/elasticapm/instrumentation/packages/psycopg2.py b/elasticapm/instrumentation/packages/psycopg2.py index b871a4179..919aa6acc 100644 --- a/elasticapm/instrumentation/packages/psycopg2.py +++ b/elasticapm/instrumentation/packages/psycopg2.py @@ -92,7 +92,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): destination_info = { "address": kwargs.get("host", "localhost"), "port": int(kwargs.get("port", default_ports.get("postgresql"))), - "service": {"name": "postgresql", "resource": "postgresql", "type": "db"}, } with capture_span( signature, diff --git a/elasticapm/instrumentation/packages/pylibmc.py b/elasticapm/instrumentation/packages/pylibmc.py index 10ecac3cc..d8ab18e01 100644 --- a/elasticapm/instrumentation/packages/pylibmc.py +++ b/elasticapm/instrumentation/packages/pylibmc.py @@ -65,7 +65,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): destination = { "address": address, "port": port, - "service": {"name": "memcached", "resource": "memcached", "type": "cache"}, } with capture_span( wrapped_name, diff --git a/elasticapm/instrumentation/packages/pymemcache.py b/elasticapm/instrumentation/packages/pymemcache.py index ff001cdc5..7decc4f31 100644 --- a/elasticapm/instrumentation/packages/pymemcache.py +++ b/elasticapm/instrumentation/packages/pymemcache.py @@ -83,7 +83,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): destination = { "address": address, "port": port, - "service": {"name": "memcached", "resource": "memcached", "type": "cache"}, } if "PooledClient" in name: diff --git a/elasticapm/instrumentation/packages/pymongo.py b/elasticapm/instrumentation/packages/pymongo.py index de2fb1786..777c7159a 100644 --- a/elasticapm/instrumentation/packages/pymongo.py +++ b/elasticapm/instrumentation/packages/pymongo.py @@ -80,7 +80,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): destination_info = { "address": host, "port": port, - "service": {"name": "mongodb", "resource": "mongodb", "type": "db"}, } with capture_span( signature, @@ -106,7 +105,7 @@ def call(self, module, method, wrapped, instance, args, kwargs): span_type="db", span_subtype="mongodb", span_action="query", - extra={"destination": {"service": {"name": "mongodb", "resource": "mongodb", "type": "db"}}}, + extra={"destination": {}}, ): return wrapped(*args, **kwargs) @@ -124,7 +123,7 @@ def call(self, module, method, wrapped, instance, args, kwargs): span_type="db", span_subtype="mongodb", span_action="query", - extra={"destination": {"service": {"name": "mongodb", "resource": "mongodb", "type": "db"}}}, + extra={"destination": {}}, ) as span: response = wrapped(*args, **kwargs) if span.context and instance.address: diff --git a/elasticapm/instrumentation/packages/pymssql.py b/elasticapm/instrumentation/packages/pymssql.py index de3e53795..2d17929e5 100644 --- a/elasticapm/instrumentation/packages/pymssql.py +++ b/elasticapm/instrumentation/packages/pymssql.py @@ -58,7 +58,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): destination_info = { "address": host, "port": port, - "service": {"name": "mssql", "resource": "mssql", "type": "db"}, } return PyMSSQLConnectionProxy(wrapped(*args, **kwargs), destination_info=destination_info) diff --git a/elasticapm/instrumentation/packages/python_memcached.py b/elasticapm/instrumentation/packages/python_memcached.py index 33624569d..60bfb1120 100644 --- a/elasticapm/instrumentation/packages/python_memcached.py +++ b/elasticapm/instrumentation/packages/python_memcached.py @@ -75,7 +75,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): destination = { "address": address, "port": port, - "service": {"name": "memcached", "resource": "memcached", "type": "cache"}, } with capture_span( name, span_type="cache", span_subtype="memcached", span_action="query", extra={"destination": destination} diff --git a/elasticapm/instrumentation/packages/redis.py b/elasticapm/instrumentation/packages/redis.py index 0b3c6ea03..e15a2e66a 100644 --- a/elasticapm/instrumentation/packages/redis.py +++ b/elasticapm/instrumentation/packages/redis.py @@ -92,7 +92,7 @@ def call(self, module, method, wrapped, instance, args, kwargs): def get_destination_info(connection): - destination_info = {"service": {"name": "redis", "resource": "redis", "type": "db"}} + destination_info = {} if hasattr(connection, "port"): destination_info["port"] = connection.port destination_info["address"] = connection.host diff --git a/elasticapm/instrumentation/packages/requests.py b/elasticapm/instrumentation/packages/requests.py index 11129f5d1..dc2285045 100644 --- a/elasticapm/instrumentation/packages/requests.py +++ b/elasticapm/instrumentation/packages/requests.py @@ -30,7 +30,7 @@ from elasticapm.instrumentation.packages.base import AbstractInstrumentedModule from elasticapm.traces import capture_span -from elasticapm.utils import get_host_from_url, sanitize_url, url_to_destination +from elasticapm.utils import get_host_from_url, sanitize_url class RequestsInstrumentation(AbstractInstrumentedModule): @@ -47,13 +47,12 @@ def call(self, module, method, wrapped, instance, args, kwargs): signature = request.method.upper() signature += " " + get_host_from_url(request.url) url = sanitize_url(request.url) - destination = url_to_destination(url) with capture_span( signature, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: response = wrapped(*args, **kwargs) diff --git a/elasticapm/instrumentation/packages/urllib.py b/elasticapm/instrumentation/packages/urllib.py index c3629a88e..bfdef23e4 100644 --- a/elasticapm/instrumentation/packages/urllib.py +++ b/elasticapm/instrumentation/packages/urllib.py @@ -32,7 +32,7 @@ from elasticapm.conf import constants from elasticapm.instrumentation.packages.base import AbstractInstrumentedModule from elasticapm.traces import DroppedSpan, capture_span, execution_context -from elasticapm.utils import compat, default_ports, sanitize_url, url_to_destination +from elasticapm.utils import compat, default_ports, sanitize_url from elasticapm.utils.disttracing import TracingOptions @@ -74,7 +74,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): host = request_host(request_object) url = sanitize_url(request_object.get_full_url()) - destination = url_to_destination(url) signature = method.upper() + " " + host transaction = execution_context.get_transaction() @@ -83,7 +82,7 @@ def call(self, module, method, wrapped, instance, args, kwargs): signature, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: # if urllib has been called in a leaf span, this span might be a DroppedSpan. diff --git a/elasticapm/instrumentation/packages/urllib3.py b/elasticapm/instrumentation/packages/urllib3.py index 35a08f750..80e7eadf2 100644 --- a/elasticapm/instrumentation/packages/urllib3.py +++ b/elasticapm/instrumentation/packages/urllib3.py @@ -33,7 +33,7 @@ from elasticapm.conf import constants from elasticapm.instrumentation.packages.base import AbstractInstrumentedModule from elasticapm.traces import DroppedSpan, capture_span, execution_context -from elasticapm.utils import default_ports, url_to_destination +from elasticapm.utils import default_ports from elasticapm.utils.disttracing import TracingOptions @@ -106,7 +106,6 @@ def call(self, module, method, wrapped, instance, args, kwargs): signature = method.upper() + " " + host url = "%s://%s%s" % (instance.scheme, host, url) - destination = url_to_destination(url) transaction = execution_context.get_transaction() @@ -114,7 +113,7 @@ def call(self, module, method, wrapped, instance, args, kwargs): signature, span_type="external", span_subtype="http", - extra={"http": {"url": url}, "destination": destination}, + extra={"http": {"url": url}}, leaf=True, ) as span: # if urllib3 has been called in a leaf span, this span might be a DroppedSpan. diff --git a/elasticapm/traces.py b/elasticapm/traces.py index c6f465e0d..3656717ce 100644 --- a/elasticapm/traces.py +++ b/elasticapm/traces.py @@ -41,7 +41,7 @@ from elasticapm.conf.constants import LABEL_RE, SPAN, TRANSACTION from elasticapm.context import init_execution_context from elasticapm.metrics.base_metrics import Timer -from elasticapm.utils import compat, encoding, get_name_from_func, nested_key +from elasticapm.utils import compat, encoding, get_name_from_func, nested_key, url_to_destination_resource from elasticapm.utils.disttracing import TraceParent, TracingOptions from elasticapm.utils.logging import get_logger @@ -210,7 +210,7 @@ def end(self, skip_frames: int = 0, duration: Optional[float] = None): "transaction.duration", reset_on_collect=True, unit="us", - **{"transaction.name": self.name, "transaction.type": self.transaction_type} + **{"transaction.name": self.name, "transaction.type": self.transaction_type}, ).update(int(self.duration * 1000000)) if self._breakdown: for (span_type, span_subtype), timer in compat.iteritems(self._span_timers): @@ -232,7 +232,7 @@ def end(self, skip_frames: int = 0, duration: Optional[float] = None): "span.self_time", reset_on_collect=True, unit="us", - **{"span.type": "app", "transaction.name": self.name, "transaction.type": self.transaction_type} + **{"span.type": "app", "transaction.name": self.name, "transaction.type": self.transaction_type}, ).update(int((self.duration - self._child_durations.duration) * 1000000)) def _begin_span( @@ -516,6 +516,30 @@ def to_dict(self) -> dict: self.context = {} self.context["tags"] = self.labels 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"] = "" result["context"] = self.context if self.frames: result["stacktrace"] = self.frames @@ -641,7 +665,7 @@ def update_context(self, key, data): self.context[key] = current def __str__(self): - return u"{}/{}/{}".format(self.name, self.type, self.subtype) + return "{}/{}/{}".format(self.name, self.type, self.subtype) @property def tracer(self) -> "Tracer": diff --git a/elasticapm/utils/__init__.py b/elasticapm/utils/__init__.py index b823a9e5d..1fda0125d 100644 --- a/elasticapm/utils/__init__.py +++ b/elasticapm/utils/__init__.py @@ -142,7 +142,7 @@ def get_host_from_url(url: str) -> str: return host -def url_to_destination(url: str, service_type: str = "external") -> dict: +def url_to_destination_resource(url: str) -> dict: parts = compat.urlparse.urlsplit(url) hostname = parts.hostname if parts.hostname else "" # preserve brackets for IPv6 URLs @@ -162,7 +162,7 @@ def url_to_destination(url: str, service_type: str = "external") -> dict: if port != default_port: name += ":%d" % port resource += ":%d" % port - return {"service": {"name": name, "resource": resource, "type": service_type}} + return resource def read_pem_file(file_obj) -> bytes: diff --git a/tests/instrumentation/asyncio_tests/aiohttp_client_tests.py b/tests/instrumentation/asyncio_tests/aiohttp_client_tests.py index 7de4e1f81..d00048d3a 100644 --- a/tests/instrumentation/asyncio_tests/aiohttp_client_tests.py +++ b/tests/instrumentation/asyncio_tests/aiohttp_client_tests.py @@ -64,9 +64,9 @@ async def test_http_get(instrument, event_loop, elasticapm_client, waiting_https assert span["context"]["http"]["url"] == waiting_httpserver.url assert span["context"]["http"]["status_code"] == 204 assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % waiting_httpserver.server_address[1], + "name": "", "resource": "127.0.0.1:%d" % waiting_httpserver.server_address[1], - "type": "external", + "type": "", } assert spans[0]["outcome"] == "success" @@ -95,9 +95,9 @@ async def test_http_get_error(instrument, event_loop, elasticapm_client, waiting assert span["context"]["http"]["url"] == waiting_httpserver.url assert span["context"]["http"]["status_code"] == status_code assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % waiting_httpserver.server_address[1], + "name": "", "resource": "127.0.0.1:%d" % waiting_httpserver.server_address[1], - "type": "external", + "type": "", } assert spans[0]["outcome"] == "failure" diff --git a/tests/instrumentation/asyncio_tests/aiomysql_tests.py b/tests/instrumentation/asyncio_tests/aiomysql_tests.py index 4a3f3f5be..959c1477f 100644 --- a/tests/instrumentation/asyncio_tests/aiomysql_tests.py +++ b/tests/instrumentation/asyncio_tests/aiomysql_tests.py @@ -98,5 +98,5 @@ async def test_aiomysql_select(instrument, aiomysql_connection, elasticapm_clien assert span["context"]["destination"] == { "address": os.environ.get("MYSQL_HOST", "localhost"), "port": default_ports.get("mysql"), - "service": {"name": "mysql", "resource": "mysql", "type": "db"}, + "service": {"name": "", "resource": "mysql", "type": ""}, } diff --git a/tests/instrumentation/asyncio_tests/aioredis_tests.py b/tests/instrumentation/asyncio_tests/aioredis_tests.py index 28804df38..c402c482d 100644 --- a/tests/instrumentation/asyncio_tests/aioredis_tests.py +++ b/tests/instrumentation/asyncio_tests/aioredis_tests.py @@ -87,7 +87,7 @@ async def test_pipeline(instrument, elasticapm_client, redis_conn): assert spans[0]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "aioredis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[1]["name"] == "test_pipeline" @@ -118,7 +118,7 @@ async def test_redis_client(instrument, elasticapm_client, redis_conn): assert spans[0]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "aioredis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[1]["name"] == "RPUSH" @@ -128,7 +128,7 @@ async def test_redis_client(instrument, elasticapm_client, redis_conn): assert spans[1]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "aioredis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[2]["name"] == "test_redis_client" @@ -164,7 +164,7 @@ async def test_publish_subscribe_async(instrument, elasticapm_client, redis_conn assert spans[0]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "aioredis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[1]["name"] == "SUBSCRIBE" @@ -174,7 +174,7 @@ async def test_publish_subscribe_async(instrument, elasticapm_client, redis_conn assert spans[1]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "aioredis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[2]["name"] == "test_publish_subscribe" diff --git a/tests/instrumentation/asyncio_tests/httpx_tests.py b/tests/instrumentation/asyncio_tests/httpx_tests.py index 0a58076e4..529f7cc38 100644 --- a/tests/instrumentation/asyncio_tests/httpx_tests.py +++ b/tests/instrumentation/asyncio_tests/httpx_tests.py @@ -66,9 +66,9 @@ async def test_httpx_instrumentation(instrument, elasticapm_client, waiting_http assert spans[0]["outcome"] == "success" assert url == spans[0]["context"]["http"]["url"] assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } headers = waiting_httpserver.requests[0].headers diff --git a/tests/instrumentation/cassandra_tests.py b/tests/instrumentation/cassandra_tests.py index 0ccc0fe85..52f75c669 100644 --- a/tests/instrumentation/cassandra_tests.py +++ b/tests/instrumentation/cassandra_tests.py @@ -85,7 +85,7 @@ def test_cassandra_connect(instrument, elasticapm_client, cassandra_cluster): assert span["context"]["destination"] == { "address": socket.gethostbyname(os.environ.get("CASSANDRA_HOST", "localhost")), "port": 9042, - "service": {"name": "cassandra", "resource": "cassandra", "type": "db"}, + "service": {"name": "", "resource": "cassandra", "type": ""}, } @@ -103,7 +103,7 @@ def test_select_query_string(instrument, cassandra_session, elasticapm_client): assert span["context"]["destination"] == { "address": socket.gethostbyname(os.environ.get("CASSANDRA_HOST", "localhost")), "port": 9042, - "service": {"name": "cassandra", "resource": "cassandra", "type": "db"}, + "service": {"name": "", "resource": "cassandra", "type": ""}, } diff --git a/tests/instrumentation/elasticsearch_tests.py b/tests/instrumentation/elasticsearch_tests.py index 286e46b81..797ff5c7f 100644 --- a/tests/instrumentation/elasticsearch_tests.py +++ b/tests/instrumentation/elasticsearch_tests.py @@ -107,7 +107,7 @@ def test_ping(instrument, elasticapm_client, elasticsearch): assert span["action"] == "query" assert span["context"]["destination"] == { "address": os.environ["ES_URL"], - "service": {"name": "elasticsearch", "resource": "elasticsearch", "type": "db"}, + "service": {"name": "", "resource": "elasticsearch", "type": ""}, } assert span["context"]["http"]["status_code"] == 200 diff --git a/tests/instrumentation/httplib2_tests.py b/tests/instrumentation/httplib2_tests.py index 9edbcb056..a4e164357 100644 --- a/tests/instrumentation/httplib2_tests.py +++ b/tests/instrumentation/httplib2_tests.py @@ -61,9 +61,9 @@ def test_httplib2_instrumentation(instrument, elasticapm_client, waiting_httpser assert url == spans[0]["context"]["http"]["url"] assert 200 == spans[0]["context"]["http"]["status_code"] assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } assert spans[0]["outcome"] == "success" @@ -95,9 +95,9 @@ def test_httplib2_instrumentation_error(instrument, elasticapm_client, waiting_h assert url == spans[0]["context"]["http"]["url"] assert status_code == spans[0]["context"]["http"]["status_code"] assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } assert spans[0]["outcome"] == "failure" diff --git a/tests/instrumentation/httpx_tests.py b/tests/instrumentation/httpx_tests.py index 4165699fe..716e28bfe 100644 --- a/tests/instrumentation/httpx_tests.py +++ b/tests/instrumentation/httpx_tests.py @@ -64,9 +64,9 @@ def test_httpx_instrumentation(instrument, elasticapm_client, waiting_httpserver assert spans[0]["subtype"] == "http" assert url == spans[0]["context"]["http"]["url"] assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } headers = waiting_httpserver.requests[0].headers diff --git a/tests/instrumentation/mysql_connector_tests.py b/tests/instrumentation/mysql_connector_tests.py index dac3337db..a421cb845 100644 --- a/tests/instrumentation/mysql_connector_tests.py +++ b/tests/instrumentation/mysql_connector_tests.py @@ -87,5 +87,5 @@ def test_mysql_connector_select(instrument, mysql_connector_connection, elastica assert span["context"]["destination"] == { "address": "mysql", "port": 3306, - "service": {"name": "mysql", "resource": "mysql", "type": "db"}, + "service": {"name": "", "resource": "mysql", "type": ""}, } diff --git a/tests/instrumentation/mysqlclient_tests.py b/tests/instrumentation/mysqlclient_tests.py index fda1909af..3ef941737 100644 --- a/tests/instrumentation/mysqlclient_tests.py +++ b/tests/instrumentation/mysqlclient_tests.py @@ -89,5 +89,5 @@ def test_mysql_connector_select(instrument, mysqlclient_connection, elasticapm_c assert span["context"]["destination"] == { "address": "mysql", "port": 3306, - "service": {"name": "mysql", "resource": "mysql", "type": "db"}, + "service": {"name": "", "resource": "mysql", "type": ""}, } diff --git a/tests/instrumentation/psycopg2_tests.py b/tests/instrumentation/psycopg2_tests.py index 607df44a1..4469976b3 100644 --- a/tests/instrumentation/psycopg2_tests.py +++ b/tests/instrumentation/psycopg2_tests.py @@ -275,7 +275,7 @@ def test_destination(instrument, postgres_connection, elasticapm_client): assert span["context"]["destination"] == { "address": os.environ.get("POSTGRES_HOST", None), "port": default_ports["postgresql"], - "service": {"name": "postgresql", "resource": "postgresql", "type": "db"}, + "service": {"name": "", "resource": "postgresql", "type": ""}, } diff --git a/tests/instrumentation/pylibmc_tests.py b/tests/instrumentation/pylibmc_tests.py index d216ede05..13b8458e6 100644 --- a/tests/instrumentation/pylibmc_tests.py +++ b/tests/instrumentation/pylibmc_tests.py @@ -75,7 +75,7 @@ def test_pylibmc(instrument, elasticapm_client): assert spans[1]["context"]["destination"] == { "address": host, "port": 11211, - "service": {"name": "memcached", "resource": "memcached", "type": "cache"}, + "service": {"name": "", "resource": "memcached", "type": ""}, } assert spans[2]["name"] == "Client.get_multi" diff --git a/tests/instrumentation/pymemcache_tests.py b/tests/instrumentation/pymemcache_tests.py index 5700d1662..a0e4357ee 100644 --- a/tests/instrumentation/pymemcache_tests.py +++ b/tests/instrumentation/pymemcache_tests.py @@ -77,7 +77,7 @@ def test_pymemcache_client(instrument, elasticapm_client): assert spans[1]["context"]["destination"] == { "address": host, "port": 11211, - "service": {"name": "memcached", "resource": "memcached", "type": "cache"}, + "service": {"name": "", "resource": "memcached", "type": ""}, } assert spans[2]["name"] == "Client.get_many" diff --git a/tests/instrumentation/pymongo_tests.py b/tests/instrumentation/pymongo_tests.py index 029f9d589..56b331dde 100644 --- a/tests/instrumentation/pymongo_tests.py +++ b/tests/instrumentation/pymongo_tests.py @@ -98,7 +98,7 @@ def test_collection_count(instrument, elasticapm_client, mongo_database): assert span["context"]["destination"] == { "address": os.environ.get("MONGODB_HOST", "localhost"), "port": int(os.environ.get("MONGODB_PORT", 27017)), - "service": {"name": "mongodb", "resource": "mongodb", "type": "db"}, + "service": {"name": "", "resource": "mongodb", "type": ""}, } @@ -207,7 +207,7 @@ def test_collection_find(instrument, elasticapm_client, mongo_database): assert span["context"]["destination"] == { "address": os.environ.get("MONGODB_HOST", "localhost"), "port": int(os.environ.get("MONGODB_PORT", 27017)), - "service": {"name": "mongodb", "resource": "mongodb", "type": "db"}, + "service": {"name": "", "resource": "mongodb", "type": ""}, } @@ -229,7 +229,7 @@ def test_collection_find_one(instrument, elasticapm_client, mongo_database): assert span["context"]["destination"] == { "address": os.environ.get("MONGODB_HOST", "localhost"), "port": int(os.environ.get("MONGODB_PORT", 27017)), - "service": {"name": "mongodb", "resource": "mongodb", "type": "db"}, + "service": {"name": "", "resource": "mongodb", "type": ""}, } diff --git a/tests/instrumentation/pymssql_tests.py b/tests/instrumentation/pymssql_tests.py index f64558f3e..4b06c23aa 100644 --- a/tests/instrumentation/pymssql_tests.py +++ b/tests/instrumentation/pymssql_tests.py @@ -89,7 +89,7 @@ def test_pymssql_select(instrument, pymssql_connection, elasticapm_client): assert span["context"]["destination"] == { "address": "mssql", "port": default_ports["mssql"], - "service": {"name": "mssql", "resource": "mssql", "type": "db"}, + "service": {"name": "", "resource": "mssql", "type": ""}, } diff --git a/tests/instrumentation/python_memcached_tests.py b/tests/instrumentation/python_memcached_tests.py index 424faf82a..7cb4feb76 100644 --- a/tests/instrumentation/python_memcached_tests.py +++ b/tests/instrumentation/python_memcached_tests.py @@ -77,7 +77,7 @@ def test_memcached(instrument, elasticapm_client): assert spans[1]["context"]["destination"] == { "address": host, "port": 11211, - "service": {"name": "memcached", "resource": "memcached", "type": "cache"}, + "service": {"name": "", "resource": "memcached", "type": ""}, } assert spans[2]["name"] == "Client.get_multi" diff --git a/tests/instrumentation/redis_tests.py b/tests/instrumentation/redis_tests.py index 6b632cb7f..9d7887814 100644 --- a/tests/instrumentation/redis_tests.py +++ b/tests/instrumentation/redis_tests.py @@ -75,7 +75,7 @@ def test_pipeline(instrument, elasticapm_client, redis_conn): assert spans[0]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "redis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[1]["name"] == "test_pipeline" @@ -108,7 +108,7 @@ def test_rq_patches_redis(instrument, elasticapm_client, redis_conn): assert spans[0]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "redis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[1]["name"] == "test_pipeline" @@ -139,7 +139,7 @@ def test_redis_client(instrument, elasticapm_client, redis_conn): assert spans[0]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "redis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[1]["name"] == "EXPIRE" @@ -149,7 +149,7 @@ def test_redis_client(instrument, elasticapm_client, redis_conn): assert spans[1]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "redis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[2]["name"] == "test_redis_client" @@ -193,7 +193,7 @@ def test_publish_subscribe(instrument, elasticapm_client, redis_conn): assert spans[0]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "redis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[1]["name"] == "SUBSCRIBE" @@ -203,7 +203,7 @@ def test_publish_subscribe(instrument, elasticapm_client, redis_conn): assert spans[1]["context"]["destination"] == { "address": os.environ.get("REDIS_HOST", "localhost"), "port": int(os.environ.get("REDIS_PORT", 6379)), - "service": {"name": "redis", "resource": "redis", "type": "db"}, + "service": {"name": "", "resource": "redis", "type": ""}, } assert spans[2]["name"] == "test_publish_subscribe" diff --git a/tests/instrumentation/requests_tests.py b/tests/instrumentation/requests_tests.py index 60ba9bdd1..c5edfa254 100644 --- a/tests/instrumentation/requests_tests.py +++ b/tests/instrumentation/requests_tests.py @@ -61,9 +61,9 @@ def test_requests_instrumentation(instrument, elasticapm_client, waiting_httpser assert url == spans[0]["context"]["http"]["url"] assert 200 == spans[0]["context"]["http"]["status_code"] assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } assert spans[0]["outcome"] == "success" @@ -99,9 +99,9 @@ def test_requests_instrumentation_error(instrument, elasticapm_client, waiting_h assert url == spans[0]["context"]["http"]["url"] assert status_code == spans[0]["context"]["http"]["status_code"] assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } assert spans[0]["outcome"] == "failure" diff --git a/tests/instrumentation/urllib3_tests.py b/tests/instrumentation/urllib3_tests.py index 82618282e..28a387360 100644 --- a/tests/instrumentation/urllib3_tests.py +++ b/tests/instrumentation/urllib3_tests.py @@ -67,9 +67,9 @@ def test_urllib3(instrument, elasticapm_client, waiting_httpserver): assert spans[0]["context"]["http"]["url"] == url assert spans[0]["context"]["http"]["status_code"] == 200 assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } assert spans[0]["parent_id"] == spans[1]["id"] assert spans[0]["outcome"] == "success" @@ -103,9 +103,9 @@ def test_urllib3_error(instrument, elasticapm_client, waiting_httpserver, status assert spans[0]["context"]["http"]["url"] == url assert spans[0]["context"]["http"]["status_code"] == status_code assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } assert spans[0]["parent_id"] == spans[1]["id"] assert spans[0]["outcome"] == "failure" diff --git a/tests/instrumentation/urllib_tests.py b/tests/instrumentation/urllib_tests.py index 291ed1b04..38536c1b6 100644 --- a/tests/instrumentation/urllib_tests.py +++ b/tests/instrumentation/urllib_tests.py @@ -78,9 +78,9 @@ def test_urllib(instrument, elasticapm_client, waiting_httpserver): assert spans[0]["context"]["http"]["url"] == url assert spans[0]["context"]["http"]["status_code"] == 200 assert spans[0]["context"]["destination"]["service"] == { - "name": "http://127.0.0.1:%d" % parsed_url.port, + "name": "", "resource": "127.0.0.1:%d" % parsed_url.port, - "type": "external", + "type": "", } assert spans[0]["parent_id"] == spans[1]["id"] assert spans[0]["outcome"] == "success" diff --git a/tests/utils/tests.py b/tests/utils/tests.py index ae132279d..c309093c6 100644 --- a/tests/utils/tests.py +++ b/tests/utils/tests.py @@ -41,7 +41,7 @@ read_pem_file, sanitize_url, starmatch_to_regex, - url_to_destination, + url_to_destination_resource, ) from elasticapm.utils.deprecation import deprecated @@ -221,14 +221,13 @@ def test_url_sanitization_urlencoded_password(): ], ) def test_url_to_destination(url, name, resource): - destination = url_to_destination(url) - assert destination["service"]["name"] == name - assert destination["service"]["resource"] == resource + destination = url_to_destination_resource(url) + assert destination == resource def test_url_to_destination_bad_port(): - destination = url_to_destination("https://www.elastic.co:bad") - assert destination["service"]["resource"] == "www.elastic.co:443" + destination = url_to_destination_resource("https://www.elastic.co:bad") + assert destination == "www.elastic.co:443" def test_read_pem_file():