

# Connect to an AWS X-Ray data source
<a name="x-ray-data-source"></a>

**Note**  
In workspaces that support version 9 or newer, this data source might require you to install the appropriate plugin. For more information, see [Extend your workspace with plugins](grafana-plugins.md).

 Add AWS X-Ray as a data source, and then build dashboards or use Explore with X-Ray to look at traces, analytics, or insights. 

 With Amazon Managed Grafana, you can add X-Ray as a data source by using the AWS data source configuration option in the Grafana workspace console. This feature simplifies adding X-Ray as a data source by discovering your existing X-Ray accounts and manages the configuration of the authentication credentials that are required to access X-Ray. You can use this method to set up authentication and add X-Ray as a data source, or you can manually set up the data source and the necessary authentication credentials using the same method that you would on a self-managed Grafana server.

**Topics**
+ [Use AWS data source configuration to add X-Ray as a data source](xray-adding-AWS-config.md)
+ [Manually adding the X-Ray data source](xray-add-the-data-source.md)
+ [X-Ray settings](#xray-settings)
+ [Using the X-Ray data source](xray-using.md)

# Use AWS data source configuration to add X-Ray as a data source
<a name="xray-adding-AWS-config"></a>

To use AWS data source configuration, first you use the Amazon Managed Grafana console to enable service-mananged IAM roles that grant the workspace the IAM policies necessary to read the X-Ray resources in your account or in your entire organizational units. Then you use the Amazon Managed Grafana workspace console to add X-Ray as a data source.

**To use AWS data source configuration to add X-Ray as a data source**

1. Open the Amazon Managed Grafana console at [https://console.aws.amazon.com/grafana/](https://console.aws.amazon.com/grafana/home/).

1. In the upper left corner of the page, choose the menu icon and then choose **All workspaces**.

1. Choose the name of the workspace.

1. If you didn't choose to use service-managed permissions for this workspace when you created it, then change from using customer-managed permissions to use service-managed permissions to ensure that the proper IAM roles and policies are enabled for using the AWS data source configuration option in the Grafana workspace console. To do so, choose the edit icon by **IAM role** and then choose **Service managed**, **Save changes**. For more information, see [Amazon Managed Grafana permissions and policies for AWS data sources](AMG-manage-permissions.md). 

1. Choose the **Data sources** tab. Then select the check box for **AWS X-Ray**, and choose **Actions**, **Enable service-managed policy**.

1. Choose the **Data sources** tab again, and then choose **Configure in Grafana** in the **AWS X-Ray** row.

1. Sign into the Grafana workspace console using IAM Identity Center if necessary.

1. In the left navigation bar in the Grafana workspace console, choose the AWS icon and then choose**AWS services**, **X-Ray**.

1. Select the default Region that you want the X-Ray data source to query from, select the accounts, and then choose **Add data source**.

# Manually adding the X-Ray data source
<a name="xray-add-the-data-source"></a>

**To manually add the X-Ray data source**

1.  In the Grafana console side menu, pause on the **Configuration** (gear) icon, then choose **Data Sources**.

1. Choose **Add data source**.

1. Choose the **X-Ray** data source. If necessary, you can start typing **X-Ray** in the search box to help you find it.

## X-Ray settings
<a name="xray-settings"></a>


|  Name  |  Description  | 
| --- | --- | 
|  Name  |  The data source name. This is how you see the data source in panels and queries.  | 
|  Default  |  Default data source means that it will be pre-selected for new panels.  | 
|  Default Region  |  Used in query editor to set region (can be changed on per query basis). | 
|  Auth Provider  |  Specify the provider to get credentials.  | 
|  Credentials profile name  |  Specify the name of the profile to use (if you use \$1/.aws/credentials file), keep blank for default.  | 
|  Assume Role Arn  |  Specify the ARN of the role to assume.  | 
|  External ID  |  If you are assuming a role in another account, that has been created with an external ID, specify the external ID here.  | 

### Authentication
<a name="xray-authentication"></a>

This section covers the different types of authentication that you can use for X-Ray data source. 

#### IAM roles
<a name="xray-iam-roles"></a>

 Currently, all access to X-Ray is done server side by the Grafana workspace backend using the official AWS SDK. If your Grafana server is running on AWS, you can use IAM roles and authentication will be handled automatically. 

 For more information, see [IAM roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html). 

### IAM policies
<a name="xray-iam-policies"></a>

 Grafana needs permissions granted via IAM to be able to read X-Ray data and EC2 tags/instances/regions. You can attach these permissions to IAM roles and use the built-in Grafana support for assuming roles. 

 The following code example shows a minimal policy. 

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "xray:BatchGetTraces",
                "xray:GetTraceSummaries",
                "xray:GetTraceGraph",
                "xray:GetGroups",
                "xray:GetTimeSeriesServiceStatistics",
                "xray:GetInsightSummaries",
                "xray:GetInsight",
                "ec2:DescribeRegions"
            ],
            "Resource": "*"
        }
    ]
}
```

------

#### Example AWS credentials
<a name="xray-example-aws-credentials"></a>

 You can't use the credentials file method in Amazon Managed Grafana. 

# Using the X-Ray data source
<a name="xray-using"></a>

## Query editor
<a name="xray-query-editor"></a>

 The most important field in the editor is the query type. There are four query types: 
+  Trace List (Traces in AWS) 
+  Trace Statistics 
+  Trace Analytics (Analytics in AWS) 
+  Insights 

## Trace List
<a name="xray-trace-list"></a>

 The Trace List type allows you to search for traces, which are shown in a table. Choosing the trace ID in the first column opens the trace on the right side. Notice the query field in the editor. You can write queries, filter expressions, or you can insert a single trace ID that will be shown in a trace view. For more details about filter expressions, see the [AWS X-Ray documentation](https://docs.aws.amazon.com/xray/latest/devguide/xray-console-filters.html). 

**Note**  
 The trace list will show only the first 1000 traces. 

## Trace Statistics
<a name="xray-trace-statistics"></a>

 In Trace Statistics, you can see a graph and a table showing information about error, fault, throttle, success, and total count. You can use the columns field in the query editor to see only specified columns. 

## Trace Analytics
<a name="xray-trace-analytics"></a>

 In Trace Analytics, you can visualize the following tables. 
+  Root Cause 
  +  Response Time 
    +  Root Cause Service (Last service in path) 
    +  Path (multiple paths) 
  +  Error 
    +  Root Cause Service (Last service in path) 
    +  Path 
    +  Error Message 
  +  Fault 
    +  Root Cause Service (Last service in path) 
    +  Path 
    +  Error Message 
+  End-user Impact 
+  URL 
+  HTTP Status Code 

## Insights
<a name="xray-insights"></a>

 In Insights, you can see the summary table for Insights. Choosing the InsightId will take you to AWS Management console. 

## Alerting
<a name="xray-alerting"></a>

 Because X-Ray queries can return numeric data, alerts are supported. For more information, see [Grafana alerting](alerts-overview.md). 