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

Rename the Server-Timing header property #185

Merged
merged 1 commit into from
Apr 7, 2021
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
2 changes: 1 addition & 1 deletion bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ compileJava {

dependencies {
// slf4j is included in the otel javaagent, no need to add it here too
compileOnly "org.slf4j:slf4j-api:1.7.30"
compileOnly deps.slf4j
// add micrometer to the bootstrap classloader so that it's available in instrumentations
implementation "io.micrometer:micrometer-core:${versions.micrometer}"
}
1 change: 1 addition & 0 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ext {
"com.google.auto.service:auto-service:1.0-rc7",
"com.google.auto:auto-common:0.8"
],
slf4j : "org.slf4j:slf4j-api:1.7.30",

// test
assertj : "org.assertj:assertj-core:3.19.0",
Expand Down
2 changes: 2 additions & 0 deletions instrumentation/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ plugins {
}

dependencies {
compileOnly deps.slf4j
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:${versions.opentelemetryJavaagentAlpha}")
compileOnly("io.opentelemetry:opentelemetry-api:${versions.opentelemetry}")

testImplementation deps.slf4j
testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common:${versions.opentelemetryJavaagentAlpha}")
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@
import io.opentelemetry.instrumentation.api.config.Config;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Adds {@code Server-Timing} header (and {@code Access-Control-Expose-Headers}) to the HTTP
* response. The {@code Server-Timing} header contains the traceId and spanId of the server span.
*/
public final class ServerTimingHeader {
private static final Logger log = LoggerFactory.getLogger(ServerTimingHeader.class);

public static final String SERVER_TIMING = "Server-Timing";
public static final String EXPOSE_HEADERS = "Access-Control-Expose-Headers";

private static final String EMIT_RESPONSE_HEADERS_OLD = "splunk.context.server-timing.enabled";
private static final String EMIT_RESPONSE_HEADERS = "splunk.trace-response-header.enabled";

public static boolean shouldEmitServerTimingHeader() {
return Config.get().getBooleanProperty("splunk.context.server-timing.enabled", false);
return ConfigHolder.SHOULD_EMIT_RESPONSE_HEADERS;
}

public static <RS> void setHeaders(Context context, RS response, TextMapSetter<RS> headerSetter) {
Expand All @@ -52,4 +59,22 @@ private static String toHeaderValue(Context context) {
}

private ServerTimingHeader() {}

// tests didn't like using Config in ServerTimingHeader.<clinit>
static class ConfigHolder {
private static final boolean SHOULD_EMIT_RESPONSE_HEADERS;

static {
Config config = Config.get();
if (config.getProperty(EMIT_RESPONSE_HEADERS_OLD) != null) {
log.warn(
"Deprecated property '{}' was set; please use '{}' instead. Support for the deprecated property will be removed in future versions.",
EMIT_RESPONSE_HEADERS_OLD,
EMIT_RESPONSE_HEADERS);
}
SHOULD_EMIT_RESPONSE_HEADERS =
config.getBooleanProperty(
EMIT_RESPONSE_HEADERS, config.getBooleanProperty(EMIT_RESPONSE_HEADERS_OLD, true));
}
}
}
4 changes: 0 additions & 4 deletions instrumentation/netty-3.8/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ dependencies {

testImplementation group: 'io.netty', name: 'netty', version: '3.8.0.Final'
}

tasks.withType(Test) {
jvmArgs '-Dsplunk.context.server-timing.enabled=true'
}
4 changes: 0 additions & 4 deletions instrumentation/netty-4.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ dependencies {

testImplementation group: 'io.netty', name: 'netty-codec-http', version: '4.0.0.Final'
}

tasks.withType(Test) {
jvmArgs '-Dsplunk.context.server-timing.enabled=true'
}
4 changes: 0 additions & 4 deletions instrumentation/servlet-3-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ dependencies {
testImplementation group: 'org.eclipse.jetty', name: 'jetty-server', version: '8.0.0.v20110901'
testImplementation group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '8.0.0.v20110901'
}

tasks.withType(Test) {
jvmArgs '-Dsplunk.context.server-timing.enabled=true'
}
4 changes: 0 additions & 4 deletions instrumentation/servlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@ dependencies {
}
}
}

tasks.withType(Test) {
jvmArgs '-Dsplunk.context.server-timing.enabled=true'
}