Skip to content

Commit

Permalink
Fixed span optionally None (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
danyi1212 authored Jan 28, 2025
1 parent 6abc1d3 commit bd69bfb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/opal-client/opal_client/data/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def _handle_policy_data_update(span=None):
)
return {"status": "ok"}
else:
if span:
if span is not None:
span.set_status(trace.StatusCode.ERROR)
span.set_attribute("error", True)
span.set_attribute("error_type", "updater_disabled")
Expand All @@ -37,7 +37,7 @@ async def _handle_policy_data_update(span=None):
)
except Exception as e:
logger.error(f"Error during data update: {str(e)}")
if span:
if span is not None:
span.set_status(trace.StatusCode.ERROR)
span.set_attribute("error", True)
span.record_exception(e)
Expand Down
2 changes: 1 addition & 1 deletion packages/opal-client/opal_client/policy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def _handle_policy_update(span=None):
return {"status": "ok"}
except Exception as e:
logger.error(f"Error during policy update: {str(e)}")
if span:
if span is not None:
span.set_status(trace.StatusCode.ERROR)
span.set_attribute("error", True)
span.record_exception(e)
Expand Down
3 changes: 2 additions & 1 deletion packages/opal-server/opal_server/policy/watcher/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ async def trigger(self, topic: Topic, data: Any):
pull)"""
try:
async with start_span("opal_server_policy_update") as span:
span.set_attribute("topic", str(topic))
if span is not None:
span.set_attribute("topic", str(topic))
await self._watcher.check_for_changes()
except Exception as e:
raise
11 changes: 7 additions & 4 deletions packages/opal-server/opal_server/scopes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ async def put_scope(
claims: JWTClaims = Depends(authenticator),
):
async with start_span("opal_server_policy_update") as span:
span.set_attribute("scope_id", scope_in.scope_id)
if span is not None:
span.set_attribute("scope_id", scope_in.scope_id)
return await _handle_put_scope(force_fetch, scope_in, claims)

async def _handle_put_scope(
Expand Down Expand Up @@ -273,7 +274,8 @@ async def get_scope_policy(
),
):
async with start_span("opal_server_policy_bundle_request") as span:
span.set_attribute("scope_id", scope_id)
if span is not None:
span.set_attribute("scope_id", scope_id)
policy_bundle = await _handle_get_scope_policy(scope_id, base_hash)
policy_bundle_size_histogram = get_policy_bundle_size_histogram()
if policy_bundle_size_histogram and policy_bundle.bundle:
Expand Down Expand Up @@ -380,7 +382,8 @@ async def publish_data_update_event(
scope_id: str = Path(..., description="Scope ID"),
):
async with start_span("opal_server_data_update") as span:
span.set_attribute("scope_id", scope_id)
if span is not None:
span.set_attribute("scope_id", scope_id)
await _handle_publish_data_update_event(update, claims, scope_id, span)

async def _handle_publish_data_update_event(
Expand All @@ -399,7 +402,7 @@ async def _handle_publish_data_update_event(
entry.topics = [f"data:{topic}" for topic in entry.topics]
all_topics.update(entry.topics)

if span:
if span is not None:
span.set_attribute("entries_count", len(update.entries))
span.set_attribute("topics", list(all_topics))

Expand Down

0 comments on commit bd69bfb

Please sign in to comment.