Questions tagged with AWS X-Ray
Content language: English
Sort by most recent
Hi there,
I was reading the official documentation on https://github.com/aws/aws-xray-sdk-go but not quite sure how can I add the Cognito client that is created on my lambda function to the service map and x-ray traces.
```
import (
"context"
cognito "github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-xray-sdk-go/xray"
)
func GetClient() {
...
cfg, errCfg := config.LoadDefaultConfig(context.TODO())
client := cognito.NewFromConfig(cfg)
// the next line is not valid, because the function receives a *client.Client as a parameter
// and my current client si of type *cognito.Client
// the error is: cannot use client (variable of type *cognitoidentityprovider.Client) as *"github.com/aws/aws-sdk-go/aws/client".Client value in argument to xray.AWS
xray.AWS(client)
...
}
```
I appreciate your advice.
I have XRay tracing working in my single component API. I see Xray Traces and see the Service Map. I also wanted to enable Insights so that I could get notified about anomolies. I created an XRay Group based on an attribute in the API url. I then started to introduce 4xx errors and 5xx faults into the API so that I could trigger insights (I hoped). I could see the traces start to show all the errors and faults, but Insights never appeared.

I figured that I should start to see some insights appear on the XRay Insights page, but nothing ever comes up even with massive amounts of errors and faults.

I have followed the examples given by Nikhil Shetty in his blogs, but I'm not able to get this to work! How can I get this to work?
We have an existing Java 17 app running SpringBoot 2.7.9 and are upgrading to SpringBoot 3.0.3
Spring Boot 3 uses the Jakarta EE 10 - as a result the javax.servlet.Filter is no longer available (instead its jakarta.servlet.Filter)
ref: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#jakarta-ee
Given the above, we can no longer trace incoming requests - https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-filters.html
Are there alternatives are available to resolve this? (eg updated AWS SDK, alternative filter suggestions?)
-- updated --
I see in the github repo that a Jakarta compatible servlet has been merged into the master branch, so I guess this is just pending a new release
ref : https://github.com/aws/aws-xray-sdk-java/pull/372
Dear Gurus,
I need your kind support to resolve issue which i am facing with respect to architecture.
I have one App Server in which i have desktop base exe installed and user use it by running on there desktop.
I have one Web Server in which i am running IIS and user use it on there browsers.
I have one Database Server (MSSQL) which is connected with the App and Web.
All Three are installed in EC2.
How can i get the application detail from XRAY ?
What Should i do ?
Should i only install the AWS X-Ray daemon and that's it or do i have to do some configuration on APP + WEB + DB to collect the traces.
Your kind support will save my time, thanks in advance.
Regards
Malik Adeel Imtiaz
Hi,
I've been trying to make a bit more sense of my X-Ray traces, and I've been seeing a lot of stuff that is initated by my service (like initialisation calls or stuff done in an update loop) being seen by X-ray as having a client request behind them.
Traces are sent from a go program with the otel go SDK to an OTEL collector which then forwards them to the AWS account.
I've tried intialising the trace with different traceKind (Internal, Producer) to no avail.
I was able to get what I wanted using the aws client to send out edited traces with an invalid 'parent_id' parameter to get the visualisation I wanted in the ServiceMap, but this is pretty hacky & I couldn't even get the same result through OTEL's go sdk.

(The service in the example is actually run locally for testing, I just forced the origin to AppRunner so the serviceMap doesn't get confused & so I do not confuse them with actual ECS instances of the services that are running)
For the sake of example, here's a trace with an "unwanted client", and the manually edited version which appears "clientless" in the service map:
The version with the client link
```
{
"Id": "1-63ee407a-35043ec3121f735baa80ebea",
"Duration": 0.801,
"LimitExceeded": false,
"Segments": [
{
"Id": "497e0cc431330383",
"Document": {
"id": "497e0cc431330383",
"name": "SQS",
"start_time": 1676481266.4775069,
"trace_id": "1-63ee407a-35043ec3121f735baa80ebea",
"end_time": 1676481267.278352,
"fault": false,
"error": false,
"throttle": false,
"aws": {
"queue_url": "https://sqs.eu-west-1.amazonaws.com/639648953767/rt-netsample-ServicesStack-VpcDev-snsrtnetsampledevonlinebmatchmaki-rRQaezXx98aB",
"xray": {
"auto_instrumentation": false
},
"region": "eu-west-1",
"operation": "SendMessageBatch",
"request_id": "618bb528-1ab6-5fe3-8fc0-e94f0f854783"
},
"metadata": {
"default": {
"messaging.system": "AmazonSQS",
"messaging.url": "https://sqs.eu-west-1.amazonaws.com/639648953767/rt-netsample-ServicesStack-VpcDev-snsrtnetsampledevonlinebmatchmaki-rRQaezXx98aB",
"aws.service": "SQS",
"otel.resource.cloud.platform": "aws_app_runner",
"otel.resource.cloud.provider": "aws"
}
},
"origin": "AWS::AppRunner::Service"
}
}
]
}
```
The version without:
```
{
"Id": "1-63ee41c9-a06f9285771aedcd36b04dd3",
"Duration": 0.801,
"LimitExceeded": false,
"Segments": [
{
"Id": "497e0cc431330383",
"Document": {
"id": "497e0cc431330383",
"name": "SQS",
"start_time": 1676481266.4775069,
"trace_id": "1-63ee41c9-a06f9285771aedcd36b04dd3",
"end_time": 1676481267.278352,
"parent_id": "004f72be19cddc2b",
"fault": false,
"error": false,
"throttle": false,
"aws": {
"queue_url": "https://sqs.eu-west-1.amazonaws.com/639648953767/rt-netsample-ServicesStack-VpcDev-snsrtnetsampledevonlinebmatchmaki-rRQaezXx98aB",
"xray": {
"auto_instrumentation": false
},
"region": "eu-west-1",
"operation": "SendMessageBatch",
"request_id": "618bb528-1ab6-5fe3-8fc0-e94f0f854783"
},
"metadata": {
"default": {
"messaging.system": "AmazonSQS",
"messaging.url": "https://sqs.eu-west-1.amazonaws.com/639648953767/rt-netsample-ServicesStack-VpcDev-snsrtnetsampledevonlinebmatchmaki-rRQaezXx98aB",
"aws.service": "SQS",
"otel.resource.cloud.platform": "aws_app_runner",
"otel.resource.cloud.provider": "aws"
}
},
"origin": "AWS::AppRunner::Service"
}
}
]
}
```
Thanks in advance !
I have a very simple ` node js` application.
in the code I want to use ` x-ray ` and catch the calls I do with the AWS sdk. In my case the secrets manager.
I always get this error "**Error: Failed to get the current sub/segment from the context**." when I run it localy.
```
const AWS = require('aws-sdk');
const AWSXRay = require('aws-xray-sdk');
AWS.config.update({ region: 'eu-west-1' });
// Initialize the AWS X-Ray SDK
AWSXRay.captureAWS(require('aws-sdk'));
// Create a Secrets Manager client with X-Ray instrumentation
const secretsManager = AWSXRay.captureAWSClient(new AWS.SecretsManager());
// Retrieve the secret value with X-Ray instrumentation
AWSXRay.captureAsyncFunc('getSecretValue', function(subsegment) {
// Define the parameters for the secret
const params = {
SecretId: 'thesecretId'
};
return secretsManager.getSecretValue(params).promise().then(data => {
if (AWSXRay.getSegment()) {
AWSXRay.getSegment().addMetadata('SecretId', params.SecretId);
}
return JSON.parse(data.SecretString).password;
});
}).then(password => {
console.log('got password:');
}).catch(err => {
console.error(err);
});
```
I have an eventbridge rule with an SQS target, and the lambda function that puts the event on the bus is configured to use xray (traces lead up to eventbridge in xray, so this is working fine).
In the SQS messages (received with a ReceiveMessageCommand) there is no AWSTraceHeader attribute, so I cannot continue the trace downstream.
I have added an identical rule with lambda target with tracing to test if the trace is propagated correctly, and this is the case, I have a lambda node linked after the events node in the service map.
I read that eventbridge should propagate trace headers to SQS targets, mentioned here:
https://aws.amazon.com/about-aws/whats-new/2021/03/amazon-eventbridge-now-supports-propagation-of-x-ray-trace-context/?nc1=h_ls
Is this actually the case? If so, is there anything I am missing for this to work?
I am trying to integrate my React application with XRay for application tracing. I created a Cognito Identity Pool, allowed access for unauthenticated users and attached a proper policy to allow uploading traces to XRay service.
In the React app, I am receiving the credentials but after that, the PutTraceSegmentsCommand fails with the following error:
**AccessDeniedException: User: arn:aws:sts::<account-ID>:assumed-role/<user-role>/CognitoIdentityCredentials is not authorized to perform: xray:PutTraceSegments because no session policy allows the xray:PutTraceSegments action**.
I am using React v18 and AWS Javascript SDK v3. I am not using the Amplify SDK but @aws-sdk/credential-provider-cognito-identity package.
Kindly suggest a resolution.
Thanky in advance,
Naveen.
Hello Team,
I have couple of questions w.r.t X-Ray filtering and Grouping.
Q1 : How do we forward the Traces to a predefined Trace Group ?
Description : I would like to know how do we group the Traces from a Kubernetes cluster. We are using Otel Collector to forward the Traces from Cluster to Cloud X-Ray.
We can define a group in case of fluentbit and forward the logs to specific group on a cloud watch. Do we have anything like this.
Q2: How do we filter on the Metadata of a Trace ?
We have Cluster specific information in our metadata and trying to filter on the the same. This data is getting displayed in Segement Tab -> Metadata.
Sample:
{
"default": {
"otel.resource.k8s.pod.uid": "82784adc-4f59-411e-9a7e-ee8f070752d8",
"otel.resource.service.version": "v1",
"otel.resource.k8s.deployment.name": "ihe-forwarder",
"otel.resource.k8s.pod.start_time": "2023-01-09 19:16:11 +0000 UTC",
"otel.resource.ClusterId": "",
"otel.resource.service.instance.id": "95fb977c-7ded-40be-8da3-983b052db1ef",
"otel.resource.k8s.pod.ip": "10.42.0.90",
"otel.resource.k8s.node.name": "ingbtcpic6vl355",
"otel.resource.k8s.pod.name": "ihe-forwarder-7f6b98b99b-nthw7",
"otel.resource.service.name": "ix-ihe-forwarder",
"db.statement_type": "Text",
"otel.resource.k8s.namespace.name": "ix"
}
}
Overall, my requirement is to get the Total number of Trace metric from a given Kubernetes Cluster. I am capturing these metrics to have the Cost Analysis done for our Application.
Thanks,
Hi,
I am getting below error when trying to upload files in S3 bucket. I checked policies and updated them but still getting error.
```
2023-01-01T16:08:29.758+05:30
Jan 1 10:38:29 ip-172-31-40-199 web: boto3.exceptions.S3UploadFailedError: Failed to upload static/uploads/alexa.wav to myflask/alexa.wav: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
Jan 1 10:38:29 ip-172-31-40-199 web: boto3.exceptions.S3UploadFailedError: Failed to upload static/uploads/alexa.wav to myflask/alexa.wav: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
Jan 1 10:58:40 ip-172-31-40-199 web: ERROR:aws_xray_sdk.core.context:cannot find the current segment/subsegment, please make sure you have a segment open
```
Bucket is public and policy applied is
```
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "myflask-allow-permission-for-saving-audios",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::377727317375:role/aws-elasticbeanstalk-ec2-role"
},
"Action": [
"s3:PutObject",
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::myflask",
"arn:aws:s3:::myflask/*"
]
}
]
}
```
We have a build an application using mutiple aws services. The request from front end goes to API GW and then to Aggregator Lambda Function and then to Individual Data Based Lambda Function and then the request goes to Dynamo db or Elastic Search.
The logs from Lambda goes to Cloudwatch. We have to open 2 different cloudwatch logs to debug the issues.
We want to understand the ways to get all logs in a single log view. Are there any way to get these kind of logs ?
Can some one share any insights on this ?
I have a Node.js app running in EC2 and have successfully launched the X-Ray collector using user data. The X-Ray service is getting the traces from the application (instrumented using the javascript xray-sdk), but I see no trend information in the sampling rules I have set up in the AWS console (including the default rule).
My code to initialize the sdk is pretty simple:
```
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
AWS.config.update({ region: process.env.DEFAULT_AWS_REGION || 'us-west-2' });
...
app.use(AWSXRay.express.closeSegment());
...
app.use(AWSXRay.express.closeSegment());
```
I have also added code to use the AWS sdk to query for and log the sampling rules to see if they are visible to the app, and they are. I have not called `AWSXRay.middleware.disableCentralizedSampling()`, so I don't know why the sampling rules are not being used.
Is there some other configuration I need to set up to allow the rules to be used?