Skip to content

Commit

Permalink
update to new http semconv
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Dec 15, 2023
1 parent 5d0957b commit 402946a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api")
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv")
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api")
compileOnly("io.opentelemetry.semconv:opentelemetry-semconv")
annotationProcessor("com.google.auto.service:auto-service")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.contrib.sampler.RuleBasedRoutingSampler;
import io.opentelemetry.contrib.sampler.RuleBasedRoutingSamplerBuilder;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider;
import io.opentelemetry.sdk.trace.samplers.Sampler;
Expand Down Expand Up @@ -52,11 +51,8 @@ public Sampler createSampler(ConfigProperties config) {
return builder.build();
}

@SuppressWarnings("deprecation") // old semconv still used
private AttributeKey<String> getHttpPathAttribute() {
return SemconvStability.emitOldHttpSemconv()
? SemanticAttributes.HTTP_TARGET
: SemanticAttributes.URL_PATH;
return SemanticAttributes.URL_PATH;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import io.opentelemetry.semconv.SemanticAttributes;
import java.net.InetSocketAddress;
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -64,11 +62,6 @@ public List<String> getHttpResponseHeader(
return header != null ? singletonList(header) : emptyList();
}

@Override
public String getTransport(RequestWrapper requestWrapper, @Nullable Response response) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}

@Nullable
@Override
public String getServerAddress(RequestWrapper requestWrapper) {
Expand Down Expand Up @@ -100,16 +93,4 @@ public String getNetworkProtocolName(RequestWrapper requestWrapper, @Nullable Re
public String getNetworkTransport(RequestWrapper requestWrapper, @Nullable Response response) {
return "tcp";
}

@Nullable
@Override
public InetSocketAddress getServerInetSocketAddress(
RequestWrapper requestWrapper, @Nullable Response response) {
String host = getServerAddress(requestWrapper);
Integer port = getServerPort(requestWrapper);
if (host == null || port == null) {
return null;
}
return new InetSocketAddress(host, port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package com.splunk.opentelemetry.instrumentation.khttp;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import khttp.responses.Response;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class KHttpClientTest extends HttpClientTest<Void> implements AgentTestTrait {

Set<AttributeKey<?>> httpAttributes(URI uri) {
def attributes = super.httpAttributes(uri)
attributes.remove(stringKey("net.protocol.name"))
attributes.remove(stringKey("net.protocol.version"))
attributes.remove(stringKey("network.protocol.version"))
return attributes
}
}

0 comments on commit 402946a

Please sign in to comment.