Skip to content
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

orbs:
lumigo-orb: &lumigo_orb_version lumigo/lumigo-orb@volatile
lumigo-orb: &lumigo_orb_version lumigo/lumigo-orb@dev:c7858b2

defaults: &defaults
working_directory: ~/java-tracer
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ There are 2 way to pass configuration properties

Adding `LUMIGO_TRACER_TOKEN` environment variables

#### Execution Tags

Execution tags can be added by utilizing `ExecutionTags` Module

```java
ExecutionTags.addTag("key", "value", true);
```


#### Static code initiation

```java
Expand Down
7 changes: 6 additions & 1 deletion scripts/checks.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env bash
set -eo pipefail

java -jar libs/google-java-format-1.7-all-deps.jar --set-exit-if-changed -i -a $(find . -type f -name "*.java" | grep ".*/src/.*java")
echo "Checking for formatting issues..."
if ! java -jar libs/google-java-format-1.7-all-deps.jar --set-exit-if-changed -i -a $(find . -type f -name "*.java" | grep ".*/src/.*java"); then
echo "some files were formatted, exiting"
exit 1
fi

mvn -Djava.security.manager=allow -f agent/pom.xml clean package
mvn -Djava.security.manager=allow clean package
84 changes: 84 additions & 0 deletions src/main/java/io/lumigo/core/ExecutionTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.lumigo.core;

import io.lumigo.models.Span.ExecutionTag;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.pmw.tinylog.Logger;

public final class ExecutionTags {
private static final int MAX_TAG_KEY_LEN = 100;
private static final int MAX_TAG_VALUE_LEN = 100;
private static final int MAX_TAGS = 50;
private static final String ADD_TAG_ERROR_MSG_PREFIX = "Error adding tag";
private final List<ExecutionTag> tags = new ArrayList<ExecutionTag>();

private static final ExecutionTags ourInstance = new ExecutionTags();

private ExecutionTags() {}

public static void add(String key, String value) {
getInstance().addTagInternal(key, value);
}

// Package-private methods for internal consumption
static ExecutionTags getInstance() {
return ourInstance;
}

static List<ExecutionTag> getTags() {
return Collections.unmodifiableList(new ArrayList<>(getInstance().tags));
}

static void clear() {
getInstance().tags.clear();
}

private boolean validateTag(String key, String value) {
key = String.valueOf(key);
value = String.valueOf(value);
if (key.isEmpty() || key.length() > MAX_TAG_KEY_LEN) {
Logger.debug(
String.format(
"%s: key length should be between 1 and %d: %s - %s",
ADD_TAG_ERROR_MSG_PREFIX, MAX_TAG_KEY_LEN, key, value));
return false;
}
if (value.isEmpty() || value.length() > MAX_TAG_VALUE_LEN) {
Logger.debug(
String.format(
"%s: value length should be between 1 and %d: %s - %s",
ADD_TAG_ERROR_MSG_PREFIX, MAX_TAG_VALUE_LEN, key, value));
return false;
}
if (tags.size() >= MAX_TAGS) {
Logger.debug(
String.format(
"%s: maximum number of tags is %d: %s - %s",
ADD_TAG_ERROR_MSG_PREFIX, MAX_TAGS, key, value));
return false;
}
return true;
}

private String normalizeTag(Object val) {
return (val == null) ? null : String.valueOf(val);
}

private void addTagInternal(String key, String value) {
try {
Logger.debug(String.format("Adding tag: %s - %s", key, value));
if (!validateTag(key, value)) {
Logger.debug(String.format("Invalid tag not added: %s - %s", key, value));
return;
}
tags.add(
ExecutionTag.builder()
.key(normalizeTag(key))
.value(normalizeTag(value))
.build());
} catch (Exception err) {
Logger.error(String.format("%s - %s", ADD_TAG_ERROR_MSG_PREFIX, err.getMessage()));
}
}
}
8 changes: 7 additions & 1 deletion src/main/java/io/lumigo/core/SpansContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void clear() {
endFunctionSpan = null;
reporter = null;
spans = new LinkedList<>();
ExecutionTags.clear();
}

private SpansContainer() {}
Expand Down Expand Up @@ -219,6 +220,12 @@ private void end(Span endFunctionSpan) throws IOException {
.reporter_rtt(rttDuration)
.ended(System.currentTimeMillis())
.id(this.baseSpan.getId())
.info(
endFunctionSpan
.getInfo()
.toBuilder()
.tags(ExecutionTags.getTags())
.build())
.build();
reporter.reportSpans(
prepareToSend(getAllCollectedSpans(), endFunctionSpan.getError() != null),
Expand Down Expand Up @@ -430,7 +437,6 @@ public void addHttpSpan(
.statusCode(context.httpResponse().statusCode())
.build())
.build());

Logger.debug(
"Trying to extract aws custom properties for service: "
+ executionAttributes.getAttribute(SdkExecutionAttribute.SERVICE_NAME));
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/lumigo/models/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static class Info {
private String stage;
private String messageId;
private List<String> messageIds;
private List<ExecutionTag> tags;
private long approxEventCreationTime;
}

Expand Down Expand Up @@ -80,6 +81,14 @@ public static class Error {
private String stacktrace;
}

@AllArgsConstructor
@Builder(toBuilder = true)
@Data(staticConstructor = "of")
public static class ExecutionTag {
private String key;
private String value;
}

public enum READINESS {
WARM,
COLD;
Expand Down
Loading