Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade starlette, python #40

Merged
merged 6 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand All @@ -36,7 +36,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pytest-asyncio = "==0.16.0"

[packages]
aiozipkin = "==1.0.0"
starlette = "==0.14.1"
starlette = "==0.20.4"

[pipenv]
allow_prereleases = false
894 changes: 413 additions & 481 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def get_packages(package):
author_email="mic.vala@gmail.com",
packages=get_packages("starlette_zipkin"),
install_requires=[
'aiozipkin <2',
'starlette >0.14,<18',
"aiozipkin <2",
"starlette >0.14,<21",
],
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import pytest
from starlette.testclient import TestClient

from starlette_zipkin import ZipkinConfig, ZipkinMiddleware


def test_config_instance(app, tracer):
with pytest.raises(ValueError):
app.add_middleware(ZipkinMiddleware, config=TestClient, _tracer=tracer)


def test_sync_no_inject(app, tracer, b3_keys):
config = ZipkinConfig(inject_response_headers=False)
app.add_middleware(ZipkinMiddleware, config=config, _tracer=tracer)
Expand Down
38 changes: 14 additions & 24 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ async def test_dispatch_trace_new_child(app, dummy_request, next_response):
)
assert middleware.tracer is not None
assert middleware.tracer._transport is not None
assert (
str(middleware.tracer._transport._address)
== "http://zipkin.host:9411/api/v2/spans"
)
assert dict(resp.headers) == {
"x-b3-spanid": span_id,
"x-b3-traceid": trace_id,
}
assert str(middleware.tracer._transport._address) == "http://zipkin.host:9411/api/v2/spans"
assert resp.headers["x-b3-spanid"] == span_id
assert resp.headers["x-b3-traceid"] == trace_id
await middleware.tracer.close()


Expand All @@ -45,16 +40,11 @@ async def test_dispatch_trace(app, dummy_request, next_response):
)
assert middleware.tracer is not None
assert middleware.tracer._transport is not None
assert (
str(middleware.tracer._transport._address)
== "http://localhost:9411/api/v2/spans"
)
assert dict(resp.headers) == {
"x-b3-flags": "0",
"x-b3-sampled": "1",
"x-b3-spanid": resp.headers["x-b3-spanid"],
"x-b3-traceid": resp.headers["x-b3-traceid"],
}
assert str(middleware.tracer._transport._address) == "http://localhost:9411/api/v2/spans"
assert resp.headers["x-b3-flags"] == "0"
assert resp.headers["x-b3-sampled"] == "1"
assert resp.headers["x-b3-spanid"] == resp.headers["x-b3-spanid"]
assert resp.headers["x-b3-traceid"] == resp.headers["x-b3-traceid"]
await middleware.tracer.close()


Expand All @@ -76,12 +66,10 @@ async def test_dispatch_trace_buggy_headers(app, dummy_request, next_response):
)
assert middleware.tracer is not None
assert middleware.tracer._transport is not None
assert dict(resp.headers) == {
"x-b3-flags": "0",
"x-b3-sampled": "1",
"x-b3-spanid": resp.headers["x-b3-spanid"],
"x-b3-traceid": resp.headers["x-b3-traceid"],
}
assert resp.headers["x-b3-flags"] == "0"
assert resp.headers["x-b3-sampled"] == "1"
assert resp.headers["x-b3-spanid"] == resp.headers["x-b3-spanid"]
assert resp.headers["x-b3-traceid"] == resp.headers["x-b3-traceid"]
# we cannot reuse the traceid if the span id was missing
assert trace_id != resp.headers["x-b3-spanid"]
await middleware.tracer.close()
Expand Down Expand Up @@ -172,10 +160,12 @@ def test_get_transaction(app, params):
transac = middleware.get_transaction({"endpoint": params["endpoint"]})
assert transac == params["expected"]


def test_get_ip_with_hostname_that_resolves(monkeypatch):
monkeypatch.setattr(middleware.socket, "gethostname", lambda: "localhost")
assert middleware.get_ip() == "127.0.0.1"


def test_get_ip_without_hostname_that_resolves(monkeypatch):
monkeypatch.setattr(middleware.socket, "gethostname", lambda: "thishostnamewontresolve")
assert middleware.get_ip() == "0.0.0.0"