Skip to content

Commit

Permalink
fix a bunch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beniwohli committed Oct 13, 2021
1 parent aed498a commit 518baf1
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion elasticapm/instrumentation/packages/dbapi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions elasticapm/instrumentation/packages/pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,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)

Expand All @@ -123,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:
Expand Down
8 changes: 4 additions & 4 deletions tests/instrumentation/asyncio_tests/aioredis_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/instrumentation/pymongo_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""},
}


Expand All @@ -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": ""},
}


Expand Down
10 changes: 5 additions & 5 deletions tests/instrumentation/redis_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/instrumentation/requests_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 2 additions & 3 deletions tests/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,12 @@ def test_url_sanitization_urlencoded_password():
)
def test_url_to_destination(url, name, resource):
destination = url_to_destination_resource(url)
assert destination["service"]["name"] == name
assert destination["service"]["resource"] == resource
assert destination == resource


def test_url_to_destination_bad_port():
destination = url_to_destination_resource("https://www.elastic.co:bad")
assert destination["service"]["resource"] == "www.elastic.co:443"
assert destination == "www.elastic.co:443"


def test_read_pem_file():
Expand Down

0 comments on commit 518baf1

Please sign in to comment.