Skip to content

Commit 99e3928

Browse files
authored
Merge branch 'main' into otelbot/code-review-spring-boot-actuator-autoconfigure-2.0-javaagent
2 parents 0c0880e + c511cf0 commit 99e3928

File tree

10 files changed

+22
-26
lines changed

10 files changed

+22
-26
lines changed
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
plugins {
22
id("otel.library-instrumentation")
33
}
4-
5-
dependencies {
6-
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
7-
}

instrumentation/servlet/servlet-common/library/src/main/java/io/opentelemetry/instrumentation/servlet/internal/ServletAdditionalAttributesExtractor.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.opentelemetry.instrumentation.servlet.internal;
77

88
import static io.opentelemetry.api.common.AttributeKey.longKey;
9-
import static io.opentelemetry.semconv.incubating.EnduserIncubatingAttributes.ENDUSER_ID;
109

1110
import io.opentelemetry.api.common.AttributeKey;
1211
import io.opentelemetry.api.common.AttributesBuilder;
@@ -23,6 +22,8 @@ public class ServletAdditionalAttributesExtractor<REQUEST, RESPONSE>
2322
implements AttributesExtractor<
2423
ServletRequestContext<REQUEST>, ServletResponseContext<RESPONSE>> {
2524

25+
// copied from EnduserIncubatingAttributes
26+
private static final AttributeKey<String> ENDUSER_ID = AttributeKey.stringKey("enduser.id");
2627
private static final AttributeKey<Long> SERVLET_TIMEOUT = longKey("servlet.timeout");
2728

2829
private final ServletAccessor<REQUEST, RESPONSE> accessor;
@@ -54,10 +55,7 @@ public void onEnd(
5455
if (captureEnduserId) {
5556
Principal principal = accessor.getRequestUserPrincipal(requestContext.request());
5657
if (principal != null) {
57-
String name = principal.getName();
58-
if (name != null) {
59-
attributes.put(ENDUSER_ID, name);
60-
}
58+
attributes.put(ENDUSER_ID, principal.getName());
6159
}
6260
}
6361
if (!captureExperimentalAttributes) {

instrumentation/servlet/servlet-common/library/src/main/java/io/opentelemetry/instrumentation/servlet/internal/ServletRequestGetter.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
package io.opentelemetry.instrumentation.servlet.internal;
77

8+
import static java.util.Collections.emptyIterator;
9+
810
import io.opentelemetry.context.propagation.TextMapGetter;
911
import java.util.Iterator;
12+
import javax.annotation.Nullable;
1013

1114
class ServletRequestGetter<REQUEST> implements TextMapGetter<ServletRequestContext<REQUEST>> {
1215
protected final ServletAccessor<REQUEST, ?> accessor;
@@ -21,12 +24,19 @@ public Iterable<String> keys(ServletRequestContext<REQUEST> carrier) {
2124
}
2225

2326
@Override
24-
public String get(ServletRequestContext<REQUEST> carrier, String key) {
27+
@Nullable
28+
public String get(@Nullable ServletRequestContext<REQUEST> carrier, String key) {
29+
if (carrier == null) {
30+
return null;
31+
}
2532
return accessor.getRequestHeader(carrier.request(), key);
2633
}
2734

2835
@Override
29-
public Iterator<String> getAll(ServletRequestContext<REQUEST> carrier, String key) {
36+
public Iterator<String> getAll(@Nullable ServletRequestContext<REQUEST> carrier, String key) {
37+
if (carrier == null) {
38+
return emptyIterator();
39+
}
3040
return accessor.getRequestHeaderValues(carrier.request(), key).iterator();
3141
}
3242
}

instrumentation/spring/spring-batch-3.0/javaagent/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ tasks {
5454
excludeTestsMatching("*CustomSpanEventTest")
5555
}
5656

57-
systemProperty("collectMetadata", findProperty("collectMetadata"))
5857
systemProperty("metadataConfig", "otel.instrumentation.spring-batch.experimental-span-attributes=true")
5958
}
6059

@@ -63,6 +62,7 @@ tasks {
6362
}
6463

6564
withType<Test>().configureEach {
65+
systemProperty("collectMetadata", findProperty("collectMetadata"))
6666
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
6767
jvmArgs("-Dotel.instrumentation.spring-batch.enabled=true")
6868
// TODO run tests both with and without experimental span attributes

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/job/JobFactoryBeanInstrumentation.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import static net.bytebuddy.matcher.ElementMatchers.isArray;
99
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
10-
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
1110
import static net.bytebuddy.matcher.ElementMatchers.named;
1211
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
1312
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@@ -33,10 +32,7 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3332
public void transform(TypeTransformer transformer) {
3433
transformer.applyAdviceToMethod(isConstructor(), this.getClass().getName() + "$InitAdvice");
3534
transformer.applyAdviceToMethod(
36-
isMethod()
37-
.and(named("setJobExecutionListeners"))
38-
.and(takesArguments(1))
39-
.and(takesArgument(0, isArray())),
35+
named("setJobExecutionListeners").and(takesArguments(1)).and(takesArgument(0, isArray())),
4036
this.getClass().getName() + "$SetListenersAdvice");
4137
}
4238

instrumentation/spring/spring-batch-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/job/JobParserJobFactoryBeanInstrumentation.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import static net.bytebuddy.matcher.ElementMatchers.isArray;
99
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
10-
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
1110
import static net.bytebuddy.matcher.ElementMatchers.named;
1211
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
1312
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@@ -34,10 +33,7 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3433
public void transform(TypeTransformer transformer) {
3534
transformer.applyAdviceToMethod(isConstructor(), this.getClass().getName() + "$InitAdvice");
3635
transformer.applyAdviceToMethod(
37-
isMethod()
38-
.and(named("setJobExecutionListeners"))
39-
.and(takesArguments(1))
40-
.and(takesArgument(0, isArray())),
36+
named("setJobExecutionListeners").and(takesArguments(1)).and(takesArgument(0, isArray())),
4137
this.getClass().getName() + "$SetListenersAdvice");
4238
}
4339

instrumentation/spring/spring-batch-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/basic/JavaConfigBatchJobTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class JavaConfigBatchJobTest extends SpringBatchTest {
1717
new ApplicationConfigRunner(
1818
() -> new AnnotationConfigApplicationContext(SpringBatchApplication.class));
1919

20-
public JavaConfigBatchJobTest() {
20+
JavaConfigBatchJobTest() {
2121
super(runner);
2222
}
2323
}

instrumentation/spring/spring-batch-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/basic/JsrConfigBatchJobTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected boolean hasPartitionManagerStep() {
1616

1717
@RegisterExtension static final JavaxBatchConfigRunner runner = new JavaxBatchConfigRunner();
1818

19-
public JsrConfigBatchJobTest() {
19+
JsrConfigBatchJobTest() {
2020
super(runner);
2121
}
2222
}

instrumentation/spring/spring-batch-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/basic/SpringBatchTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class SpringBatchTest {
2828
@RegisterExtension
2929
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
3030

31-
public SpringBatchTest(JobRunner runner) {
31+
SpringBatchTest(JobRunner runner) {
3232
this.runner = runner;
3333
}
3434

instrumentation/spring/spring-batch-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/batch/v3_0/basic/XmlConfigBatchJobTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class XmlConfigBatchJobTest extends SpringBatchTest {
1515
static final ApplicationConfigRunner runner =
1616
new ApplicationConfigRunner(() -> new ClassPathXmlApplicationContext("spring-batch.xml"));
1717

18-
public XmlConfigBatchJobTest() {
18+
XmlConfigBatchJobTest() {
1919
super(runner);
2020
}
2121
}

0 commit comments

Comments
 (0)