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

Set 'env' to 'none' if not set or empty #4765

Merged
Merged
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 @@ -47,9 +47,7 @@ private void process(DDSpan span) {
span.setResourceName(span.getOperationName());
}

if (span.getTag("env") != null) {
span.setTag("env", TraceUtils.normalizeEnv((String) span.getTag("env")));
}
span.setTag("env", TraceUtils.normalizeEnv((String) span.getTag("env")));

final short httpStatusCode = span.getHttpStatusCode();
if (httpStatusCode != 0 && !isValidStatusCode(httpStatusCode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,18 @@ class DDIntakeTraceInterceptorTest extends DDCoreSpecification {
def span = trace[0]
span.type == originalSpanType
}

def "test default env setting"() {
setup:
tracer.buildSpan("my-operation-name").start().finish()
writer.waitForTraces(1)

expect:
def trace = writer.firstTrace()
trace.size() == 1

def span = trace[0]

span.getTag("env") == "none"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TraceUtils {

static final String DEFAULT_SERVICE_NAME = "unnamed-service";
static final String DEFAULT_OPERATION_NAME = "unnamed_operation";
static final String DEFAULT_ENV = "none";

private static final Logger log = LoggerFactory.getLogger(TraceUtils.class);

Expand Down Expand Up @@ -73,7 +74,7 @@ public static CharSequence normalizeSpanType(final CharSequence spanType) {

public static String normalizeEnv(final String env) {
if (env == null || env.length() == 0) {
return "";
return DEFAULT_ENV;
}

String e = truncate(env, MAX_ENV_LEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class TraceUtilsTest extends DDSpecification {

where:
env | expected
null | ""
"" | ""
null | TraceUtils.DEFAULT_ENV
"" | TraceUtils.DEFAULT_ENV
"ok" | "ok"
repeat("a",300)|repeat("a",200)
}
Expand Down