/** * Extracts the appId/roleName out of Tracestate and compares it with the current appId. It then * generates the appropriate source or target. */ private static String generateSourceTargetCorrelation(String instrumentationKey, String appId) { assert instrumentationKey != null; assert appId != null; String myAppId = InstrumentationKeyResolver.INSTANCE.resolveInstrumentationKey(instrumentationKey); return resolve(appId, myAppId); }
/** * Gets AppId prefixed with key to append to Request-Context header * @return */ private static String getAppIdWithKey() { return REQUEST_CONTEXT_HEADER_APPID_KEY + "=" + getAppId(); }
/** * Used for SpringBoot setttings to propogate the switch for W3C to TracecontextCorrelation class * @param enableBackCompatibilityForW3C */ public void setEnableBackCompatibilityForW3C(boolean enableBackCompatibilityForW3C) { TraceContextCorrelation.setIsW3CBackCompatEnabled(enableBackCompatibilityForW3C); }
@Test public void testFetchApplicationIdWithTaskCompleteImmediately() throws InterruptedException, ExecutionException, ParseException, IOException { //setup MockHttpAsyncClientWrapper clientWrapper = new MockHttpAsyncClientWrapper(); clientWrapper.setAppId("AppId"); clientWrapper.setFailureOn(false); clientWrapper.setTaskAsComplete(); CdsProfileFetcher fetcher = new CdsProfileFetcher(); fetcher.setHttpClient(clientWrapper.getClient()); // task is completed right away ProfileFetcherResult result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.COMPLETE, result.getStatus()); Assert.assertEquals("AppId", result.getAppId()); }
private static String generateId(String parentId) { String sanitizedParentId = sanitizeParentId(parentId); String suffix = generateSuffix(); //handle overflow if (sanitizedParentId.length() + suffix.length() > REQUESTID_MAXLENGTH) { return shortenId(sanitizedParentId, suffix); } return sanitizedParentId + suffix + "_"; }
private static String sanitizeParentId(String parentId) { String result = parentId; if (!isHierarchicalId(parentId)) { result = "|" + result; } char lastChar = parentId.charAt(parentId.length() - 1); if (lastChar != '.' && lastChar != '_') { result = result + '.'; } return result; }
InstrumentationKeyResolver() { this.appIdCache = new ConcurrentHashMap<String, String>(); this.profileFetcher = new CdsProfileFetcher(); }
@Override public ProfileFetcherResult fetchAppProfile(String instrumentationKey) throws ExecutionException { ++callCounter; if (throwException) { throw new ExecutionException("No doughnuts for you.", null); } return new ProfileFetcherResult(this.appId, this.status); }
/** * Constructs new RequestTelemetryContext object. * @param ticks The time in ticks * @param servletRequest The servlet request */ public RequestTelemetryContext(long ticks, HttpServletRequest servletRequest) { requestTelemetry = new RequestTelemetry(); requestStartTimeTicks = ticks; this.servletRequest = servletRequest; correlationContext = new CorrelationContext(); }
/** * Extracts the value of a "Key-Value" type of header. For example, for a header with value: "foo=bar, name=joe", * we can extract "joe" with a call to this method passing the key "name". * @param headerFullValue The entire header value. * @param key They key for which to extract the value * @return The extracted value */ private static String getKeyValueHeaderValue(String headerFullValue, String key) { return getPropertyBag(headerFullValue).get(key); }
private static String shortenId(String parentId, String suffix) { // ported from .NET's System.Diagnostics.Activity.cs implementation: // https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs int trimPosition = REQUESTID_MAXLENGTH - 9; // make room for suffix + delimiter while (trimPosition > 1) { if (parentId.charAt(trimPosition - 1) == '.' || parentId.charAt(trimPosition - 1) == '_') break; trimPosition--; } // parentId is not a valid requestId, so generate one. if (trimPosition == 1) { return "|" + generateRootId() + "."; } return parentId.substring(0, trimPosition) + suffix + '#'; }
@Before public void testInitialize() { InstrumentationKeyResolver.INSTANCE.clearCache(); }
private static String generateId(String parentId) { String sanitizedParentId = sanitizeParentId(parentId); String suffix = generateSuffix(); //handle overflow if (sanitizedParentId.length() + suffix.length() > REQUESTID_MAXLENGTH) { return shortenId(sanitizedParentId, suffix); } return sanitizedParentId + suffix + "_"; }
/** * Extracts the appId/roleName out of Tracestate and compares it with the current appId. It then * generates the appropriate source or target. */ private static String generateSourceTargetCorrelation(String instrumentationKey, String appId) { assert instrumentationKey != null; assert appId != null; String myAppId = InstrumentationKeyResolver.INSTANCE.resolveInstrumentationKey(instrumentationKey); return resolve(appId, myAppId); }
private static String sanitizeParentId(String parentId) { String result = parentId; if (!isHierarchicalId(parentId)) { result = "|" + result; } char lastChar = parentId.charAt(parentId.length() - 1); if (lastChar != '.' && lastChar != '_') { result = result + '.'; } return result; }
InstrumentationKeyResolver() { this.appIdCache = new ConcurrentHashMap<String, String>(); this.profileFetcher = new CdsProfileFetcher(); }
/** * Gets AppId prefixed with key to append to Request-Context header * @return */ private static String getAppIdWithKey() { return REQUEST_CONTEXT_HEADER_APPID_KEY + "=" + getAppId(); }
/** * Used for SpringBoot setttings to propogate the switch for W3C to TracecontextCorrelation class * @param enableBackCompatibilityForW3C */ public void setEnableBackCompatibilityForW3C(boolean enableBackCompatibilityForW3C) { TraceContextCorrelation.setIsW3CBackCompatEnabled(enableBackCompatibilityForW3C); }
/** * Constructs new RequestTelemetryContext object. * @param ticks The time in ticks * @param servletRequest The servlet request */ public RequestTelemetryContext(long ticks, HttpServletRequest servletRequest) { requestTelemetry = new RequestTelemetry(); requestStartTimeTicks = ticks; this.servletRequest = servletRequest; correlationContext = new CorrelationContext(); }
/** * Extracts the value of a "Key-Value" type of header. For example, for a header with value: "foo=bar, name=joe", * we can extract "joe" with a call to this method passing the key "name". * @param headerFullValue The entire header value. * @param key They key for which to extract the value * @return The extracted value */ private static String getKeyValueHeaderValue(String headerFullValue, String key) { return getPropertyBag(headerFullValue).get(key); }