Skip to content

✨Added tracing decorator, and add some example usage#9161

Draft
sanderegg wants to merge 11 commits into
ITISFoundation:masterfrom
sanderegg:autoscaling/add-ec2-tracing
Draft

✨Added tracing decorator, and add some example usage#9161
sanderegg wants to merge 11 commits into
ITISFoundation:masterfrom
sanderegg:autoscaling/add-ec2-tracing

Conversation

@sanderegg
Copy link
Copy Markdown
Member

What do these changes do?

Related issue/s

How to test

Dev-ops

@sanderegg sanderegg added this to the Ionio milestone May 22, 2026
@sanderegg sanderegg self-assigned this May 22, 2026
@sanderegg sanderegg requested a review from Copilot May 22, 2026 14:11
@github-actions github-actions Bot added a:storage issue related to storage service a:webserver webserver's codebase. Assigning the area is particularly useful for bugs a:services-library issues on packages/service-libs a:static-webserver static-webserver service a:autoscaling autoscaling service in simcore's stack a:clusters-keeper labels May 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.01%. Comparing base (344551f) to head (09e42f7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9161      +/-   ##
==========================================
+ Coverage   87.34%   89.01%   +1.67%     
==========================================
  Files        2065     1410     -655     
  Lines       81471    59906   -21565     
  Branches     1475      194    -1281     
==========================================
- Hits        71162    53328   -17834     
+ Misses       9900     6517    -3383     
+ Partials      409       61     -348     
Flag Coverage Δ
integrationtests 71.95% <ø> (+8.24%) ⬆️
unittests 87.81% <100.00%> (+1.58%) ⬆️
Components Coverage Δ
pkg_aws_library ∅ <ø> (∅)
pkg_celery_library ∅ <ø> (∅)
pkg_dask_task_models_library ∅ <ø> (∅)
pkg_models_library ∅ <ø> (∅)
pkg_notifications_library ∅ <ø> (∅)
pkg_postgres_database ∅ <ø> (∅)
pkg_service_integration ∅ <ø> (∅)
pkg_service_library ∅ <ø> (∅)
pkg_settings_library ∅ <ø> (∅)
pkg_simcore_sdk 85.92% <ø> (-0.06%) ⬇️
agent 93.43% <ø> (ø)
api_server 91.45% <ø> (ø)
autoscaling 95.51% <100.00%> (+0.02%) ⬆️
catalog 92.12% <ø> (ø)
clusters_keeper 98.61% <100.00%> (+<0.01%) ⬆️
dask_sidecar 91.74% <ø> (ø)
datcore_adapter 97.95% <ø> (ø)
director 77.44% <ø> (ø)
director_v2 91.30% <ø> (-0.03%) ⬇️
dynamic_scheduler 95.98% <ø> (+0.19%) ⬆️
dynamic_sidecar 88.03% <ø> (ø)
efs_guardian 89.77% <ø> (ø)
invitations 91.56% <ø> (ø)
payments 92.44% <ø> (ø)
resource_usage_tracker 92.37% <ø> (+0.25%) ⬆️
storage 86.82% <100.00%> (+0.01%) ⬆️
webclient ∅ <ø> (∅)
webserver 86.07% <100.00%> (-0.74%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 344551f...09e42f7. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a reusable tracing decorator in servicelib and applies it across several services to generate OpenTelemetry spans with minimal boilerplate, plus adds autoscaling-specific helpers to link EC2 instance lifecycle spans back to the launch span via EC2 tags.

Changes:

  • Added a @traced decorator (sync + async) built on top of traced_operation, with new unit tests.
  • Instrumented key periodic/background routines (webserver garbage collector, storage DSM cleaner, clusters-keeper cluster checks, autoscaling cycles) via @traced.
  • Added autoscaling utilities to persist traceparent in EC2 tags and create linked lifecycle spans (launch/attach/drain/terminate).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
services/web/server/src/simcore_service_webserver/garbage_collector/_core.py Wraps garbage collection entrypoint with @traced for span creation.
services/storage/src/simcore_service_storage/dsm_cleaner.py Adds @traced to DSM cleaner periodic task.
services/clusters-keeper/src/simcore_service_clusters_keeper/modules/clusters_management_core.py Adds @traced to cluster heartbeat/termination/start/broken handling functions.
services/autoscaling/src/simcore_service_autoscaling/utils/tracing.py New helper module to store trace context in EC2 tags and create linked lifecycle spans.
services/autoscaling/src/simcore_service_autoscaling/modules/cluster_scaling/_warm_buffer_machines_pool_core.py Adds @traced spans around warm-buffer monitoring/termination workflows; modernizes type aliases to type ... =.
services/autoscaling/src/simcore_service_autoscaling/modules/cluster_scaling/_auto_scaling_core.py Adds @traced to key autoscaling steps and introduces per-instance lifecycle spans with launch linking.
packages/service-library/tests/fastapi/test_tracing.py Adds tests validating @traced behavior (async/sync/custom names/attributes+links/no-op warning).
packages/service-library/src/servicelib/tracing.py Implements the @traced decorator and tracing-config resolution logic.

Comment on lines +71 to +79
@contextmanager
def traced_instance_lifecycle(
operation_name: str,
*,
app: FastAPI,
ec2_instance: EC2InstanceData,
hostname: str | None = None,
**extra_attributes: str,
):
Comment on lines +90 to +92
# For root spans (no active parent), create a link back to the launch span
current_span = trace.get_current_span()
is_root_span = not current_span.is_recording()
Comment on lines +46 to +56
def get_trace_carrier_ec2_tags() -> EC2Tags:
"""Return EC2 tags containing the current trace context (traceparent).

Should be called during instance launch within an active span so that
the tag is set on the new EC2 instance.
Returns an empty dict if no active trace context.
"""
carrier = get_trace_carrier_from_current_context()
if carrier and (traceparent := carrier.get("traceparent")):
return {TRACEPARENT_EC2_TAG_KEY: TypeAdapter(AWSTagValue).validate_python(traceparent)}
return {}
set_and_clean_settings_env_vars: None,
tracing_settings_in: tuple[str, int | str, float],
faker: Faker,
) -> None:
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:autoscaling autoscaling service in simcore's stack a:clusters-keeper a:services-library issues on packages/service-libs a:static-webserver static-webserver service a:storage issue related to storage service a:webserver webserver's codebase. Assigning the area is particularly useful for bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants