Skip to content

Commit 9ec76d4

Browse files
committed
changes according to PR feedback @pcrespov
1 parent c820e6b commit 9ec76d4

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

packages/service-library/src/servicelib/aiohttp/tracing.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _startup(
113113
# Since the code that is provided (monkeypatched) in the __init__ that the opentelemetry-autoinstrumentation-library provides is only 4 lines,
114114
# just adding a middleware, we are free to simply execute this "missed call" [since we can't call the monkeypatch'ed __init__()] in this following line:
115115
if add_response_trace_id_header:
116-
app.middlewares.insert(0, ResponseTraceIdHeaderMiddleware)
116+
app.middlewares.insert(0, response_trace_id_header_middleware)
117117
app.middlewares.insert(0, aiohttp_server_opentelemetry_middleware)
118118
# Code of the aiohttp server instrumentation: github.com/open-telemetry/opentelemetry-python-contrib/blob/eccb05c808a7d797ef5b6ecefed3590664426fbf/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py#L246
119119
# For reference, the above statement was written for:
@@ -155,14 +155,16 @@ def _startup(
155155

156156

157157
@web.middleware
158-
async def ResponseTraceIdHeaderMiddleware(request: web.Request, handler):
158+
async def response_trace_id_header_middleware(request: web.Request, handler):
159+
headers = get_trace_id_header()
160+
159161
try:
160162
response = await handler(request)
161163
except web.HTTPException as exc:
162-
if headers := get_trace_id_header():
164+
if headers:
163165
exc.headers.update(headers)
164166
raise exc
165-
if headers := get_trace_id_header():
167+
if headers:
166168
response.headers.update(headers)
167169
return response
168170

@@ -196,6 +198,7 @@ def _shutdown() -> None:
196198

197199

198200
def get_tracing_lifespan(
201+
*,
199202
app: web.Application,
200203
tracing_settings: TracingSettings,
201204
service_name: str,

packages/service-library/tests/aiohttp/test_tracing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def test_valid_tracing_settings(
6262
service_name = "simcore_service_webserver"
6363
tracing_settings = TracingSettings()
6464
async for _ in get_tracing_lifespan(
65-
app, service_name=service_name, tracing_settings=tracing_settings
65+
app=app, service_name=service_name, tracing_settings=tracing_settings
6666
)(app):
6767
pass
6868

@@ -139,13 +139,13 @@ async def test_tracing_setup_package_detection(
139139
service_name = "simcore_service_webserver"
140140
tracing_settings = TracingSettings()
141141
async for _ in get_tracing_lifespan(
142-
app,
142+
app=app,
143143
service_name=service_name,
144144
tracing_settings=tracing_settings,
145145
)(app):
146146
# idempotency
147147
async for _ in get_tracing_lifespan(
148-
app,
148+
app=app,
149149
service_name=service_name,
150150
tracing_settings=tracing_settings,
151151
)(app):
@@ -182,7 +182,7 @@ async def handler(request: web.Request) -> web.Response:
182182
app.router.add_get("/", handler)
183183

184184
async for _ in get_tracing_lifespan(
185-
app,
185+
app=app,
186186
service_name=service_name,
187187
tracing_settings=tracing_settings,
188188
add_response_trace_id_header=True,

services/web/server/src/simcore_service_webserver/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setup_app_tracing(app: web.Application):
2525
tracing_settings: TracingSettings = get_plugin_settings(app)
2626
app.cleanup_ctx.append(
2727
get_tracing_lifespan(
28-
app,
28+
app=app,
2929
tracing_settings=tracing_settings,
3030
service_name=APP_NAME,
3131
add_response_trace_id_header=True,

0 commit comments

Comments
 (0)