Skip to content

Commit

Permalink
Set 'env' to 'none' if not set or empty
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Feb 22, 2023
1 parent 17ed007 commit 11f5085
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
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

0 comments on commit 11f5085

Please sign in to comment.