Skip to content

Commit

Permalink
Merge branch 'open-telemetry:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AlchemyDing authored Nov 6, 2023
2 parents fcbfe9c + f811bf6 commit 668d7c4
Show file tree
Hide file tree
Showing 72 changed files with 821 additions and 56 deletions.
2 changes: 1 addition & 1 deletion benchmark-overhead/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

dependencies {
implementation(enforcedPlatform("org.junit:junit-bom:5.10.0"))
implementation(enforcedPlatform("org.junit:junit-bom:5.10.1"))

testImplementation("org.testcontainers:testcontainers:1.19.1")
testImplementation("org.testcontainers:postgresql:1.19.1")
Expand Down
2 changes: 1 addition & 1 deletion conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies {
implementation("net.ltgt.gradle:gradle-nullaway-plugin:1.6.0")
implementation("me.champeau.gradle:japicmp-gradle-plugin:0.4.2")

testImplementation(enforcedPlatform("org.junit:junit-bom:5.10.0"))
testImplementation(enforcedPlatform("org.junit:junit-bom:5.10.1"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.assertj:assertj-core:3.24.2")
Expand Down
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ val DEPENDENCY_BOMS = listOf(
"org.apache.groovy:groovy-bom:${groovyVersion}",
"io.opentelemetry:opentelemetry-bom:${otelSdkVersion}",
"io.opentelemetry:opentelemetry-bom-alpha:${otelSdkAlphaVersion}",
"org.junit:junit-bom:5.10.0",
"org.junit:junit-bom:5.10.1",
"org.testcontainers:testcontainers-bom:1.19.1",
"org.spockframework:spock-bom:2.4-M1-groovy-4.0"
)
Expand Down
1 change: 1 addition & 0 deletions docs/supported-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ These are the supported libraries and frameworks:
| [Spark Web Framework](https://github.com/perwendel/spark) | 2.3+ | N/A | Provides `http.route` [2] |
| [Spring Boot](https://spring.io/projects/spring-boot) | | [opentelemetry-spring-boot-resources](../instrumentation/spring/spring-boot-resources/library) | none |
| [Spring Batch](https://spring.io/projects/spring-batch) | 3.0+ (not including 5.0+ yet) | N/A | none |
| [Spring Cloud Gateway](https://github.com/spring-cloud/spring-cloud-gateway) | 2.0+ | N/A | Provides `http.route` [2] |
| [Spring Data](https://spring.io/projects/spring-data) | 1.8+ | N/A | none |
| [Spring Integration](https://spring.io/projects/spring-integration) | 4.1+ (not including 6.0+ yet) | [opentelemetry-spring-integration-4.1](../instrumentation/spring/spring-integration-4.1/library) | [Messaging Spans] |
| [Spring JMS](https://docs.spring.io/spring-framework/docs/current/reference/html/integration.html#jms) | 2.0+ | N/A | [Messaging Spans] |
Expand Down
2 changes: 1 addition & 1 deletion examples/distro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ subprojects {
opentelemetryJavaagentAlpha: "1.32.0-alpha-SNAPSHOT",

autoservice : "1.1.1",
junit : "5.10.0"
junit : "5.10.1"
]

deps = [
Expand Down
2 changes: 1 addition & 1 deletion examples/extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ext {
opentelemetryJavaagent : "1.32.0-SNAPSHOT",
opentelemetryJavaagentAlpha: "1.32.0-alpha-SNAPSHOT",

junit : "5.10.0"
junit : "5.10.1"
]

deps = [
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {

testImplementation("org.assertj:assertj-core:3.24.2")

testImplementation(enforcedPlatform("org.junit:junit-bom:5.10.0"))
testImplementation(enforcedPlatform("org.junit:junit-bom:5.10.1"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST,
HttpClientAttributesExtractor(HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> builder) {
super(
builder.httpAttributesGetter,
builder.netAttributesGetter,
HttpStatusCodeConverter.CLIENT,
builder.capturedRequestHeaders,
builder.capturedResponseHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ InternalNetworkAttributesExtractor<REQUEST, RESPONSE> buildNetworkExtractor() {
return new InternalNetworkAttributesExtractor<>(
netAttributesGetter,
serverAddressAndPortExtractor,
/* captureNetworkTransportAndType= */ false,
// network.{transport,type} are opt-in, network.protocol.* have HTTP-specific logic
/* captureProtocolAttributes= */ false,
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ true,
SemconvStability.emitStableHttpSemconv(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.annotation.Nullable;

Expand All @@ -34,18 +36,21 @@ abstract class HttpCommonAttributesExtractor<
implements AttributesExtractor<REQUEST, RESPONSE> {

final GETTER getter;
final NetworkAttributesGetter<REQUEST, RESPONSE> networkGetter;
private final HttpStatusCodeConverter statusCodeConverter;
private final List<String> capturedRequestHeaders;
private final List<String> capturedResponseHeaders;
private final Set<String> knownMethods;

HttpCommonAttributesExtractor(
GETTER getter,
NetworkAttributesGetter<REQUEST, RESPONSE> networkGetter,
HttpStatusCodeConverter statusCodeConverter,
List<String> capturedRequestHeaders,
List<String> capturedResponseHeaders,
Set<String> knownMethods) {
this.getter = getter;
this.networkGetter = networkGetter;
this.statusCodeConverter = statusCodeConverter;
this.capturedRequestHeaders = lowercase(capturedRequestHeaders);
this.capturedResponseHeaders = lowercase(capturedResponseHeaders);
Expand Down Expand Up @@ -143,6 +148,19 @@ public void onEnd(
}
internalSet(attributes, HttpAttributes.ERROR_TYPE, errorType);
}

if (SemconvStability.emitStableHttpSemconv()) {
String protocolName = lowercaseStr(networkGetter.getNetworkProtocolName(request, response));
String protocolVersion =
lowercaseStr(networkGetter.getNetworkProtocolVersion(request, response));

if (protocolVersion != null) {
if (!"http".equals(protocolName)) {
internalSet(attributes, SemanticAttributes.NETWORK_PROTOCOL_NAME, protocolName);
}
internalSet(attributes, SemanticAttributes.NETWORK_PROTOCOL_VERSION, protocolVersion);
}
}
}

@Nullable
Expand Down Expand Up @@ -173,4 +191,9 @@ private static Long parseNumber(@Nullable String number) {
return null;
}
}

@Nullable
private static String lowercaseStr(@Nullable String str) {
return str == null ? null : str.toLowerCase(Locale.ROOT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST,
HttpServerAttributesExtractor(HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> builder) {
super(
builder.httpAttributesGetter,
builder.netAttributesGetter,
HttpStatusCodeConverter.SERVER,
builder.capturedRequestHeaders,
builder.capturedResponseHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ InternalNetworkAttributesExtractor<REQUEST, RESPONSE> buildNetworkExtractor() {
return new InternalNetworkAttributesExtractor<>(
netAttributesGetter,
clientAddressPortExtractor,
// network.type and network.transport are opt-in
/* captureNetworkTransportAndType= */ false,
// network.{transport,type} are opt-in, network.protocol.* have HTTP-specific logic
/* captureProtocolAttributes= */ false,
// network.local.* are opt-in
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
attributes,
SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_COMPRESSED_SIZE_BYTES,
getter.getMessagePayloadCompressedSize(request));
if (operation == RECEIVE || operation == PROCESS) {
if (operation != null) {
internalSet(attributes, SemanticAttributes.MESSAGING_OPERATION, operation.operationName());
}
}
Expand Down Expand Up @@ -120,6 +120,10 @@ public void onEnd(
*/
@Override
public SpanKey internalGetSpanKey() {
if (operation == null) {
return null;
}

switch (operation) {
case PUBLISH:
return SpanKey.PRODUCER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private NetClientAttributesExtractor(NetClientAttributesGetter<REQUEST, RESPONSE
new InternalNetworkAttributesExtractor<>(
getter,
serverAddressAndPortExtractor,
/* captureNetworkTransportAndType= */ true,
/* captureProtocolAttributes= */ true,
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ true,
SemconvStability.emitStableHttpSemconv(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private NetServerAttributesExtractor(NetServerAttributesGetter<REQUEST, RESPONSE
new InternalNetworkAttributesExtractor<>(
getter,
clientAddressAndPortExtractor,
/* captureNetworkTransportAndType= */ true,
/* captureProtocolAttributes= */ true,
/* captureLocalSocketAttributes= */ true,
/* captureOldPeerDomainAttribute= */ false,
SemconvStability.emitStableHttpSemconv(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static <REQUEST, RESPONSE> NetworkAttributesExtractor<REQUEST, RESPONSE>
new InternalNetworkAttributesExtractor<>(
getter,
AddressAndPortExtractor.noop(),
/* captureNetworkTransportAndType= */ true,
/* captureProtocolAttributes= */ true,
/* captureLocalSocketAttributes= */ true,
// capture the old net.sock.peer.name attr for backwards compatibility
/* captureOldPeerDomainAttribute= */ true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class InternalNetworkAttributesExtractor<REQUEST, RESPONSE> {

private final NetworkAttributesGetter<REQUEST, RESPONSE> getter;
private final AddressAndPortExtractor<REQUEST> logicalPeerAddressAndPortExtractor;
private final boolean captureNetworkTransportAndType;
private final boolean captureProtocolAttributes;
private final boolean captureLocalSocketAttributes;
private final boolean captureOldPeerDomainAttribute;
private final boolean emitStableUrlAttributes;
Expand All @@ -32,14 +32,14 @@ public final class InternalNetworkAttributesExtractor<REQUEST, RESPONSE> {
public InternalNetworkAttributesExtractor(
NetworkAttributesGetter<REQUEST, RESPONSE> getter,
AddressAndPortExtractor<REQUEST> logicalPeerAddressAndPortExtractor,
boolean captureNetworkTransportAndType,
boolean captureProtocolAttributes,
boolean captureLocalSocketAttributes,
boolean captureOldPeerDomainAttribute,
boolean emitStableUrlAttributes,
boolean emitOldHttpAttributes) {
this.getter = getter;
this.logicalPeerAddressAndPortExtractor = logicalPeerAddressAndPortExtractor;
this.captureNetworkTransportAndType = captureNetworkTransportAndType;
this.captureProtocolAttributes = captureProtocolAttributes;
this.captureLocalSocketAttributes = captureLocalSocketAttributes;
this.captureOldPeerDomainAttribute = captureOldPeerDomainAttribute;
this.emitStableUrlAttributes = emitStableUrlAttributes;
Expand All @@ -51,15 +51,13 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO
String protocolName = lowercase(getter.getNetworkProtocolName(request, response));
String protocolVersion = lowercase(getter.getNetworkProtocolVersion(request, response));

if (emitStableUrlAttributes) {
if (emitStableUrlAttributes && captureProtocolAttributes) {
String transport = lowercase(getter.getNetworkTransport(request, response));
if (captureNetworkTransportAndType) {
internalSet(attributes, SemanticAttributes.NETWORK_TRANSPORT, transport);
internalSet(
attributes,
SemanticAttributes.NETWORK_TYPE,
lowercase(getter.getNetworkType(request, response)));
}
internalSet(attributes, SemanticAttributes.NETWORK_TRANSPORT, transport);
internalSet(
attributes,
SemanticAttributes.NETWORK_TYPE,
lowercase(getter.getNetworkType(request, response)));
internalSet(attributes, SemanticAttributes.NETWORK_PROTOCOL_NAME, protocolName);
internalSet(attributes, SemanticAttributes.NETWORK_PROTOCOL_VERSION, protocolVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static Stream<Arguments> destinations() {
void shouldExtractNoAttributesIfNoneAreAvailable() {
// given
AttributesExtractor<Map<String, String>, String> underTest =
MessagingAttributesExtractor.create(TestGetter.INSTANCE, MessageOperation.PUBLISH);
MessagingAttributesExtractor.create(TestGetter.INSTANCE, null);

Context context = Context.root();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ void normal() {
asList("654", "321")),
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ void normal() {
.containsOnly(
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ void normal() {
entry(
AttributeKey.stringArrayKey("http.response.header.custom-response-header"),
asList("654", "321")),
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"),
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
Expand Down Expand Up @@ -397,4 +396,29 @@ void shouldExtractPeerAddressEvenIfItDuplicatesServerAddress() {
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"),
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
}

@Test
void shouldExtractProtocolNameDifferentFromHttp() {
Map<String, String> request = new HashMap<>();
request.put("networkProtocolName", "spdy");
request.put("networkProtocolVersion", "3.1");

Map<String, String> response = new HashMap<>();
response.put("statusCode", "200");

AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());

AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()).isEmpty();

AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, response, null);
assertThat(endAttributes.build())
.containsOnly(
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"),
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1"));
}
}
Loading

0 comments on commit 668d7c4

Please sign in to comment.