-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linking CloudWatch logs to traces from ECS Fargate #588
Comments
Have you tried setting the "awslogs-group"? |
Closing as stale issue - please reopen if there are any further questions |
@hexionas Did you guys ever figure this out? |
This can be done using resource-detectors in collector config:
|
I'm having the same issue, I'm adding the log group as metadata and it's not working! any workaround for this? |
I fixed this way:
|
I was able to get it working with express using the below sample code and it can be possibly be adapted for other use cases as well. const express = require('express');
const AWSXRay = require('aws-xray-sdk');
const logger = {
info: function (message, subsegment) {
if (subsegment != undefined){
console.info( `AWS-XRAY-TRACE-ID: ${subsegment.parent.trace_id} ${subsegment.id} ${message}`)
} else {
const segment = AWSXRay.getSegment()
console.info(`AWS-XRAY-TRACE-ID: ${segment.trace_id} ${message}`)
}
}
}
const setCloudWatchConfig = (cloudwatch_log_groupname) => (req, res, next) => {
const segment = AWSXRay.getSegment()
segment.aws.cloudwatch_logs= [{log_group: cloudwatch_log_groupname}]
next();
}
const app = express();
app.use(AWSXRay.express.openSegment('MyApp'));
app.use(setCloudWatchConfig("xray-test"))
app.get('/user' ,(req, res) => {
logger.info('rendering user!');
res.send('user rendered!')
})
app.use(AWSXRay.express.closeSegment());
app.listen('5000', ()=> {
console.log('App listening on http://localhost:5000');
}) |
Using only the Log Group Name is not enough, it shows an error on the XRay UI. So you also need to specify the Log Group ARN: import * as AWSXRay from "aws-xray-sdk-core";
export function setCloudWatchLogGroup(cwLogGroupName: string, cwLogGroupArn: string): void {
const segment = AWSXRay.getSegment();
if (segment) {
const isSubsegment = "parent" in segment;
// This can only be added to the parent segment
if (!isSubsegment) {
segment.addPluginData({
cloudwatch_logs: [
{
log_group: cwLogGroupName,
arn: cwLogGroupArn,
},
],
});
}
}
} Then it works and the Cloudwatch Logs are correctly correlated on XRay. |
We would love to be able to see our logs linked to a trace. Following some previous hacked together solutions they appear to be impossible in this library.
Will there be support for this at any point? Or is there a way to achieve this that I might be missing?
The text was updated successfully, but these errors were encountered: