Search in sources :

Example 6 with AWSLogReference

use of com.amazonaws.xray.entities.AWSLogReference in project aws-xray-sdk-java by aws.

the class EKSPlugin method populateLogReferences.

/**
 * Generate log references by calling K8s for Container Insights configuration data.
 */
private void populateLogReferences() {
    if (clusterName == null) {
        clusterName = ContainerInsightsUtil.getClusterName();
    }
    AWSLogReference log = new AWSLogReference();
    log.setLogGroup(String.format("/aws/containerinsights/%s/application", clusterName));
    logReferences.add(log);
}
Also used : AWSLogReference(com.amazonaws.xray.entities.AWSLogReference)

Example 7 with AWSLogReference

use of com.amazonaws.xray.entities.AWSLogReference in project aws-xray-sdk-java by aws.

the class EC2Plugin method populateLogReferences.

/**
 * Reads the log group configuration file generated by the CloudWatch Agent to discover all log groups being used on this
 * instance and populates log reference set with them to be included in trace documents.
 */
public void populateLogReferences() {
    String filePath = null;
    String programData = System.getenv(WINDOWS_PROGRAM_DATA);
    if (StringValidator.isNullOrBlank(programData)) {
        for (Path root : fs.getRootDirectories()) {
            if (root.toString().equals(LINUX_ROOT)) {
                filePath = LINUX_ROOT + LINUX_PATH;
                break;
            }
        }
    } else {
        filePath = programData + WINDOWS_PATH;
    }
    if (filePath == null) {
        logger.warn("X-Ray could not recognize the file system in use. Expected file system to be Linux or Windows based.");
        return;
    }
    try {
        JsonNode logConfigs = JsonUtils.getNodeFromJsonFile(filePath, LOG_CONFIGS);
        List<String> logGroups = JsonUtils.getMatchingListFromJsonArrayNode(logConfigs, LOG_GROUP_NAME);
        for (String logGroup : logGroups) {
            AWSLogReference logReference = new AWSLogReference();
            logReference.setLogGroup(logGroup);
            logReferences.add(logReference);
        }
    } catch (IOException e) {
        logger.warn("CloudWatch Agent log configuration file not found at " + filePath + ". Install the CloudWatch Agent " + "on this instance to record log references in X-Ray.");
    } catch (RuntimeException e) {
        logger.warn("An unexpected exception occurred while reading CloudWatch agent log configuration file at " + filePath + ":\n", e);
    }
}
Also used : Path(java.nio.file.Path) AWSLogReference(com.amazonaws.xray.entities.AWSLogReference) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Aggregations

AWSLogReference (com.amazonaws.xray.entities.AWSLogReference)7 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 SegmentContextResolverChain (com.amazonaws.xray.contexts.SegmentContextResolverChain)1 Emitter (com.amazonaws.xray.emitters.Emitter)1 Segment (com.amazonaws.xray.entities.Segment)1 StringValidator (com.amazonaws.xray.entities.StringValidator)1 SegmentListener (com.amazonaws.xray.listeners.SegmentListener)1 EC2Plugin (com.amazonaws.xray.plugins.EC2Plugin)1 ECSPlugin (com.amazonaws.xray.plugins.ECSPlugin)1 EKSPlugin (com.amazonaws.xray.plugins.EKSPlugin)1 ElasticBeanstalkPlugin (com.amazonaws.xray.plugins.ElasticBeanstalkPlugin)1 Plugin (com.amazonaws.xray.plugins.Plugin)1 ContextMissingStrategy (com.amazonaws.xray.strategy.ContextMissingStrategy)1 IgnoreErrorContextMissingStrategy (com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy)1 LogErrorContextMissingStrategy (com.amazonaws.xray.strategy.LogErrorContextMissingStrategy)1 PrioritizationStrategy (com.amazonaws.xray.strategy.PrioritizationStrategy)1