Java Code Examples for com.amazonaws.xray.entities.Subsegment#setNamespace()
The following examples show how to use
com.amazonaws.xray.entities.Subsegment#setNamespace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TracedHttpClient.java From aws-xray-sdk-java with Apache License 2.0 | 6 votes |
public static void addRequestInformation(Subsegment subsegment, HttpRequest request, String url) { subsegment.setNamespace(Namespace.REMOTE.toString()); Segment parentSegment = subsegment.getParentSegment(); TraceHeader header = new TraceHeader(parentSegment.getTraceId(), parentSegment.isSampled() ? subsegment.getId() : null, parentSegment.isSampled() ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED); request.addHeader(TraceHeader.HEADER_KEY, header.toString()); Map<String, Object> requestInformation = new HashMap<>(); requestInformation.put("url", url); requestInformation.put("method", request.getRequestLine().getMethod()); subsegment.putHttp("request", requestInformation); }
Example 2
Source File: TracingInterceptor.java From aws-xray-sdk-java with Apache License 2.0 | 6 votes |
@Override public void beforeExecution(Context.BeforeExecution context, ExecutionAttributes executionAttributes) { AWSXRayRecorder recorder = getRecorder(); Entity origin = recorder.getTraceEntity(); Subsegment subsegment = recorder.beginSubsegment(executionAttributes.getAttribute(SdkExecutionAttribute.SERVICE_NAME)); if (subsegment == null) { return; } subsegment.setNamespace(Namespace.AWS.toString()); subsegment.putAws(EntityDataKeys.AWS.OPERATION_KEY, executionAttributes.getAttribute(SdkExecutionAttribute.OPERATION_NAME)); Region region = executionAttributes.getAttribute(AwsExecutionAttribute.AWS_REGION); if (region != null) { subsegment.putAws(EntityDataKeys.AWS.REGION_KEY, region.id()); } subsegment.putAllAws(extractRequestParameters(context, executionAttributes)); if (accountId != null) { subsegment.putAws(EntityDataKeys.AWS.ACCOUNT_ID_SUBSEGMENT_KEY, accountId); } recorder.setTraceEntity(origin); // store the subsegment in the AWS SDK's executionAttributes so it can be accessed across threads executionAttributes.putAttribute(entityKey, subsegment); }
Example 3
Source File: TracingStatement.java From aws-xray-sdk-java with Apache License 2.0 | 5 votes |
private Subsegment createSubsegment() { try { Connection connection = delegate.getConnection(); DatabaseMetaData metadata = connection.getMetaData(); String subsegmentName = DEFAULT_DATABASE_NAME; try { URI normalizedUri = new URI(new URI(metadata.getURL()).getSchemeSpecificPart()); subsegmentName = connection.getCatalog() + "@" + normalizedUri.getHost(); } catch (URISyntaxException e) { logger.warn("Unable to parse database URI. Falling back to default '" + DEFAULT_DATABASE_NAME + "' for subsegment name.", e); } Subsegment subsegment = AWSXRay.beginSubsegment(subsegmentName); if (subsegment == null) { return null; } subsegment.setNamespace(Namespace.REMOTE.toString()); Map<String, Object> sqlParams = new HashMap<>(); sqlParams.put(URL, metadata.getURL()); sqlParams.put(USER, metadata.getUserName()); sqlParams.put(DRIVER_VERSION, metadata.getDriverVersion()); sqlParams.put(DATABASE_TYPE, metadata.getDatabaseProductName()); sqlParams.put(DATABASE_VERSION, metadata.getDatabaseProductVersion()); subsegment.putAllSql(sqlParams); return subsegment; } catch (SQLException exception) { logger.warn("Failed to create X-Ray subsegment for the statement execution.", exception); return null; } }
Example 4
Source File: TracingHandler.java From aws-xray-sdk-java with Apache License 2.0 | 5 votes |
@Override public void beforeRequest(Request<?> request) { String serviceName = extractServiceName(request); String operationName = extractOperationName(request); if (S3_SERVICE_NAME.equals(serviceName) && S3_PRESIGN_REQUEST.equals(operationName)) { return; } if (XRAY_SERVICE_NAME.equals(serviceName) && (XRAY_SAMPLING_RULE_REQUEST.equals(operationName) || XRAY_SAMPLING_TARGET_REQUEST.equals(operationName))) { return; } if (isSubsegmentDuplicate(recorder.getCurrentSubsegmentOptional(), request)) { return; } Entity entityContext = request.getHandlerContext(ENTITY_KEY); if (null != entityContext) { recorder.setTraceEntity(entityContext); } Subsegment currentSubsegment = recorder.beginSubsegment(serviceName); if (null == currentSubsegment) { return; } currentSubsegment.putAllAws(extractRequestParameters(request)); currentSubsegment.putAws(EntityDataKeys.AWS.OPERATION_KEY, operationName); if (null != accountId) { currentSubsegment.putAws(EntityDataKeys.AWS.ACCOUNT_ID_SUBSEGMENT_KEY, accountId); } currentSubsegment.setNamespace(Namespace.AWS.toString()); if (null != recorder.getCurrentSegment()) { TraceHeader header = new TraceHeader(recorder.getCurrentSegment().getTraceId(), recorder.getCurrentSegment().isSampled() ? currentSubsegment.getId() : null, recorder.getCurrentSegment().isSampled() ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED); request.addHeader(TraceHeader.HEADER_KEY, header.toString()); } }
Example 5
Source File: TracingInterceptor.java From aws-xray-sdk-java with Apache License 2.0 | 4 votes |
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { //get the name of the method for comparison final String name = method.getName(); //was close invoked? boolean close = compare(JdbcInterceptor.CLOSE_VAL, name); //allow close to be called multiple times if (close && closed) { return null; } //are we calling isClosed? if (compare(JdbcInterceptor.ISCLOSED_VAL, name)) { return Boolean.valueOf(closed); } //if we are calling anything else, bail out if (closed) { throw new SQLException("Statement closed."); } //check to see if we are about to execute a query final boolean process = isExecute(method); Object result = null; Subsegment subsegment = null; if (process) { subsegment = AWSXRay.beginSubsegment(hostname); } try { if (process && null != subsegment) { subsegment.putAllSql(additionalParams); subsegment.setNamespace(Namespace.REMOTE.toString()); } result = method.invoke(delegate, args); //execute the query } catch (Throwable t) { if (null != subsegment) { subsegment.addException(t); } if (t instanceof InvocationTargetException && t.getCause() != null) { throw t.getCause(); } else { throw t; } } finally { if (process && null != subsegment) { AWSXRay.endSubsegment(); } } //perform close cleanup if (close) { closed = true; delegate = null; } return result; }
Example 6
Source File: TracingInterceptor.java From aws-xray-sdk-java with Apache License 2.0 | 4 votes |
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { //get the name of the method for comparison final String name = method.getName(); //was close invoked? boolean close = compare(JdbcInterceptor.CLOSE_VAL, name); //allow close to be called multiple times if (close && closed) { return null; } //are we calling isClosed? if (compare(JdbcInterceptor.ISCLOSED_VAL, name)) { return Boolean.valueOf(closed); } //if we are calling anything else, bail out if (closed) { throw new SQLException("Statement closed."); } //check to see if we are about to execute a query final boolean process = isExecute(method); Object result = null; Subsegment subsegment = null; if (process) { subsegment = AWSXRay.beginSubsegment(hostname); } try { if (process && null != subsegment) { subsegment.putAllSql(additionalParams); subsegment.setNamespace(Namespace.REMOTE.toString()); } result = method.invoke(delegate, args); //execute the query } catch (Throwable t) { if (null != subsegment) { subsegment.addException(t); } if (t instanceof InvocationTargetException && t.getCause() != null) { throw t.getCause(); } else { throw t; } } finally { if (process && null != subsegment) { AWSXRay.endSubsegment(); } } //perform close cleanup if (close) { closed = true; delegate = null; } return result; }