[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72XVX6N09X3CZV0TY0SB113":3,"skill-same:01M72XVX6N09X3CZV0TY0SB113":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":28,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M72XVX6N09X3CZV0TY0SB113","python-observability",null,"Python observability patterns including structured logging, metrics, and distributed tracing. Use when adding logging, implementing metrics collection, setting up tracing, or debugging production systems.","steph-frtech\u002Fclaude-code-up","steph-frtech","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F198466323?v=4","01M72XD213FVQA2QXRGTJFKHE1","01M72XD227AANJ993SQTNZB1CK",1,"MIT","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fpython-development\u002Fskills\u002Fpython-observability\u002FSKILL.md",[],[],"2026-11-10 22:39:42",false,"---\nname: python-observability\ndescription: Python observability patterns including structured logging, metrics, and distributed tracing. Use when adding logging, implementing metrics collection, setting up tracing, or debugging production systems.\n---\n\n# Python Observability\n\nInstrument Python applications with structured logs, metrics, and traces. When something breaks in production, you need to answer \"what, where, and why\" without deploying new code.\n\n## When to Use This Skill\n\n- Adding structured logging to applications\n- Implementing metrics collection with Prometheus\n- Setting up distributed tracing across services\n- Propagating correlation IDs through request chains\n- Debugging production issues\n- Building observability dashboards\n\n## Core Concepts\n\n### 1. Structured Logging\n\nEmit logs as JSON with consistent fields for production environments. Machine-readable logs enable powerful queries and alerts. For local development, consider human-readable formats.\n\n### 2. The Four Golden Signals\n\nTrack latency, traffic, errors, and saturation for every service boundary.\n\n### 3. Correlation IDs\n\nThread a unique ID through all logs and spans for a single request, enabling end-to-end tracing.\n\n### 4. Bounded Cardinality\n\nKeep metric label values bounded. Unbounded labels (like user IDs) explode storage costs.\n\n## Quick Start\n\n```python\nimport structlog\n\nstructlog.configure(\n    processors=[\n        structlog.processors.TimeStamper(fmt=\"iso\"),\n        structlog.processors.JSONRenderer(),\n    ],\n)\n\nlogger = structlog.get_logger()\nlogger.info(\"Request processed\", user_id=\"123\", duration_ms=45)\n```\n\n## Fundamental Patterns\n\n### Pattern 1: Structured Logging with Structlog\n\nConfigure structlog for JSON output with consistent fields.\n\n```python\nimport logging\nimport structlog\n\ndef configure_logging(log_level: str = \"INFO\") -> None:\n    \"\"\"Configure structured logging for the application.\"\"\"\n    structlog.configure(\n        processors=[\n            structlog.contextvars.merge_contextvars,\n            structlog.processors.add_log_level,\n            structlog.processors.TimeStamper(fmt=\"iso\"),\n            structlog.processors.StackInfoRenderer(),\n            structlog.processors.format_exc_info,\n            structlog.processors.JSONRenderer(),\n        ],\n        wrapper_class=structlog.make_filtering_bound_logger(\n            getattr(logging, log_level.upper())\n        ),\n        context_class=dict,\n        logger_factory=structlog.PrintLoggerFactory(),\n        cache_logger_on_first_use=True,\n    )\n\n# Initialize at application startup\nconfigure_logging(\"INFO\")\nlogger = structlog.get_logger()\n```\n\n### Pattern 2: Consistent Log Fields\n\nEvery log entry should include standard fields for filtering and correlation.\n\n```python\nimport structlog\nfrom contextvars import ContextVar\n\n# Store correlation ID in context\ncorrelation_id: ContextVar[str] = ContextVar(\"correlation_id\", default=\"\")\n\nlogger = structlog.get_logger()\n\ndef process_request(request: Request) -> Response:\n    \"\"\"Process request with structured logging.\"\"\"\n    logger.info(\n        \"Request received\",\n        correlation_id=correlation_id.get(),\n        method=request.method,\n        path=request.path,\n        user_id=request.user_id,\n    )\n\n    try:\n        result = handle_request(request)\n        logger.info(\n            \"Request completed\",\n            correlation_id=correlation_id.get(),\n            status_code=200,\n            duration_ms=elapsed,\n        )\n        return result\n    except Exception as e:\n        logger.error(\n            \"Request failed\",\n            correlation_id=correlation_id.get(),\n            error_type=type(e).__name__,\n            error_message=str(e),\n        )\n        raise\n```\n\n### Pattern 3: Semantic Log Levels\n\nUse log levels consistently across the application.\n\n| Level | Purpose | Examples |\n|-------|---------|----------|\n| `DEBUG` | Development diagnostics | Variable values, internal state |\n| `INFO` | Request lifecycle, operations | Request start\u002Fend, job completion |\n| `WARNING` | Recoverable anomalies | Retry attempts, fallback used |\n| `ERROR` | Failures needing attention | Exceptions, service unavailable |\n\n```python\n# DEBUG: Detailed internal information\nlogger.debug(\"Cache lookup\", key=cache_key, hit=cache_hit)\n\n# INFO: Normal operational events\nlogger.info(\"Order created\", order_id=order.id, total=order.total)\n\n# WARNING: Abnormal but handled situations\nlogger.warning(\n    \"Rate limit approaching\",\n    current_rate=950,\n    limit=1000,\n    reset_seconds=30,\n)\n\n# ERROR: Failures requiring investigation\nlogger.error(\n    \"Payment processing failed\",\n    order_id=order.id,\n    error=str(e),\n    payment_provider=\"stripe\",\n)\n```\n\nNever log expected behavior at `ERROR`. A user entering a wrong password is `INFO`, not `ERROR`.\n\n### Pattern 4: Correlation ID Propagation\n\nGenerate a unique ID at ingress and thread it through all operations.\n\n```python\nfrom contextvars import ContextVar\nimport uuid\nimport structlog\n\ncorrelation_id: ContextVar[str] = ContextVar(\"correlation_id\", default=\"\")\n\ndef set_correlation_id(cid: str | None = None) -> str:\n    \"\"\"Set correlation ID for current context.\"\"\"\n    cid = cid or str(uuid.uuid4())\n    correlation_id.set(cid)\n    structlog.contextvars.bind_contextvars(correlation_id=cid)\n    return cid\n\n# FastAPI middleware example\nfrom fastapi import Request\n\nasync def correlation_middleware(request: Request, call_next):\n    \"\"\"Middleware to set and propagate correlation ID.\"\"\"\n    # Use incoming header or generate new\n    cid = request.headers.get(\"X-Correlation-ID\") or str(uuid.uuid4())\n    set_correlation_id(cid)\n\n    response = await call_next(request)\n    response.headers[\"X-Correlation-ID\"] = cid\n    return response\n```\n\nPropagate to outbound requests:\n\n```python\nimport httpx\n\nasync def call_downstream_service(endpoint: str, data: dict) -> dict:\n    \"\"\"Call downstream service with correlation ID.\"\"\"\n    async with httpx.AsyncClient() as client:\n        response = await client.post(\n            endpoint,\n            json=data,\n            headers={\"X-Correlation-ID\": correlation_id.get()},\n        )\n        return response.json()\n```\n\n## Advanced Patterns\n\n### Pattern 5: The Four Golden Signals with Prometheus\n\nTrack these metrics for every service boundary:\n\n```python\nfrom prometheus_client import Counter, Histogram, Gauge\n\n# Latency: How long requests take\nREQUEST_LATENCY = Histogram(\n    \"http_request_duration_seconds\",\n    \"Request latency in seconds\",\n    [\"method\", \"endpoint\", \"status\"],\n    buckets=[0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],\n)\n\n# Traffic: Request rate\nREQUEST_COUNT = Counter(\n    \"http_requests_total\",\n    \"Total HTTP requests\",\n    [\"method\", \"endpoint\", \"status\"],\n)\n\n# Errors: Error rate\nERROR_COUNT = Counter(\n    \"http_errors_total\",\n    \"Total HTTP errors\",\n    [\"method\", \"endpoint\", \"error_type\"],\n)\n\n# Saturation: Resource utilization\nDB_POOL_USAGE = Gauge(\n    \"db_connection_pool_used\",\n    \"Number of database connections in use\",\n)\n```\n\nInstrument your endpoints:\n\n```python\nimport time\nfrom functools import wraps\n\ndef track_request(func):\n    \"\"\"Decorator to track request metrics.\"\"\"\n    @wraps(func)\n    async def wrapper(request: Request, *args, **kwargs):\n        method = request.method\n        endpoint = request.url.path\n        start = time.perf_counter()\n\n        try:\n            response = await func(request, *args, **kwargs)\n            status = str(response.status_code)\n            return response\n        except Exception as e:\n            status = \"500\"\n            ERROR_COUNT.labels(\n                method=method,\n                endpoint=endpoint,\n                error_type=type(e).__name__,\n            ).inc()\n            raise\n        finally:\n            duration = time.perf_counter() - start\n            REQUEST_COUNT.labels(method=method, endpoint=endpoint, status=status).inc()\n            REQUEST_LATENCY.labels(method=method, endpoint=endpoint, status=status).observe(duration)\n\n    return wrapper\n```\n\n### Pattern 6: Bounded Cardinality\n\nAvoid labels with unbounded values to prevent metric explosion.\n\n```python\n# BAD: User ID has potentially millions of values\nREQUEST_COUNT.labels(method=\"GET\", user_id=user.id)  # Don't do this!\n\n# GOOD: Bounded values only\nREQUEST_COUNT.labels(method=\"GET\", endpoint=\"\u002Fusers\", status=\"200\")\n\n# If you need per-user metrics, use a different approach:\n# - Log the user_id and query logs\n# - Use a separate analytics system\n# - Bucket users by type\u002Ftier\nREQUEST_COUNT.labels(\n    method=\"GET\",\n    endpoint=\"\u002Fusers\",\n    user_tier=\"premium\",  # Bounded set of values\n)\n```\n\n### Pattern 7: Timed Operations with Context Manager\n\nCreate a reusable timing context manager for operations.\n\n```python\nfrom contextlib import contextmanager\nimport time\nimport structlog\n\nlogger = structlog.get_logger()\n\n@contextmanager\ndef timed_operation(name: str, **extra_fields):\n    \"\"\"Context manager for timing and logging operations.\"\"\"\n    start = time.perf_counter()\n    logger.debug(\"Operation started\", operation=name, **extra_fields)\n\n    try:\n        yield\n    except Exception as e:\n        elapsed_ms = (time.perf_counter() - start) * 1000\n        logger.error(\n            \"Operation failed\",\n            operation=name,\n            duration_ms=round(elapsed_ms, 2),\n            error=str(e),\n            **extra_fields,\n        )\n        raise\n    else:\n        elapsed_ms = (time.perf_counter() - start) * 1000\n        logger.info(\n            \"Operation completed\",\n            operation=name,\n            duration_ms=round(elapsed_ms, 2),\n            **extra_fields,\n        )\n\n# Usage\nwith timed_operation(\"fetch_user_orders\", user_id=user.id):\n    orders = await order_repository.get_by_user(user.id)\n```\n\n### Pattern 8: OpenTelemetry Tracing\n\nSet up distributed tracing with OpenTelemetry.\n\n**Note:** OpenTelemetry is actively evolving. Check the [official Python documentation](https:\u002F\u002Fopentelemetry.io\u002Fdocs\u002Flanguages\u002Fpython\u002F) for the latest API patterns and best practices.\n\n```python\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\nfrom opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter\n\ndef configure_tracing(service_name: str, otlp_endpoint: str) -> None:\n    \"\"\"Configure OpenTelemetry tracing.\"\"\"\n    provider = TracerProvider()\n    processor = BatchSpanProcessor(OTLPSpanExporter(endpoint=otlp_endpoint))\n    provider.add_span_processor(processor)\n    trace.set_tracer_provider(provider)\n\ntracer = trace.get_tracer(__name__)\n\nasync def process_order(order_id: str) -> Order:\n    \"\"\"Process order with tracing.\"\"\"\n    with tracer.start_as_current_span(\"process_order\") as span:\n        span.set_attribute(\"order.id\", order_id)\n\n        with tracer.start_as_current_span(\"validate_order\"):\n            validate_order(order_id)\n\n        with tracer.start_as_current_span(\"charge_payment\"):\n            charge_payment(order_id)\n\n        with tracer.start_as_current_span(\"send_confirmation\"):\n            send_confirmation(order_id)\n\n        return order\n```\n\n## Best Practices Summary\n\n1. **Use structured logging** - JSON logs with consistent fields\n2. **Propagate correlation IDs** - Thread through all requests and logs\n3. **Track the four golden signals** - Latency, traffic, errors, saturation\n4. **Bound label cardinality** - Never use unbounded values as metric labels\n5. **Log at appropriate levels** - Don't cry wolf with ERROR\n6. **Include context** - User ID, request ID, operation name in logs\n7. **Use context managers** - Consistent timing and error handling\n8. **Separate concerns** - Observability code shouldn't pollute business logic\n9. **Test your observability** - Verify logs and metrics in integration tests\n10. **Set up alerts** - Metrics are useless without alerting\n","# Python Observability\n\nInstrument Python applications with structured logs, metrics, and traces. When something breaks in production, you need to answer \"what, where, and why\" without deploying new code.\n\n## When to Use This Skill\n\n- Adding structured logging to applications\n- Implementing metrics collection with Prometheus\n- Setting up distributed tracing across services\n- Propagating correlation IDs through request chains\n- Debugging production issues\n- Building observability dashboards\n\n## Core Concepts\n\n### 1. Structured Logging\n\nEmit logs as JSON with consistent fields for production environments. Machine-readable logs enable powerful queries and alerts. For local development, consider human-readable formats.\n\n### 2. The Four Golden Signals\n\nTrack latency, traffic, errors, and saturation for every service boundary.\n\n### 3. Correlation IDs\n\nThread a unique ID through all logs and spans for a single request, enabling end-to-end tracing.\n\n### 4. Bounded Cardinality\n\nKeep metric label values bounded. Unbounded labels (like user IDs) explode storage costs.\n\n## Quick Start\n\n```python\nimport structlog\n\nstructlog.configure(\n    processors=[\n        structlog.processors.TimeStamper(fmt=\"iso\"),\n        structlog.processors.JSONRenderer(),\n    ],\n)\n\nlogger = structlog.get_logger()\nlogger.info(\"Request processed\", user_id=\"123\", duration_ms=45)\n```\n\n## Fundamental Patterns\n\n### Pattern 1: Structured Logging with Structlog\n\nConfigure structlog for JSON output with consistent fields.\n\n```python\nimport logging\nimport structlog\n\ndef configure_logging(log_level: str = \"INFO\") -> None:\n    \"\"\"Configure structured logging for the application.\"\"\"\n    structlog.configure(\n        processors=[\n            structlog.contextvars.merge_contextvars,\n            structlog.processors.add_log_level,\n            structlog.processors.TimeStamper(fmt=\"iso\"),\n            structlog.processors.StackInfoRenderer(),\n            structlog.processors.format_exc_info,\n            structlog.processors.JSONRenderer(),\n        ],\n        wrapper_class=structlog.make_filtering_bound_logger(\n            getattr(logging, log_level.upper())\n        ),\n        context_class=dict,\n        logger_factory=structlog.PrintLoggerFactory(),\n        cache_logger_on_first_use=True,\n    )\n\n# Initialize at application startup\nconfigure_logging(\"INFO\")\nlogger = structlog.get_logger()\n```\n\n### Pattern 2: Consistent Log Fields\n\nEvery log entry should include standard fields for filtering and correlation.\n\n```python\nimport structlog\nfrom contextvars import ContextVar\n\n# Store correlation ID in context\ncorrelation_id: ContextVar[str] = ContextVar(\"correlation_id\", default=\"\")\n\nlogger = structlog.get_logger()\n\ndef process_request(request: Request) -> Response:\n    \"\"\"Process request with structured logging.\"\"\"\n    logger.info(\n        \"Request received\",\n        correlation_id=correlation_id.get(),\n        method=request.method,\n        path=request.path,\n        user_id=request.user_id,\n    )\n\n    try:\n        result = handle_request(request)\n        logger.info(\n            \"Request completed\",\n            correlation_id=correlation_id.get(),\n            status_code=200,\n            duration_ms=elapsed,\n        )\n        return result\n    except Exception as e:\n        logger.error(\n            \"Request failed\",\n            correlation_id=correlation_id.get(),\n            error_type=type(e).__name__,\n            error_message=str(e),\n        )\n        raise\n```\n\n### Pattern 3: Semantic Log Levels\n\nUse log levels consistently across the application.\n\n| Level | Purpose | Examples |\n|-------|---------|----------|\n| `DEBUG` | Development diagnostics | Variable values, internal state |\n| `INFO` | Request lifecycle, operations | Request start\u002Fend, job completion |\n| `WARNING` | Recoverable anomalies | Retry attempts, fallback used |\n| `ERROR` | Failures needing attention | Exceptions, service unavailable |\n\n```python\n# DEBUG: Detailed internal information\nlogger.debug(\"Cache lookup\", key=cache_key, hit=cache_hit)\n\n# INFO: Normal operational events\nlogger.info(\"Order created\", order_id=order.id, total=order.total)\n\n# WARNING: Abnormal but handled situations\nlogger.warning(\n    \"Rate limit approaching\",\n    current_rate=950,\n    limit=1000,\n    reset_seconds=30,\n)\n\n# ERROR: Failures requiring investigation\nlogger.error(\n    \"Payment processing failed\",\n    order_id=order.id,\n    error=str(e),\n    payment_provider=\"stripe\",\n)\n```\n\nNever log expected behavior at `ERROR`. A user entering a wrong password is `INFO`, not `ERROR`.\n\n### Pattern 4: Correlation ID Propagation\n\nGenerate a unique ID at ingress and thread it through all operations.\n\n```python\nfrom contextvars import ContextVar\nimport uuid\nimport structlog\n\ncorrelation_id: ContextVar[str] = ContextVar(\"correlation_id\", default=\"\")\n\ndef set_correlation_id(cid: str | None = None) -> str:\n    \"\"\"Set correlation ID for current context.\"\"\"\n    cid = cid or str(uuid.uuid4())\n    correlation_id.set(cid)\n    structlog.contextvars.bind_contextvars(correlation_id=cid)\n    return cid\n\n# FastAPI middleware example\nfrom fastapi import Request\n\nasync def correlation_middleware(request: Request, call_next):\n    \"\"\"Middleware to set and propagate correlation ID.\"\"\"\n    # Use incoming header or generate new\n    cid = request.headers.get(\"X-Correlation-ID\") or str(uuid.uuid4())\n    set_correlation_id(cid)\n\n    response = await call_next(request)\n    response.headers[\"X-Correlation-ID\"] = cid\n    return response\n```\n\nPropagate to outbound requests:\n\n```python\nimport httpx\n\nasync def call_downstream_service(endpoint: str, data: dict) -> dict:\n    \"\"\"Call downstream service with correlation ID.\"\"\"\n    async with httpx.AsyncClient() as client:\n        response = await client.post(\n            endpoint,\n            json=data,\n            headers={\"X-Correlation-ID\": correlation_id.get()},\n        )\n        return response.json()\n```\n\n## Advanced Patterns\n\n### Pattern 5: The Four Golden Signals with Prometheus\n\nTrack these metrics for every service boundary:\n\n```python\nfrom prometheus_client import Counter, Histogram, Gauge\n\n# Latency: How long requests take\nREQUEST_LATENCY = Histogram(\n    \"http_request_duration_seconds\",\n    \"Request latency in seconds\",\n    [\"method\", \"endpoint\", \"status\"],\n    buckets=[0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],\n)\n\n# Traffic: Request rate\nREQUEST_COUNT = Counter(\n    \"http_requests_total\",\n    \"Total HTTP requests\",\n    [\"method\", \"endpoint\", \"status\"],\n)\n\n# Errors: Error rate\nERROR_COUNT = Counter(\n    \"http_errors_total\",\n    \"Total HTTP errors\",\n    [\"method\", \"endpoint\", \"error_type\"],\n)\n\n# Saturation: Resource utilization\nDB_POOL_USAGE = Gauge(\n    \"db_connection_pool_used\",\n    \"Number of database connections in use\",\n)\n```\n\nInstrument your endpoints:\n\n```python\nimport time\nfrom functools import wraps\n\ndef track_request(func):\n    \"\"\"Decorator to track request metrics.\"\"\"\n    @wraps(func)\n    async def wrapper(request: Request, *args, **kwargs):\n        method = request.method\n        endpoint = request.url.path\n        start = time.perf_counter()\n\n        try:\n            response = await func(request, *args, **kwargs)\n            status = str(response.status_code)\n            return response\n        except Exception as e:\n            status = \"500\"\n            ERROR_COUNT.labels(\n                method=method,\n                endpoint=endpoint,\n                error_type=type(e).__name__,\n            ).inc()\n            raise\n        finally:\n            duration = time.perf_counter() - start\n            REQUEST_COUNT.labels(method=method, endpoint=endpoint, status=status).inc()\n            REQUEST_LATENCY.labels(method=method, endpoint=endpoint, status=status).observe(duration)\n\n    return wrapper\n```\n\n### Pattern 6: Bounded Cardinality\n\nAvoid labels with unbounded values to prevent metric explosion.\n\n```python\n# BAD: User ID has potentially millions of values\nREQUEST_COUNT.labels(method=\"GET\", user_id=user.id)  # Don't do this!\n\n# GOOD: Bounded values only\nREQUEST_COUNT.labels(method=\"GET\", endpoint=\"\u002Fusers\", status=\"200\")\n\n# If you need per-user metrics, use a different approach:\n# - Log the user_id and query logs\n# - Use a separate analytics system\n# - Bucket users by type\u002Ftier\nREQUEST_COUNT.labels(\n    method=\"GET\",\n    endpoint=\"\u002Fusers\",\n    user_tier=\"premium\",  # Bounded set of values\n)\n```\n\n### Pattern 7: Timed Operations with Context Manager\n\nCreate a reusable timing context manager for operations.\n\n```python\nfrom contextlib import contextmanager\nimport time\nimport structlog\n\nlogger = structlog.get_logger()\n\n@contextmanager\ndef timed_operation(name: str, **extra_fields):\n    \"\"\"Context manager for timing and logging operations.\"\"\"\n    start = time.perf_counter()\n    logger.debug(\"Operation started\", operation=name, **extra_fields)\n\n    try:\n        yield\n    except Exception as e:\n        elapsed_ms = (time.perf_counter() - start) * 1000\n        logger.error(\n            \"Operation failed\",\n            operation=name,\n            duration_ms=round(elapsed_ms, 2),\n            error=str(e),\n            **extra_fields,\n        )\n        raise\n    else:\n        elapsed_ms = (time.perf_counter() - start) * 1000\n        logger.info(\n            \"Operation completed\",\n            operation=name,\n            duration_ms=round(elapsed_ms, 2),\n            **extra_fields,\n        )\n\n# Usage\nwith timed_operation(\"fetch_user_orders\", user_id=user.id):\n    orders = await order_repository.get_by_user(user.id)\n```\n\n### Pattern 8: OpenTelemetry Tracing\n\nSet up distributed tracing with OpenTelemetry.\n\n**Note:** OpenTelemetry is actively evolving. Check the [official Python documentation](https:\u002F\u002Fopentelemetry.io\u002Fdocs\u002Flanguages\u002Fpython\u002F) for the latest API patterns and best practices.\n\n```python\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\nfrom opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter\n\ndef configure_tracing(service_name: str, otlp_endpoint: str) -> None:\n    \"\"\"Configure OpenTelemetry tracing.\"\"\"\n    provider = TracerProvider()\n    processor = BatchSpanProcessor(OTLPSpanExporter(endpoint=otlp_endpoint))\n    provider.add_span_processor(processor)\n    trace.set_tracer_provider(provider)\n\ntracer = trace.get_tracer(__name__)\n\nasync def process_order(order_id: str) -> Order:\n    \"\"\"Process order with tracing.\"\"\"\n    with tracer.start_as_current_span(\"process_order\") as span:\n        span.set_attribute(\"order.id\", order_id)\n\n        with tracer.start_as_current_span(\"validate_order\"):\n            validate_order(order_id)\n\n        with tracer.start_as_current_span(\"charge_payment\"):\n            charge_payment(order_id)\n\n        with tracer.start_as_current_span(\"send_confirmation\"):\n            send_confirmation(order_id)\n\n        return order\n```\n\n## Best Practices Summary\n\n1. **Use structured logging** - JSON logs with consistent fields\n2. **Propagate correlation IDs** - Thread through all requests and logs\n3. **Track the four golden signals** - Latency, traffic, errors, saturation\n4. **Bound label cardinality** - Never use unbounded values as metric labels\n5. **Log at appropriate levels** - Don't cry wolf with ERROR\n6. **Include context** - User ID, request ID, operation name in logs\n7. **Use context managers** - Consistent timing and error handling\n8. **Separate concerns** - Observability code shouldn't pollute business logic\n9. **Test your observability** - Verify logs and metrics in integration tests\n10. **Set up alerts** - Metrics are useless without alerting\n",{"name":5,"description":7},"main","900bb95bbe72cdb94af6f5a620aa5081264b7b6d",".claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fpython-development\u002Fskills\u002Fpython-observability",0,"https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up#readme","https:\u002F\u002Fgithub.com\u002Fsteph-frtech","2026-05-16 00:03:30",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add steph-frtech\u002Fclaude-code-up --skill python-observability",{"tool":37,"command":38},"bunx","bunx skills add steph-frtech\u002Fclaude-code-up --skill python-observability",{"tool":40,"command":41},"pnpm","pnpm dlx skills add steph-frtech\u002Fclaude-code-up --skill python-observability","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fmarketplaces\u002Fwshobson\u002Fplugins\u002Fpython-development\u002Fskills\u002Fpython-observability\u002FSKILL.md",true,[],[46,53,60,67,74,81],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":18},"01M72Y1BY6X8TX3DS19Y04NEBQ","example","One-line summary of what this skill does","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002Fskills\u002Fexample\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":18},"01M72Y1A38EYR8S9P1MBYDAQTW","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__writing-plans\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":18},"01M72Y174QSV1B5NV1E4KWHQBR","using-git-worktrees","Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__using-git-worktrees\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M72Y14SQRHHMKG316HGB2CGK","test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__test-driven-development\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":18},"01M72Y127BCPRH3BRKPJC3Q3G2","systematic-debugging","Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__systematic-debugging\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":18},"01M72Y1090GJA6B67KPD60WPHH","subagent-driven-development","Use when executing implementation plans with independent tasks in the current session","https:\u002F\u002Fgithub.com\u002Fsteph-frtech\u002Fclaude-code-up\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fsuperpowers__subagent-driven-development\u002FSKILL.md",[],[]]