1. Answers
  2. Integrate AWS CloudWatch with X-Ray

How do I integrate AWS CloudWatch with X-Ray?

In this guide, we will demonstrate how to integrate AWS CloudWatch with AWS X-Ray using Pulumi. This integration allows you to monitor and trace your applications, providing visibility into performance and operational health.

We will create an X-Ray group and a CloudWatch dashboard to visualize trace data.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create an X-Ray group
const xrayGroup = new aws.xray.Group("exampleGroup", {
    groupName: "exampleGroup",
    filterExpression: "service(\"example-service\")",
    insightsConfiguration: {
        insightsEnabled: true,
        notificationsEnabled: true,
    },
});

// Create a CloudWatch dashboard
const dashboard = new aws.cloudwatch.Dashboard("exampleDashboard", {
    dashboardName: "exampleDashboard",
    dashboardBody: JSON.stringify({
        widgets: [
            {
                type: "log",
                x: 0,
                y: 0,
                width: 24,
                height: 6,
                properties: {
                    query: "fields @timestamp, @message | filter @logStream like /exampleGroup/",
                    region: "us-west-2",
                    title: "X-Ray Logs",
                },
            },
            {
                type: "metric",
                x: 0,
                y: 6,
                width: 24,
                height: 6,
                properties: {
                    metrics: [
                        ["AWS/XRay", "SegmentsReceivedCount", "GroupName", "exampleGroup"],
                        ["AWS/XRay", "SegmentsSentCount", "GroupName", "exampleGroup"],
                    ],
                    period: 300,
                    stat: "Sum",
                    region: "us-west-2",
                    title: "X-Ray Segment Metrics",
                },
            },
        ],
    }),
});

// Export the names of the resources
export const xrayGroupName = xrayGroup.groupName;
export const dashboardName = dashboard.dashboardName;

Key Points

  • X-Ray Group: This resource defines a group for X-Ray traces with specific filter expressions and insights configuration.
  • CloudWatch Dashboard: This resource creates a dashboard in CloudWatch to visualize X-Ray trace data and logs.

Summary

We have created an X-Ray group and a CloudWatch dashboard to monitor and visualize trace data from AWS X-Ray. This setup helps in gaining insights into the performance and health of your applications.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up