X-Ray Tracing Deployer
An AWS CloudOps agent skill that deploys AWS X-Ray distributed tracing
with correct production defaults. Emits a READY_TO_DEPLOY checklist
verifying every configuration item.
Quick navigation
| Need |
Section |
| What MUST be in the response |
"STRICT output contract" |
| Why the deployment order matters |
"Reasoning framework" |
| What to verify before deploying |
"Prerequisites" |
| The ordered deployment steps |
"Deployment procedure" |
| Common silent-failure pitfalls |
"NEVER" |
| Platform-specific defaults |
"Platform matrix" |
| 2024-2026 feature changes |
"Recent AWS features" |
| Deep daemon + sampling CLI |
references/daemon-and-sampling-guide.md |
| SDK instrumentation, OTel, full NEVER |
references/sdk-instrumentation-guide.md |
STRICT output contract
When this skill is invoked with an X-Ray tracing deployment request, the
agent MUST respond with the READY_TO_DEPLOY checklist defined in "Output
format" using the literal all-caps labels SERVICE:, VERDICT:,
CHECKLIST:, and VERIFICATION_COMMANDS:. Do NOT preface the checklist
with prose, headings, or disclaimers — emit the block as the first lines.
Required output structure
SERVICE: <application-name> — the application being traced.
VERDICT: READY_TO_DEPLOY OR VERDICT: PREREQUISITES_MISSING.
CHECKLIST: followed by indented lines with status markers
([✓], [✗], [OPTIONAL], [INPUT NEEDED]).
VERIFICATION_COMMANDS: followed by indented aws xray ... commands.
FORBIDDEN output patterns
- No prose preamble before
SERVICE: — first non-empty line MUST be
SERVICE:.
- No markdown variants of labels — write
VERDICT:, not **VERDICT:**,
### Verdict, or `VERDICT`.
- No swapping verdict tokens — exactly
READY_TO_DEPLOY or
PREREQUISITES_MISSING.
- No omitting
VERIFICATION_COMMANDS: — include even when
PREREQUISITES_MISSING.
- No extra sections after
VERIFICATION_COMMANDS: — the checklist
block is the entire response.
- No status marker drift — use only
[✓], [✗], [OPTIONAL],
[INPUT NEEDED].
Perfect example (copy the shape exactly)
SERVICE: payments-api-prod
VERDICT: READY_TO_DEPLOY
CHECKLIST:
[✓] Platform — ECS Fargate, cluster payments-prod
[✓] Daemon — aws-xray-daemon:4.1 sidecar (UDP 2000), task definition payments-xray-sidecar:3
[✓] SDK instrumentation — Python 3.11, aws-xray-sdk 2.13, middleware on Flask app
[✓] Sampling rule — default (reservoir 1/s, rate 5%), custom rule payments-checkout (reservoir 10/s, rate 100% on POST /checkout)
[✓] IAM execution role — payments-task-exec has xray:PutTraceSegments + xray:PutTelemetryRecords
[✓] IAM task role — payments-task has xray:PutTraceSegments + xray:PutTelemetryRecords + xray:GetSamplingRules + xray:GetSamplingTargets
[✓] Annotations — region, environment, customer_id (indexable)
[✓] Metadata — request_body_size, response_status (not indexable, for correlation)
[✓] Service map — generated from traces, 4 segments (ALB, payments-api, DynamoDB, SQS)
[✓] CloudWatch ServiceLens — integrated, service map visible in CloudWatch console
[OPTIONAL] X-Ray group — payments-checkout-group (filter expression annotation.region = "us-east-1")
VERIFICATION_COMMANDS:
aws xray get-sampling-rules
aws xray get-sampling-targets
aws ecs describe-task-definition --task-definition payments-xray-sidecar:3
aws ecs describe-services --cluster payments-prod --services payments-api-prod
aws xray get-service-graph --start-time 2026-08-10T00:00:00Z --end-time 2026-08-10T23:59:59Z
Reasoning framework (why the deployment order matters)
- IAM FIRST — without
xray:PutTraceSegments and
xray:PutTelemetryRecords on the application's runtime role, the SDK
generates traces but the daemon cannot upload them. Traces are silently
dropped. This is the #1 X-Ray deployment failure.
- Daemon (or OTel Collector) SECOND — the X-Ray SDK sends segment
documents to
127.0.0.1:2000 (UDP). If no daemon is listening, the
SDK silently drops the segment. No error, no log, no trace.
- SDK instrumentation THIRD — the SDK captures incoming requests
(HTTP framework middleware) and downstream calls (SDK patches). Without
SDK patches for downstream AWS calls, only the entry segment is
captured — no downstream dependencies appear in the service map.
- Sampling rules FOURTH — sampling rules control WHICH requests are
traced. Without a custom rule, the default rule (reservoir 1/s, rate
5%) is applied. For high-traffic endpoints, this is too low; for
critical endpoints (checkout, payment), set a custom rule with
100% sampling.
- Groups + insights FIFTH — groups are saved trace filters for
recurring queries. Insights auto-detect anomalies (latency spikes,
error rate increases). Apply AFTER traces are flowing.
- ServiceLens SIXTH — ServiceLens integrates X-Ray traces with
CloudWatch metrics and logs. It is enabled at the account level, no
per-service config needed.
Prerequisites (verify before deployment)
| Prerequisite |
Why it matters |
How to verify |
| IAM role with X-Ray permissions |
App runtime role needs xray:PutTraceSegments, xray:PutTelemetryRecords, xray:GetSamplingRules, xray:GetSamplingTargets. Without these, traces are silently dropped. |
aws iam list-attached-role-policies --role-name <role> + aws iam list-role-policies --role-name <role> |
| X-Ray daemon / OTel Collector |
Must be running and listening on UDP 2000 (X-Ray daemon) or gRPC 4317 (OTel Collector). Without it, the SDK drops segments. |
aws ecs describe-task-definition (ECS) / kubectl get daemonset (EKS) / systemctl status xray (EC2) |
| SDK installed + middleware enabled |
The SDK must be a dependency AND the middleware/patcher must be active. Installing the package without enabling the middleware captures nothing. |
Check requirements.txt / package.json / pom.xml for aws-xray-sdk or opentelemetry-* |
| AWS region with X-Ray endpoint |
X-Ray is regional. The daemon resolves the regional endpoint. Ensure the region supports X-Ray. |
aws xray get-sampling-rules --region <region> |
| VPC endpoints (if private) |
If the app runs in a private VPC without NAT Gateway, an X-Ray VPC interface endpoint is needed. |
aws ec2 describe-vpc-endpoints --filter Name=service-name,Values=com.amazonaws.<region>.xray |
| ECS task definition (if ECS) |
The daemon must be a sidecar container in the SAME task definition as the app. |
aws ecs describe-task-definition --task-definition <family> |
| EKS DaemonSet (if EKS) |
The daemon runs as a DaemonSet (one pod per node). The app pod's traffic to the daemon is via the node IP. |
kubectl get daemonset -n kube-system aws-xray-daemon |
| Lambda layer / Powertools (if Lambda) |
Lambda does NOT need the daemon — the runtime injects it. Use the X-Ray Lambda layer or Powertools for tracing. |
aws lambda get-function-configuration --function-name <name> --query 'Layers' |
| KMS key (if encryption) |
X-Ray encrypts at rest with AWS-owned KMS by default. CMK needs grant on the X-Ray service role. |
aws xray get-encryption-config |
Deployment procedure (apply in order)
Step 1: IAM permissions (application runtime role)
The application's runtime role (ECS task role, EC2 instance profile,
Lambda execution role, EKS pod IRSA role) needs X-Ray permissions.
aws iam attach-role-policy \
--role-name <app-role> \
--policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess
AWSXRayDaemonWriteAccess grants:
xray:PutTraceSegments
xray:PutTelemetryRecords
xray:GetSamplingRules
xray:GetSamplingTargets
xray:GetEncryptionConfig
It does NOT grant read access to traces (BatchGetTraces,
GetServiceGraph). Those are for operators / CI roles, not the app.
For custom inline policy:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetEncryptionConfig"
],
"Resource": "*"
}]
}
NEVER forget xray:GetSamplingRules and xray:GetSamplingTargets.
Without these, the SDK cannot fetch sampling rules and falls back to
local default sampling (1/s, fixed). The central sampling rules you
configure in the console are NEVER applied.
Step 2: X-Ray daemon deployment (by platform)
EC2 (systemd)
EC2 systemd install (daemon download, unit file, enable): Daemon and sampling guide.
Load on demand for EC2 deployments.
ECS Fargate (sidecar container)
ECS Fargate sidecar container definition (JSON) and localhost UDP 2000 rationale: Daemon and sampling guide.
Load on demand for ECS Fargate deployments.
ECS EC2 (daemon as a service, NOT sidecar)
On ECS EC2, you can run the daemon as a separate ECS service (one daemon
task per instance) or a sidecar. The daemon-as-a-service pattern saves
memory but requires the app to send traces to the HOST IP on port 2000
(NOT localhost). Set the AWS_XRAY_DAEMON_ADDRESS env var to
<host-ip>:2000.
EKS / Kubernetes (DaemonSet)
EKS DaemonSet manifest and node-IP downward-API injection: Daemon and sampling guide.
Load on demand for EKS deployments.
Lambda (built-in — no daemon needed)
Lambda enable-tracing and Powertools layer CLI: Daemon and sampling guide.
Load on demand for Lambda deployments.
Step 3: SDK instrumentation (by language)
Full code examples in references/sdk-instrumentation-guide.md.
| Language |
Package |
Middleware |
| Python |
aws-xray-sdk |
XRayMiddleware(app) for Flask/Django, @xray_recorder.capture() for functions |
| Node.js |
aws-xray-sdk-core |
aws-xray-sdk.express.openSegment(<name>) for Express, AWSXRay.captureAWS() for AWS SDK |
| Java |
aws-xray-recorder-sdk-core |
@XRayEnabled on JAX-RS resources, AWSXRay.beginSegment() for custom |
| Go |
github.com/aws/aws-xray-sdk-go |
xray.Handler(nil, http.HandlerFunc(handler)) for HTTP |
| .NET |
AWSXRayRecorder |
app.UseXRay("<name>") for ASP.NET Core |
Critical SDK patterns:
- Patch AWS SDK — without
AWSXRay.captureAWS(AWS) (Node.js) or
aws_xray_sdk.core.patch_all() (Python), downstream AWS calls do NOT
generate subsegments. The service map shows only the entry point.
- Patch HTTP clients — patch
requests (Python), http/https
(Node.js) to trace outbound HTTP calls to non-AWS APIs.
- Annotations vs metadata — annotations are indexable (use for
customer_id, region, environment). Metadata is NOT indexable
(use for request/response bodies, debug info).
Step 4: Sampling rules
# Default rule (always present, applied to all services without a custom match)
aws xray create-sampling-rule --cli-input-json '{
"SamplingRule": {
"RuleName": "Default",
"RuleARN": "",
"ResourceARN": "*",
"Priority": 10000,
"FixedRate": 0.05,
"ReservoirSize": 1,
"ServiceName": "*",
"ServiceType": "*",
"Host": "*",
"HTTPMethod": "*",
"URLPath": "*",
"Version": 1,
"Attributes": {}
}
}'
# Custom rule — 100% sampling for checkout endpoint
aws xray create-sampling-rule --cli-input-json '{
"SamplingRule": {
"RuleName": "payments-checkout-100",
"ResourceARN": "*",
"Priority": 100,
"FixedRate": 1.0,
"ReservoirSize": 10,
"ServiceName": "payments-api",
"ServiceType": "*",
"Host": "*",
"HTTPMethod": "POST",
"URLPath": "/checkout/*",
"Version": 1,
"Attributes": {}
}
}'
Sampling rule semantics:
- Priority — lower number = higher priority. Rules are evaluated in
priority order. The FIRST match wins.
- ReservoirSize — guaranteed traces per second BEFORE the rate
applies. The reservoir ensures at least N traces/s even at low traffic.
- FixedRate — fraction of requests ABOVE the reservoir to sample.
1.0 = 100%, 0.05 = 5%.
- Matching — a rule matches if ALL of
ServiceName, ServiceType,
Host, HTTPMethod, URLPath, and Attributes match. * is
wildcard.
NEVER set FixedRate=1.0 on the Default rule for a high-traffic service.
This generates massive trace volume, X-Ray costs scale with trace count,
and the service map becomes noisy. Use a custom rule scoped to specific
endpoints.
Step 5: Annotations and metadata
from aws_xray_sdk.core import xray_recorder
# Annotation — indexable, use for filtering in X-Ray console
xray_recorder.put_annotation("customer_id", "cust-12345")
xray_recorder.put_annotation("region", "us-east-1")
# Metadata — NOT indexable, for debug context
xray_recorder.put_metadata("request_body_size", 1024)
xray_recorder.put_metadata("feature_flags", {"new_checkout": True})
Annotations are indexed and searchable in the X-Ray console. Metadata
is visible on individual traces but NOT searchable. Use annotations for
fields you will filter on; use metadata for everything else.
Step 6: Groups and insights
# Group — saved filter expression
aws xray create-group \
--group-name "payments-checkout-group" \
--filter-expression 'annotation.region = "us-east-1" AND service("payments-api") { fault = true }'
# Insights — auto-detect anomalies (enabled by default, no config needed)
aws xray get-insight --insight-id <id>
Groups are saved filter expressions for recurring queries. Insights
auto-detect latency spikes, error rate increases, and anomalous behavior.
Insights are enabled by default — no config needed.
Step 7: CloudWatch ServiceLens
ServiceLens integrates X-Ray traces with CloudWatch metrics and logs. It
is enabled at the account level — no per-service config needed. To
verify:
aws cloudwatch describe-alarms-for-metric \
--namespace AWS/XRay \
--metric-name FaultRate
The ServiceLens service map is visible in the CloudWatch console under
"ServiceLens" > "Service Map".
Step 8: Verification
aws xray get-sampling-rules
aws xray get-sampling-targets
aws xray get-service-graph --start-time <ISO> --end-time <ISO>
aws xray get-trace-summaries --start-time <ISO> --end-time <ISO>
aws xray get-groups
aws xray get-insight-summaries --start-time <ISO> --end-time <ISO>
Latest X-Ray features (2024-2026)
2024-2026 feature delta (Powertools v2, ADOT Collector, attribute-based sampling, Insights anomaly detection, cross-account ServiceLens, CMK, daemon 4.x maintenance mode, W3C): Advanced patterns.
Load on demand when choosing components.
Platform matrix
| Platform |
Daemon |
SDK address |
IAM role |
Notes |
| EC2 |
systemd service |
127.0.0.1:2000 |
Instance profile |
Daemon runs as a background process |
| ECS Fargate |
Sidecar container |
127.0.0.1:2000 |
Task role |
Same task definition (awsvpc shared network) |
| ECS EC2 |
Sidecar or daemon-service |
127.0.0.1:2000 or <host-ip>:2000 |
Task role |
Daemon-service saves memory; sidecar is simpler |
| EKS |
DaemonSet |
<node-ip>:2000 (downward API) |
Pod IRSA role |
DaemonSet = one daemon per node |
| Lambda |
Built-in (no daemon) |
N/A |
Execution role |
Enable TracingConfig Mode=Active |
| App Runner |
N/A (managed) |
N/A |
Instance role |
Enable observability config with Vendor=AWSXRay |
| Elastic Beanstalk |
Instance or sidecar |
127.0.0.1:2000 |
Instance profile |
EB config has an X-Ray option |
NEVER (top 5 — full list of 14 in references)
- NEVER deploy the X-Ray SDK without
xray:GetSamplingRules and
xray:GetSamplingTargets on the application's runtime role. The SDK
fetches central sampling rules from the X-Ray API. Without these
permissions, the SDK falls back to local default (1/s, fixed) and the
rules you configure in the console are NEVER applied. #1 silent-failure.
- NEVER run the X-Ray daemon / OTel Collector without
xray:PutTraceSegments and xray:PutTelemetryRecords. The SDK
generates segments and sends them to the daemon, but the daemon
uploads them. Without upload permissions, traces are silently dropped.
- NEVER set
FixedRate=1.0 on the Default sampling rule for high-traffic
services. This generates massive trace volume. X-Ray charges per trace
ingested. Use a custom rule scoped to specific endpoints.
- NEVER forget to patch the AWS SDK (
AWSXRay.captureAWS() /
aws_xray_sdk.core.patch_all()). Without the patch, downstream AWS
calls (DynamoDB, S3, SQS) do NOT generate subsegments. The service map
shows only the entry point — no dependencies.
- NEVER deploy the daemon as a separate ECS service on Fargate and point
the app to it via DNS. Fargate tasks cannot reach each other on
localhost. The daemon MUST be a sidecar in the same task definition.
Expert heuristic — choosing X-Ray SDK vs ADOT, sampling, and annotations
SDK-vs-ADOT choice, reservoir/rate tuning, annotation discipline, trace-context propagation, and cost control: Advanced patterns.
Load on demand when making design decisions.
Pre-flight safety checks (run before any deployment CLI)
- Confirm IAM role has all 5 X-Ray actions (PutTraceSegments,
PutTelemetryRecords, GetSamplingRules, GetSamplingTargets,
GetEncryptionConfig). Use
AWSXRayDaemonWriteAccess managed policy.
- Confirm daemon / OTel Collector is running and listening on UDP
2000 (X-Ray) or gRPC 4317 (OTel).
- Confirm SDK package is installed and the middleware/patcher is
active in the code.
- Confirm AWS SDK is patched for downstream call tracing.
- Confirm trace context propagation across all service boundaries.
- Confirm sampling rules (check the Default rule and any custom
rules).
- Confirm X-Ray encryption config (AWS-owned key vs CMK).
- For existing services, capture current sampling config for rollback.
Full CLI sequences for all checks in references/daemon-and-sampling-guide.md.
Output format — MANDATORY literal labels
When invoked with a tracing deployment request, your ENTIRE response MUST
be the checklist block below. The labels are case-sensitive all-caps
keywords. Do NOT write a preamble. Start with SERVICE: and stop after
the VERIFICATION_COMMANDS: block.
SERVICE: <name>
VERDICT: READY_TO_DEPLOY | PREREQUISITES_MISSING
CHECKLIST:
[✓] Platform — <ec2|ecs|eks|lambda|app-runner>, <cluster/function/detail>
[✓] Daemon — <daemon-image:version> <deployment-mode> (UDP 2000)
[✓] SDK instrumentation — <language> <version>, <package> <version>, <middleware>
[✓] Sampling rule — default (reservoir <n>/s, rate <p>%), custom rule <name> (reservoir <n>/s, rate <p>% on <match>)
[✓] IAM role — <role-name> has xray:PutTraceSegments + PutTelemetryRecords + GetSamplingRules + GetSamplingTargets
[✓] Annotations — <indexable fields>
[✓] Metadata — <debug fields>
[✓] Service map — generated from traces, <segment-count> segments
[✓] CloudWatch ServiceLens — integrated
[OPTIONAL] X-Ray group — <group-name> (filter expression <expr>)
VERIFICATION_COMMANDS:
aws xray get-sampling-rules
aws xray get-sampling-targets
aws xray get-service-graph --start-time <ISO> --end-time <ISO>
aws ecs describe-task-definition --task-definition <family>
Status marker semantics:
[✓] — applied and verified.
[✗] — NOT applied or misconfigured. Cite the gap.
[OPTIONAL] — recommended but not required.
[INPUT NEEDED] — prerequisite value missing; operator must provide.
PREREQUISITES_MISSING verdict: if any REQUIRED prerequisite is missing
(IAM permissions, daemon / Collector not running, SDK not instrumented,
sampling rules not configured), the verdict is PREREQUISITES_MISSING.
References (load on demand)
- Advanced patterns — 2024-2026 feature delta, SDK-vs-ADOT heuristics, edge-case catalog
- Daemon and sampling guide — per-platform daemon deployment blocks (EC2, ECS Fargate, EKS, Lambda) plus the full daemon/sampling CLI sequence
- SDK instrumentation guide — language-by-language instrumentation and AWS SDK patching
Domain
AWS CloudOps / X-Ray Distributed Tracing Observability Provisioning.
Edge-case handling
Edge-case catalog (cross-account, SQS/EventBridge propagation, ECS EC2 host-IP, EKS limits, Lambda cold start, OTel migration, high-cardinality annotations, CMK grants): Advanced patterns.
Load on demand when deployment hits a corner case.
AWS documentation
References
references/daemon-and-sampling-guide.md — full copy-pasteable CLI
command sequence for daemon deployment (EC2, ECS, EKS, Lambda),
sampling rule creation (default + custom), IAM role setup, group
creation, and Terraform / CloudFormation equivalents.
references/sdk-instrumentation-guide.md — deep reference on SDK
instrumentation (Python, Node.js, Java, Go, .NET), AWS SDK patching,
annotation vs metadata, trace context propagation, OpenTelemetry / ADOT
migration, full NEVER list, edge-case handling, and pre-flight safety
CLI.
1---2name: xray-tracing-deployer3description: 'Deploys AWS X-Ray distributed tracing with production-grade configuration: X-Ray daemon deployment (EC2 systemd, ECS sidecar, EKS DaemonSet, Lambda built-in), SDK instrumentation (Java, Python, Node.js, Go, .NET) with annotations and metadata, sampling rules (default reservoir + rate vs custom rules with URL / method / service-name predicates), service map generation, trace query and retrieval, groups and insights, CloudWatch ServiceLens integration, IAM permissions (PutTraceSegments, GetSamplingRules), and latest features (Lambda Powertools tracing, OpenTelemetry / ADOT Collector support, W3C trace context). Emits a READY_TO_DEPLOY checklist with every configuration item verified. Use when enabling X-Ray on a new application, adding tracing to ECS / EKS / Lambda, validating a sampling configuration, or generating daemon deployment CLI and IaC templates. Triggers: X-Ray, distributed tracing, X-Ray daemon, sampling rules, service map, X-Ray SDK, OpenTelemetry, ADOT, Lambda Powertools, CloudWatch ServiceLens.'4license: Apache-2.05compatibility: 'Requires an LLM agent runtime (Claude Code, Cursor, Windsurf, Codex, Gemini). For live deployment: AWS CLI v2 with xray, ec2, ecs, eks, lambda, iam, logs, and servicediscovery access. Works with Terraform aws_xray_* resources, CloudFormation AWS::XRay::* resources, and the AWS Distro for OpenTelemetry (ADOT) Collector.'6metadata:7 source: https://skillmd.com/skills/jhkchan/xray-tracing-deployer8 domain: aws-cloudops9 complexity: high10 requires_llm: 'true'11 phase: '1'12 supports_pipeline: 'true'13 entry_point: 'false'14 family: Management15 task_type: deploy16 skill_class: capability17 lifecycle_status: active18 verdict_shape: READY_TO_DEPLOY | PREREQUISITES_MISSING19 version: 0.1.020 author: Jacky Chan — AWS Community Builder21 tags: aws, xray, distributed-tracing, cloudops, deploy, observability, sampling-rules, opentelemetry22 dependencies: aws-orchestrator23 keywords: aws, xray, x-ray, distributed-tracing, cloudops, deploy, provisioning, observability, daemon, sampling-rules, service-map, opentelemetry, adot, servicelens24 when_to_use: Invoke when the user wants to enable X-Ray distributed tracing on a new application, add the X-Ray daemon to ECS / EKS / EC2 / Lambda, create or validate custom sampling rules, instrument an SDK (Java, Python, Node.js, Go, .NET), set up CloudWatch ServiceLens, or migrate from X-Ray SDK to OpenTelemetry / ADOT. Do NOT invoke for CloudWatch Logs metrics alone (use cloudwatch-alarm-auditor), for application performance monitoring without tracing (use cloudwatch-application-signals-deployer), or for pure log aggregation.25---2627# X-Ray Tracing Deployer2829An AWS CloudOps agent skill that deploys AWS X-Ray distributed tracing30with correct production defaults. Emits a READY_TO_DEPLOY checklist31verifying every configuration item.3233## Quick navigation3435| Need | Section |36|---|---|37| What MUST be in the response | "STRICT output contract" |38| Why the deployment order matters | "Reasoning framework" |39| What to verify before deploying | "Prerequisites" |40| The ordered deployment steps | "Deployment procedure" |41| Common silent-failure pitfalls | "NEVER" |42| Platform-specific defaults | "Platform matrix" |43| 2024-2026 feature changes | "Recent AWS features" |44| Deep daemon + sampling CLI | `references/daemon-and-sampling-guide.md` |45| SDK instrumentation, OTel, full NEVER | `references/sdk-instrumentation-guide.md` |4647## STRICT output contract4849When this skill is invoked with an X-Ray tracing deployment request, the50agent MUST respond with the READY_TO_DEPLOY checklist defined in "Output51format" using the literal all-caps labels `SERVICE:`, `VERDICT:`,52`CHECKLIST:`, and `VERIFICATION_COMMANDS:`. Do NOT preface the checklist53with prose, headings, or disclaimers — emit the block as the first lines.5455### Required output structure56571. `SERVICE: <application-name>` — the application being traced.582. `VERDICT: READY_TO_DEPLOY` OR `VERDICT: PREREQUISITES_MISSING`.593. `CHECKLIST:` followed by indented lines with status markers60 (`[✓]`, `[✗]`, `[OPTIONAL]`, `[INPUT NEEDED]`).614. `VERIFICATION_COMMANDS:` followed by indented `aws xray ...` commands.6263### FORBIDDEN output patterns6465- **No prose preamble before `SERVICE:`** — first non-empty line MUST be66 `SERVICE:`.67- **No markdown variants of labels** — write `VERDICT:`, not `**VERDICT:**`,68 `### Verdict`, or `` `VERDICT` ``.69- **No swapping verdict tokens** — exactly `READY_TO_DEPLOY` or70 `PREREQUISITES_MISSING`.71- **No omitting `VERIFICATION_COMMANDS:`** — include even when72 PREREQUISITES_MISSING.73- **No extra sections after `VERIFICATION_COMMANDS:`** — the checklist74 block is the entire response.75- **No status marker drift** — use only `[✓]`, `[✗]`, `[OPTIONAL]`,76 `[INPUT NEEDED]`.7778### Perfect example (copy the shape exactly)7980```text81SERVICE: payments-api-prod82VERDICT: READY_TO_DEPLOY83CHECKLIST:84 [✓] Platform — ECS Fargate, cluster payments-prod85 [✓] Daemon — aws-xray-daemon:4.1 sidecar (UDP 2000), task definition payments-xray-sidecar:386 [✓] SDK instrumentation — Python 3.11, aws-xray-sdk 2.13, middleware on Flask app87 [✓] Sampling rule — default (reservoir 1/s, rate 5%), custom rule payments-checkout (reservoir 10/s, rate 100% on POST /checkout)88 [✓] IAM execution role — payments-task-exec has xray:PutTraceSegments + xray:PutTelemetryRecords89 [✓] IAM task role — payments-task has xray:PutTraceSegments + xray:PutTelemetryRecords + xray:GetSamplingRules + xray:GetSamplingTargets90 [✓] Annotations — region, environment, customer_id (indexable)91 [✓] Metadata — request_body_size, response_status (not indexable, for correlation)92 [✓] Service map — generated from traces, 4 segments (ALB, payments-api, DynamoDB, SQS)93 [✓] CloudWatch ServiceLens — integrated, service map visible in CloudWatch console94 [OPTIONAL] X-Ray group — payments-checkout-group (filter expression annotation.region = "us-east-1")95VERIFICATION_COMMANDS:96 aws xray get-sampling-rules97 aws xray get-sampling-targets98 aws ecs describe-task-definition --task-definition payments-xray-sidecar:399 aws ecs describe-services --cluster payments-prod --services payments-api-prod100 aws xray get-service-graph --start-time 2026-08-10T00:00:00Z --end-time 2026-08-10T23:59:59Z101```102103## Reasoning framework (why the deployment order matters)1041051. **IAM FIRST** — without `xray:PutTraceSegments` and106 `xray:PutTelemetryRecords` on the application's runtime role, the SDK107 generates traces but the daemon cannot upload them. Traces are silently108 dropped. This is the #1 X-Ray deployment failure.1092. **Daemon (or OTel Collector) SECOND** — the X-Ray SDK sends segment110 documents to `127.0.0.1:2000` (UDP). If no daemon is listening, the111 SDK silently drops the segment. No error, no log, no trace.1123. **SDK instrumentation THIRD** — the SDK captures incoming requests113 (HTTP framework middleware) and downstream calls (SDK patches). Without114 SDK patches for downstream AWS calls, only the entry segment is115 captured — no downstream dependencies appear in the service map.1164. **Sampling rules FOURTH** — sampling rules control WHICH requests are117 traced. Without a custom rule, the default rule (reservoir 1/s, rate118 5%) is applied. For high-traffic endpoints, this is too low; for119 critical endpoints (checkout, payment), set a custom rule with120 100% sampling.1215. **Groups + insights FIFTH** — groups are saved trace filters for122 recurring queries. Insights auto-detect anomalies (latency spikes,123 error rate increases). Apply AFTER traces are flowing.1246. **ServiceLens SIXTH** — ServiceLens integrates X-Ray traces with125 CloudWatch metrics and logs. It is enabled at the account level, no126 per-service config needed.127128## Prerequisites (verify before deployment)129130| Prerequisite | Why it matters | How to verify |131|---|---|---|132| **IAM role with X-Ray permissions** | App runtime role needs `xray:PutTraceSegments`, `xray:PutTelemetryRecords`, `xray:GetSamplingRules`, `xray:GetSamplingTargets`. Without these, traces are silently dropped. | `aws iam list-attached-role-policies --role-name <role>` + `aws iam list-role-policies --role-name <role>` |133| **X-Ray daemon / OTel Collector** | Must be running and listening on UDP 2000 (X-Ray daemon) or gRPC 4317 (OTel Collector). Without it, the SDK drops segments. | `aws ecs describe-task-definition` (ECS) / `kubectl get daemonset` (EKS) / `systemctl status xray` (EC2) |134| **SDK installed + middleware enabled** | The SDK must be a dependency AND the middleware/patcher must be active. Installing the package without enabling the middleware captures nothing. | Check `requirements.txt` / `package.json` / `pom.xml` for `aws-xray-sdk` or `opentelemetry-*` |135| **AWS region with X-Ray endpoint** | X-Ray is regional. The daemon resolves the regional endpoint. Ensure the region supports X-Ray. | `aws xray get-sampling-rules --region <region>` |136| **VPC endpoints (if private)** | If the app runs in a private VPC without NAT Gateway, an X-Ray VPC interface endpoint is needed. | `aws ec2 describe-vpc-endpoints --filter Name=service-name,Values=com.amazonaws.<region>.xray` |137| **ECS task definition (if ECS)** | The daemon must be a sidecar container in the SAME task definition as the app. | `aws ecs describe-task-definition --task-definition <family>` |138| **EKS DaemonSet (if EKS)** | The daemon runs as a DaemonSet (one pod per node). The app pod's traffic to the daemon is via the node IP. | `kubectl get daemonset -n kube-system aws-xray-daemon` |139| **Lambda layer / Powertools (if Lambda)** | Lambda does NOT need the daemon — the runtime injects it. Use the X-Ray Lambda layer or Powertools for tracing. | `aws lambda get-function-configuration --function-name <name> --query 'Layers'` |140| **KMS key (if encryption)** | X-Ray encrypts at rest with AWS-owned KMS by default. CMK needs grant on the X-Ray service role. | `aws xray get-encryption-config` |141142## Deployment procedure (apply in order)143144### Step 1: IAM permissions (application runtime role)145146The application's runtime role (ECS task role, EC2 instance profile,147Lambda execution role, EKS pod IRSA role) needs X-Ray permissions.148149```bash150aws iam attach-role-policy \151 --role-name <app-role> \152 --policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess153```154155`AWSXRayDaemonWriteAccess` grants:156- `xray:PutTraceSegments`157- `xray:PutTelemetryRecords`158- `xray:GetSamplingRules`159- `xray:GetSamplingTargets`160- `xray:GetEncryptionConfig`161162It does NOT grant read access to traces (`BatchGetTraces`,163`GetServiceGraph`). Those are for operators / CI roles, not the app.164165For custom inline policy:166167```json168{169 "Version": "2012-10-17",170 "Statement": [{171 "Effect": "Allow",172 "Action": [173 "xray:PutTraceSegments",174 "xray:PutTelemetryRecords",175 "xray:GetSamplingRules",176 "xray:GetSamplingTargets",177 "xray:GetEncryptionConfig"178 ],179 "Resource": "*"180 }]181}182```183184**NEVER forget `xray:GetSamplingRules` and `xray:GetSamplingTargets`.**185Without these, the SDK cannot fetch sampling rules and falls back to186local default sampling (1/s, fixed). The central sampling rules you187configure in the console are NEVER applied.188189### Step 2: X-Ray daemon deployment (by platform)190191#### EC2 (systemd)192193EC2 systemd install (daemon download, unit file, enable): [Daemon and sampling guide](references/daemon-and-sampling-guide.md).194Load on demand for EC2 deployments.195196#### ECS Fargate (sidecar container)197198ECS Fargate sidecar container definition (JSON) and localhost UDP 2000 rationale: [Daemon and sampling guide](references/daemon-and-sampling-guide.md).199Load on demand for ECS Fargate deployments.200201#### ECS EC2 (daemon as a service, NOT sidecar)202203On ECS EC2, you can run the daemon as a separate ECS service (one daemon204task per instance) or a sidecar. The daemon-as-a-service pattern saves205memory but requires the app to send traces to the HOST IP on port 2000206(NOT localhost). Set the `AWS_XRAY_DAEMON_ADDRESS` env var to207`<host-ip>:2000`.208209#### EKS / Kubernetes (DaemonSet)210211EKS DaemonSet manifest and node-IP downward-API injection: [Daemon and sampling guide](references/daemon-and-sampling-guide.md).212Load on demand for EKS deployments.213214#### Lambda (built-in — no daemon needed)215216Lambda enable-tracing and Powertools layer CLI: [Daemon and sampling guide](references/daemon-and-sampling-guide.md).217Load on demand for Lambda deployments.218219### Step 3: SDK instrumentation (by language)220221Full code examples in `references/sdk-instrumentation-guide.md`.222223| Language | Package | Middleware |224|---|---|---|225| **Python** | `aws-xray-sdk` | `XRayMiddleware(app)` for Flask/Django, `@xray_recorder.capture()` for functions |226| **Node.js** | `aws-xray-sdk-core` | `aws-xray-sdk.express.openSegment(<name>)` for Express, `AWSXRay.captureAWS()` for AWS SDK |227| **Java** | `aws-xray-recorder-sdk-core` | `@XRayEnabled` on JAX-RS resources, `AWSXRay.beginSegment()` for custom |228| **Go** | `github.com/aws/aws-xray-sdk-go` | `xray.Handler(nil, http.HandlerFunc(handler))` for HTTP |229| **.NET** | `AWSXRayRecorder` | `app.UseXRay("<name>")` for ASP.NET Core |230231**Critical SDK patterns:**2322331. **Patch AWS SDK** — without `AWSXRay.captureAWS(AWS)` (Node.js) or234 `aws_xray_sdk.core.patch_all()` (Python), downstream AWS calls do NOT235 generate subsegments. The service map shows only the entry point.2362. **Patch HTTP clients** — patch `requests` (Python), `http`/`https`237 (Node.js) to trace outbound HTTP calls to non-AWS APIs.2383. **Annotations vs metadata** — annotations are indexable (use for239 `customer_id`, `region`, `environment`). Metadata is NOT indexable240 (use for request/response bodies, debug info).241242### Step 4: Sampling rules243244```bash245# Default rule (always present, applied to all services without a custom match)246aws xray create-sampling-rule --cli-input-json '{247 "SamplingRule": {248 "RuleName": "Default",249 "RuleARN": "",250 "ResourceARN": "*",251 "Priority": 10000,252 "FixedRate": 0.05,253 "ReservoirSize": 1,254 "ServiceName": "*",255 "ServiceType": "*",256 "Host": "*",257 "HTTPMethod": "*",258 "URLPath": "*",259 "Version": 1,260 "Attributes": {}261 }262}'263264# Custom rule — 100% sampling for checkout endpoint265aws xray create-sampling-rule --cli-input-json '{266 "SamplingRule": {267 "RuleName": "payments-checkout-100",268 "ResourceARN": "*",269 "Priority": 100,270 "FixedRate": 1.0,271 "ReservoirSize": 10,272 "ServiceName": "payments-api",273 "ServiceType": "*",274 "Host": "*",275 "HTTPMethod": "POST",276 "URLPath": "/checkout/*",277 "Version": 1,278 "Attributes": {}279 }280}'281```282283**Sampling rule semantics:**284- **Priority** — lower number = higher priority. Rules are evaluated in285 priority order. The FIRST match wins.286- **ReservoirSize** — guaranteed traces per second BEFORE the rate287 applies. The reservoir ensures at least N traces/s even at low traffic.288- **FixedRate** — fraction of requests ABOVE the reservoir to sample.289 `1.0` = 100%, `0.05` = 5%.290- **Matching** — a rule matches if ALL of `ServiceName`, `ServiceType`,291 `Host`, `HTTPMethod`, `URLPath`, and `Attributes` match. `*` is292 wildcard.293294**NEVER set FixedRate=1.0 on the Default rule for a high-traffic service.**295This generates massive trace volume, X-Ray costs scale with trace count,296and the service map becomes noisy. Use a custom rule scoped to specific297endpoints.298299### Step 5: Annotations and metadata300301```python302from aws_xray_sdk.core import xray_recorder303304# Annotation — indexable, use for filtering in X-Ray console305xray_recorder.put_annotation("customer_id", "cust-12345")306xray_recorder.put_annotation("region", "us-east-1")307308# Metadata — NOT indexable, for debug context309xray_recorder.put_metadata("request_body_size", 1024)310xray_recorder.put_metadata("feature_flags", {"new_checkout": True})311```312313Annotations are indexed and searchable in the X-Ray console. Metadata314is visible on individual traces but NOT searchable. Use annotations for315fields you will filter on; use metadata for everything else.316317### Step 6: Groups and insights318319```bash320# Group — saved filter expression321aws xray create-group \322 --group-name "payments-checkout-group" \323 --filter-expression 'annotation.region = "us-east-1" AND service("payments-api") { fault = true }'324325# Insights — auto-detect anomalies (enabled by default, no config needed)326aws xray get-insight --insight-id <id>327```328329Groups are saved filter expressions for recurring queries. Insights330auto-detect latency spikes, error rate increases, and anomalous behavior.331Insights are enabled by default — no config needed.332333### Step 7: CloudWatch ServiceLens334335ServiceLens integrates X-Ray traces with CloudWatch metrics and logs. It336is enabled at the account level — no per-service config needed. To337verify:338339```bash340aws cloudwatch describe-alarms-for-metric \341 --namespace AWS/XRay \342 --metric-name FaultRate343```344345The ServiceLens service map is visible in the CloudWatch console under346"ServiceLens" > "Service Map".347348### Step 8: Verification349350```bash351aws xray get-sampling-rules352aws xray get-sampling-targets353aws xray get-service-graph --start-time <ISO> --end-time <ISO>354aws xray get-trace-summaries --start-time <ISO> --end-time <ISO>355aws xray get-groups356aws xray get-insight-summaries --start-time <ISO> --end-time <ISO>357```358359## Latest X-Ray features (2024-2026)3603612024-2026 feature delta (Powertools v2, ADOT Collector, attribute-based sampling, Insights anomaly detection, cross-account ServiceLens, CMK, daemon 4.x maintenance mode, W3C): [Advanced patterns](references/advanced-patterns.md).362Load on demand when choosing components.363364## Platform matrix365366| Platform | Daemon | SDK address | IAM role | Notes |367|---|---|---|---|---|368| **EC2** | systemd service | `127.0.0.1:2000` | Instance profile | Daemon runs as a background process |369| **ECS Fargate** | Sidecar container | `127.0.0.1:2000` | Task role | Same task definition (awsvpc shared network) |370| **ECS EC2** | Sidecar or daemon-service | `127.0.0.1:2000` or `<host-ip>:2000` | Task role | Daemon-service saves memory; sidecar is simpler |371| **EKS** | DaemonSet | `<node-ip>:2000` (downward API) | Pod IRSA role | DaemonSet = one daemon per node |372| **Lambda** | Built-in (no daemon) | N/A | Execution role | Enable `TracingConfig Mode=Active` |373| **App Runner** | N/A (managed) | N/A | Instance role | Enable observability config with `Vendor=AWSXRay` |374| **Elastic Beanstalk** | Instance or sidecar | `127.0.0.1:2000` | Instance profile | EB config has an X-Ray option |375376## NEVER (top 5 — full list of 14 in references)377378- NEVER deploy the X-Ray SDK without `xray:GetSamplingRules` and379 `xray:GetSamplingTargets` on the application's runtime role. The SDK380 fetches central sampling rules from the X-Ray API. Without these381 permissions, the SDK falls back to local default (1/s, fixed) and the382 rules you configure in the console are NEVER applied. #1 silent-failure.383- NEVER run the X-Ray daemon / OTel Collector without384 `xray:PutTraceSegments` and `xray:PutTelemetryRecords`. The SDK385 generates segments and sends them to the daemon, but the daemon386 uploads them. Without upload permissions, traces are silently dropped.387- NEVER set `FixedRate=1.0` on the Default sampling rule for high-traffic388 services. This generates massive trace volume. X-Ray charges per trace389 ingested. Use a custom rule scoped to specific endpoints.390- NEVER forget to patch the AWS SDK (`AWSXRay.captureAWS()` /391 `aws_xray_sdk.core.patch_all()`). Without the patch, downstream AWS392 calls (DynamoDB, S3, SQS) do NOT generate subsegments. The service map393 shows only the entry point — no dependencies.394- NEVER deploy the daemon as a separate ECS service on Fargate and point395 the app to it via DNS. Fargate tasks cannot reach each other on396 localhost. The daemon MUST be a sidecar in the same task definition.397398## Expert heuristic — choosing X-Ray SDK vs ADOT, sampling, and annotations399400SDK-vs-ADOT choice, reservoir/rate tuning, annotation discipline, trace-context propagation, and cost control: [Advanced patterns](references/advanced-patterns.md).401Load on demand when making design decisions.402403## Pre-flight safety checks (run before any deployment CLI)404405- **Confirm IAM role has all 5 X-Ray actions** (PutTraceSegments,406 PutTelemetryRecords, GetSamplingRules, GetSamplingTargets,407 GetEncryptionConfig). Use `AWSXRayDaemonWriteAccess` managed policy.408- **Confirm daemon / OTel Collector is running** and listening on UDP409 2000 (X-Ray) or gRPC 4317 (OTel).410- **Confirm SDK package is installed** and the middleware/patcher is411 active in the code.412- **Confirm AWS SDK is patched** for downstream call tracing.413- **Confirm trace context propagation** across all service boundaries.414- **Confirm sampling rules** (check the Default rule and any custom415 rules).416- **Confirm X-Ray encryption config** (AWS-owned key vs CMK).417- **For existing services, capture current sampling config for rollback.**418419Full CLI sequences for all checks in `references/daemon-and-sampling-guide.md`.420421## Output format — MANDATORY literal labels422423When invoked with a tracing deployment request, your ENTIRE response MUST424be the checklist block below. The labels are **case-sensitive all-caps425keywords**. Do NOT write a preamble. Start with `SERVICE:` and stop after426the `VERIFICATION_COMMANDS:` block.427428```text429SERVICE: <name>430VERDICT: READY_TO_DEPLOY | PREREQUISITES_MISSING431CHECKLIST:432 [✓] Platform — <ec2|ecs|eks|lambda|app-runner>, <cluster/function/detail>433 [✓] Daemon — <daemon-image:version> <deployment-mode> (UDP 2000)434 [✓] SDK instrumentation — <language> <version>, <package> <version>, <middleware>435 [✓] Sampling rule — default (reservoir <n>/s, rate <p>%), custom rule <name> (reservoir <n>/s, rate <p>% on <match>)436 [✓] IAM role — <role-name> has xray:PutTraceSegments + PutTelemetryRecords + GetSamplingRules + GetSamplingTargets437 [✓] Annotations — <indexable fields>438 [✓] Metadata — <debug fields>439 [✓] Service map — generated from traces, <segment-count> segments440 [✓] CloudWatch ServiceLens — integrated441 [OPTIONAL] X-Ray group — <group-name> (filter expression <expr>)442VERIFICATION_COMMANDS:443 aws xray get-sampling-rules444 aws xray get-sampling-targets445 aws xray get-service-graph --start-time <ISO> --end-time <ISO>446 aws ecs describe-task-definition --task-definition <family>447```448449**Status marker semantics:**450- `[✓]` — applied and verified.451- `[✗]` — NOT applied or misconfigured. Cite the gap.452- `[OPTIONAL]` — recommended but not required.453- `[INPUT NEEDED]` — prerequisite value missing; operator must provide.454455**PREREQUISITES_MISSING verdict:** if any REQUIRED prerequisite is missing456(IAM permissions, daemon / Collector not running, SDK not instrumented,457sampling rules not configured), the verdict is `PREREQUISITES_MISSING`.458459## References (load on demand)460461- [Advanced patterns](references/advanced-patterns.md) — 2024-2026 feature delta, SDK-vs-ADOT heuristics, edge-case catalog462- [Daemon and sampling guide](references/daemon-and-sampling-guide.md) — per-platform daemon deployment blocks (EC2, ECS Fargate, EKS, Lambda) plus the full daemon/sampling CLI sequence463- [SDK instrumentation guide](references/sdk-instrumentation-guide.md) — language-by-language instrumentation and AWS SDK patching464465## Domain466467AWS CloudOps / X-Ray Distributed Tracing Observability Provisioning.468469## Edge-case handling470471Edge-case catalog (cross-account, SQS/EventBridge propagation, ECS EC2 host-IP, EKS limits, Lambda cold start, OTel migration, high-cardinality annotations, CMK grants): [Advanced patterns](references/advanced-patterns.md).472Load on demand when deployment hits a corner case.473474## AWS documentation475476- **AWS X-Ray Developer Guide** — https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html477- **X-Ray Daemon** — https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon.html478- **X-Ray SDK** — https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk.html479- **X-Ray Sampling Rules** — https://docs.aws.amazon.com/xray/latest/devguide/xray-console-sampling.html480- **X-Ray Service Map** — https://docs.aws.amazon.com/xray/latest/devguide/xray-services.html481- **X-Ray Groups and Insights** — https://docs.aws.amazon.com/xray/latest/devguide/xray-insights.html482- **CloudWatch ServiceLens** — https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ServiceLens.html483- **AWS Distro for OpenTelemetry (ADOT)** — https://aws-otel.github.io/484- **Lambda Powertools Tracing** — https://docs.powertools.aws.dev/lambda/python/latest/core/tracer/485- **X-Ray CLI Reference** — https://docs.aws.amazon.com/cli/latest/reference/xray/486487## References488489- `references/daemon-and-sampling-guide.md` — full copy-pasteable CLI490 command sequence for daemon deployment (EC2, ECS, EKS, Lambda),491 sampling rule creation (default + custom), IAM role setup, group492 creation, and Terraform / CloudFormation equivalents.493494- `references/sdk-instrumentation-guide.md` — deep reference on SDK495 instrumentation (Python, Node.js, Java, Go, .NET), AWS SDK patching,496 annotation vs metadata, trace context propagation, OpenTelemetry / ADOT497 migration, full NEVER list, edge-case handling, and pre-flight safety498 CLI.