Skip to content
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

Added spanId to the parsing error log #297

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation("org.hypertrace.core.serviceframework:platform-metrics:0.1.28")
implementation("org.hypertrace.core.grpcutils:grpc-client-utils:0.6.2")
implementation("org.hypertrace.config.service:spaces-config-service-api:0.1.0")
implementation("org.hypertrace.core.grpcutils:grpc-context-utils:0.6.2")
implementation("org.hypertrace.core.grpcutils:grpc-context-utils:0.7.0")

implementation("com.typesafe:config:1.4.1")
implementation("org.apache.httpcomponents:httpclient:4.5.13")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.hypertrace.core.datamodel.AttributeValue;
import org.hypertrace.core.datamodel.Event;
import org.hypertrace.core.datamodel.StructuredTrace;
import org.hypertrace.core.datamodel.shared.HexUtils;
import org.hypertrace.core.datamodel.shared.trace.AttributeValueCreator;
import org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants;
import org.hypertrace.traceenricher.enrichedspan.constants.utils.EnrichedSpanUtils;
Expand Down Expand Up @@ -46,8 +48,10 @@ public void enrichEvent(StructuredTrace trace, Event event) {
EnrichedSpanUtils.getQueryString(event)
.ifPresent(
queryString -> {
String spanId =
Optional.ofNullable(event.getEventId()).map(HexUtils::getHex).orElse(null);
Map<String, List<String>> paramNameToValues =
getQueryParamsFromQueryString(queryString);
getQueryParamsFromQueryString(queryString, spanId);
for (Map.Entry<String, List<String>> queryParamEntry : paramNameToValues.entrySet()) {
if (queryParamEntry.getValue().isEmpty()) {
continue;
Expand All @@ -65,7 +69,8 @@ public void enrichEvent(StructuredTrace trace, Event event) {
});
}

private Map<String, List<String>> getQueryParamsFromQueryString(String queryString) {
private Map<String, List<String>> getQueryParamsFromQueryString(
String queryString, String spanId) {
return Splitter.on(QUERY_PARAM_DELIMITER).splitToList(queryString).stream()
// split only on first occurrence of delimiter. eg: cat=1dog=2 should be split to cat ->
// 1dog=2
Expand All @@ -75,13 +80,15 @@ private Map<String, List<String>> getQueryParamsFromQueryString(String queryStri
kv ->
Pair.of(
String.format(
PARAM_ATTR_FORMAT, HTTP_REQUEST_QUERY_PARAM_ATTR, decodeParamKey(kv[0])),
decode(kv[1])))
PARAM_ATTR_FORMAT,
HTTP_REQUEST_QUERY_PARAM_ATTR,
decodeParamKey(kv[0], spanId)),
decode(kv[1], spanId)))
.collect(groupingBy(Pair::getKey, mapping(Pair::getValue, toList())));
}

private static String decodeParamKey(String input) {
String urlDecodedKey = decode(input);
private static String decodeParamKey(String input, String spanId) {
String urlDecodedKey = decode(input, spanId);
/* '[]' can occur at the end of param name which denotes param can have multiple values,
we strip '[]' to get original param name */
if (urlDecodedKey.endsWith("[]") && urlDecodedKey.length() > 2) {
Expand All @@ -90,11 +97,11 @@ private static String decodeParamKey(String input) {
return input;
}

private static String decode(String input) {
private static String decode(String input, String spanId) {
try {
return URLDecoder.decode(input, StandardCharsets.UTF_8);
} catch (IllegalArgumentException e) {
LOGGER.error("Cannot decode the input {}", input, e);
LOGGER.error("Cannot decode the input {}, span id {}", input, spanId, e);
// Falling back to original input if it can't be decoded
return input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -70,6 +71,7 @@ Event createMockEvent() {
.when(e.getMetrics())
.thenReturn(Metrics.newBuilder().setMetricMap(new HashMap<>()).build());
when(e.getServiceName()).thenReturn("service");
when(e.getEventId()).thenReturn(ByteBuffer.wrap("event_id".getBytes(StandardCharsets.UTF_8)));
return e;
}

Expand Down
4 changes: 2 additions & 2 deletions hypertrace-trace-enricher/trace-reader/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
api("org.hypertrace.core.datamodel:data-model:0.1.20")
implementation("org.hypertrace.core.attribute.service:attribute-projection-registry:0.12.3")
implementation("org.hypertrace.core.grpcutils:grpc-client-rx-utils:0.6.2")
implementation("org.hypertrace.core.grpcutils:grpc-context-utils:0.6.2")
implementation("org.hypertrace.core.grpcutils:grpc-context-utils:0.7.0")
implementation("io.reactivex.rxjava3:rxjava:3.0.11")

annotationProcessor("org.projectlombok:lombok:1.18.20")
Expand All @@ -22,7 +22,7 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
testImplementation("org.mockito:mockito-inline:3.8.0")
testImplementation("org.mockito:mockito-junit-jupiter:3.8.0")
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.17.0")
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.17.1")

tasks.test {
useJUnitPlatform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {

implementation("org.apache.avro:avro:1.10.2")
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("com.fasterxml.jackson.core:jackson-databind:2.12.2")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.1")

testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
testImplementation("org.mockito:mockito-core:3.8.0")
Expand Down