Skip to content

Commit

Permalink
Bump opentelemetry java sdk version and add new semconv dependency (#217
Browse files Browse the repository at this point in the history
)

* Bumping OTel sdk and adding semconv lib

* Updating unit tests

* Updating changelog

* Updated notice files
  • Loading branch information
LikeTheSalad authored Oct 27, 2023
1 parent ad337e2 commit 86355d0
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 63 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ${next_release_notes}
* Removing Gradle's warning on missing serverUrl param: {pull}209[#209]
* Adding http response content length attr to okhttp spans: {pull}211[#211]
* Marking okhttp spans as failed when receiving an error response code: {pull}212[#212]
* Bumping OTel SDK to 1.31.0 and adding new semconv dependency: {pull}217[#217]
////
[[release-notes-0.9.0]]
Expand Down
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This product includes software licensed under the 'Apache License Version 2.0' l
- okhttp (https://square.github.io/okhttp/)
- OpenTelemetry Java (https://github.com/open-telemetry/opentelemetry-java)
- OpenTelemetry Java Contrib (https://github.com/open-telemetry/opentelemetry-java-contrib)
- OpenTelemetry Semantic Conventions Java (https://github.com/open-telemetry/semantic-conventions-java)
- org.stagemonitor:stagemonitor-configuration (http://www.stagemonitor.org)
- Weakly referenced lock-free data structures (https://github.com/raphw/weak-lock-free)

Expand Down
2 changes: 1 addition & 1 deletion android-sdk-ktx/metadata/notice.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dependencies.hash=83E0E6D9CD40065C79FADBCA67A5607B
dependencies.hash=81F0B6D19D5388F15DBE3E189D6C1B22
2 changes: 1 addition & 1 deletion android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
implementation 'com.blogspot.mydailyjava:weak-lock-free:0.18'
implementation project(':android-common')
implementation "io.opentelemetry:opentelemetry-exporter-otlp:$openTelemetry_version"
implementation "io.opentelemetry:opentelemetry-semconv:$openTelemetry_version-alpha"
implementation "io.opentelemetry.semconv:opentelemetry-semconv:1.21.0-alpha"
implementation "io.opentelemetry.contrib:opentelemetry-disk-buffering:$openTelemetry_version-alpha"
implementation "androidx.annotation:annotation:$androidAnnotations_version"
implementation 'com.dslplatform:dsl-json-java8:1.10.0'
Expand Down
2 changes: 1 addition & 1 deletion android-sdk/metadata/notice.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dependencies.hash=553460B56887EDB98C3A019266F71C55
dependencies.hash=81E0A693875E87899494D84AB8C8D79D
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import co.elastic.apm.android.sdk.internal.services.network.data.CarrierInfo;
import co.elastic.apm.android.sdk.internal.utilities.providers.Provider;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;

public class CarrierHttpAttributesVisitor implements AttributesVisitor {
private final Provider<NetworkService> networkServiceProvider;
Expand All @@ -38,10 +38,10 @@ public CarrierHttpAttributesVisitor() {
public void visit(AttributesBuilder builder) {
CarrierInfo carrierInfo = networkServiceProvider.get().getCarrierInfo();
if (carrierInfo != null) {
builder.put(SemanticAttributes.NET_HOST_CARRIER_NAME, carrierInfo.name);
builder.put(SemanticAttributes.NET_HOST_CARRIER_MCC, carrierInfo.mcc);
builder.put(SemanticAttributes.NET_HOST_CARRIER_MNC, carrierInfo.mnc);
builder.put(SemanticAttributes.NET_HOST_CARRIER_ICC, carrierInfo.icc);
builder.put(SemanticAttributes.NETWORK_CARRIER_NAME, carrierInfo.name);
builder.put(SemanticAttributes.NETWORK_CARRIER_MCC, carrierInfo.mcc);
builder.put(SemanticAttributes.NETWORK_CARRIER_MNC, carrierInfo.mnc);
builder.put(SemanticAttributes.NETWORK_CARRIER_ICC, carrierInfo.icc);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import co.elastic.apm.android.sdk.internal.services.network.NetworkService;
import co.elastic.apm.android.sdk.internal.services.network.data.type.NetworkType;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;

public class ConnectionHttpAttributesVisitor implements AttributesVisitor {
private final NetworkService networkService;
Expand All @@ -48,9 +48,9 @@ private ConnectionHttpAttributesVisitor() {
@Override
public void visit(AttributesBuilder builder) {
NetworkType networkType = networkService.getType();
builder.put(SemanticAttributes.NET_HOST_CONNECTION_TYPE, networkType.getName());
builder.put(SemanticAttributes.NETWORK_CONNECTION_TYPE, networkType.getName());
if (networkType.getSubTypeName() != null) {
builder.put(SemanticAttributes.NET_HOST_CONNECTION_SUBTYPE, networkType.getSubTypeName());
builder.put(SemanticAttributes.NETWORK_CONNECTION_SUBTYPE, networkType.getSubTypeName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import co.elastic.apm.android.sdk.internal.services.ServiceManager;
import co.elastic.apm.android.sdk.internal.services.preferences.PreferencesService;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.ResourceAttributes;

public class DeviceIdVisitor implements AttributesVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import co.elastic.apm.android.sdk.attributes.AttributesVisitor;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.ResourceAttributes;

public class DeviceInfoVisitor implements AttributesVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import co.elastic.apm.android.sdk.attributes.AttributesVisitor;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.ResourceAttributes;

public class OsDescriptorVisitor implements AttributesVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.elastic.apm.android.sdk.attributes.AttributesVisitor;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.ResourceAttributes;

public class RuntimeDescriptorVisitor implements AttributesVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import co.elastic.apm.android.sdk.BuildConfig;
import co.elastic.apm.android.sdk.attributes.AttributesVisitor;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.ResourceAttributes;

public class SdkIdVisitor implements AttributesVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import co.elastic.apm.android.sdk.internal.services.appinfo.AppInfoService;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.ResourceAttributes;

public class ServiceIdVisitor implements AttributesVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import co.elastic.apm.android.sdk.logs.ElasticEvents;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.events.EventEmitter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;

public final class ElasticExceptionHandler implements Thread.UncaughtExceptionHandler {
private final Thread.UncaughtExceptionHandler wrapped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/
package co.elastic.apm.android.sdk.internal.opentelemetry.processors.logs;

import androidx.annotation.NonNull;

import org.slf4j.Logger;

import co.elastic.apm.android.common.internal.logging.Elog;
import co.elastic.apm.android.sdk.attributes.AttributesCreator;
import co.elastic.apm.android.sdk.attributes.AttributesVisitor;
import co.elastic.apm.android.sdk.instrumentation.Instrumentation;
import co.elastic.apm.android.sdk.instrumentation.Instrumentations;
import co.elastic.apm.android.sdk.internal.api.filter.Filter;
import co.elastic.apm.android.sdk.internal.configuration.Configurations;
import co.elastic.apm.android.sdk.internal.configuration.impl.AllInstrumentationConfiguration;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
Expand All @@ -48,7 +48,7 @@ public ElasticLogRecordProcessor(LogRecordProcessor original, AttributesVisitor
}

@Override
public void onEmit(Context context, ReadWriteLogRecord logRecord) {
public void onEmit(@NonNull Context context, @NonNull ReadWriteLogRecord logRecord) {
if (!Instrumentation.isEnabled(AllInstrumentationConfiguration.class)) {
Elog.getLogger().debug("Ignoring all log records");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package co.elastic.apm.android.sdk.internal.opentelemetry.processors.metrics;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -33,7 +35,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.export.CollectionRegistration;
import io.opentelemetry.sdk.metrics.export.MetricReader;
import io.opentelemetry.sdk.metrics.internal.export.MetricProducer;

public final class ElasticMetricReader implements MetricReader {
private final MetricReader wrapped;
Expand All @@ -44,12 +45,8 @@ public ElasticMetricReader(MetricReader wrapped) {
}

@Override
public void register(CollectionRegistration registration) {
if (registration instanceof MetricProducer) {
wrapped.register(new ElasticMetricProducer((MetricProducer) registration, filter));
} else {
wrapped.register(registration);
}
public void register(@NonNull CollectionRegistration registration) {
wrapped.register(new ElasticCollectionRegistration(registration, filter));
}

@Override
Expand All @@ -67,11 +64,11 @@ public AggregationTemporality getAggregationTemporality(InstrumentType instrumen
return wrapped.getAggregationTemporality(instrumentType);
}

private static class ElasticMetricProducer implements MetricProducer {
private final MetricProducer wrapped;
private static class ElasticCollectionRegistration implements CollectionRegistration {
private final CollectionRegistration wrapped;
private final Filter<MetricData> filter;

private ElasticMetricProducer(MetricProducer wrapped, Filter<MetricData> filter) {
private ElasticCollectionRegistration(CollectionRegistration wrapped, Filter<MetricData> filter) {
this.wrapped = wrapped;
this.filter = filter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import co.elastic.apm.android.sdk.traces.http.attributes.HttpAttributesVisitor;
import co.elastic.apm.android.sdk.traces.http.data.HttpRequest;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;

public class BasicHttpAttributesVisitor implements HttpAttributesVisitor {

@Override
public void visit(AttributesBuilder builder, HttpRequest request) {
builder.put(SemanticAttributes.HTTP_URL, request.url.toString())
.put(SemanticAttributes.HTTP_METHOD, request.method);
builder.put(SemanticAttributes.URL_FULL, request.url.toString())
.put(SemanticAttributes.HTTP_REQUEST_METHOD, request.method);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
import java.net.MalformedURLException;
import java.net.URL;

import co.elastic.apm.android.sdk.traces.tools.SpanFilter;
import co.elastic.apm.android.sdk.traces.http.data.HttpRequest;
import co.elastic.apm.android.sdk.traces.tools.SpanFilter;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;

abstract public class HttpFilter implements SpanFilter {

@Override
public boolean shouldInclude(ReadableSpan item) {
String httpMethod = item.getAttribute(SemanticAttributes.HTTP_METHOD);
String httpMethod = item.getAttribute(SemanticAttributes.HTTP_REQUEST_METHOD);
if (httpMethod == null) {
// Not an http-related Span.
return false;
Expand All @@ -42,7 +42,7 @@ public boolean shouldInclude(ReadableSpan item) {
}

private URL getUrl(ReadableSpan span) {
String urlString = span.getAttribute(SemanticAttributes.HTTP_URL);
String urlString = span.getAttribute(SemanticAttributes.URL_FULL);
try {
return new URL(urlString);
} catch (MalformedURLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;
import okhttp3.Call;
import okhttp3.EventListener;
import okhttp3.HttpUrl;
Expand Down Expand Up @@ -133,12 +133,12 @@ public void responseHeadersEnd(@NonNull Call call, @NonNull Response response) {
private static void setResponseSize(@NonNull Response response, Span span) {
String contentLength = response.header("Content-Length");
if (contentLength != null) {
span.setAttribute(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, Long.valueOf(contentLength));
span.setAttribute(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, Long.valueOf(contentLength));
}
}

private static void setStatusCode(Span span, int code) {
span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, code);
span.setAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, code);
}

private static boolean isHttpError(int code) {
Expand Down
1 change: 1 addition & 0 deletions android-sdk/src/main/resources/META-INF/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This product includes software licensed under the 'Apache License Version 2.0' l
- okhttp (https://square.github.io/okhttp/)
- OpenTelemetry Java (https://github.com/open-telemetry/opentelemetry-java)
- OpenTelemetry Java Contrib (https://github.com/open-telemetry/opentelemetry-java-contrib)
- OpenTelemetry Semantic Conventions Java (https://github.com/open-telemetry/semantic-conventions-java)
- org.stagemonitor:stagemonitor-configuration (http://www.stagemonitor.org)
- Weakly referenced lock-free data structures (https://github.com/raphw/weak-lock-free)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void whenALogIsCreated_andThereIsWifiConnectivity_verifyItHasWifiConnecti
LogRecordData log = captureLog();

Logs.verifyRecord(log)
.hasAttribute("net.host.connection.type", "wifi");
.hasAttribute("network.connection.type", "wifi");
}

@Config(application = AppsWithConnectivity.WithCellular.class)
Expand All @@ -33,7 +33,7 @@ public void whenALogIsCreated_andThereIsCellularConnectivity_verifyItHasCellular
LogRecordData log = captureLog();

Logs.verifyRecord(log)
.hasAttribute("net.host.connection.type", "cell");
.hasAttribute("network.connection.type", "cell");
}

@Config(application = AppsWithConnectivity.WithCellularAndSubtype.class)
Expand All @@ -42,8 +42,8 @@ public void whenALogIsCreated_andThereIsCellularConnectivityWithSubtype_verifyIt
LogRecordData log = captureLog();

Logs.verifyRecord(log)
.hasAttribute("net.host.connection.type", "cell")
.hasAttribute("net.host.connection.subtype", "EDGE");
.hasAttribute("network.connection.type", "cell")
.hasAttribute("network.connection.subtype", "EDGE");
}

private LogRecordData captureLog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public void whenASpanIsCreated_verifyItHasCarrierInfoParams() {
SpanData customSpan = getSpanData();

Spans.verify(customSpan)
.hasAttribute("net.host.carrier.name", AppWithCarrierInfo.SIM_OPERATOR_NAME)
.hasAttribute("net.host.carrier.mcc", "123")
.hasAttribute("net.host.carrier.mnc", "456")
.hasAttribute("net.host.carrier.icc", AppWithCarrierInfo.SIM_COUNTRY_ISO);
.hasAttribute("network.carrier.name", AppWithCarrierInfo.SIM_OPERATOR_NAME)
.hasAttribute("network.carrier.mcc", "123")
.hasAttribute("network.carrier.mnc", "456")
.hasAttribute("network.carrier.icc", AppWithCarrierInfo.SIM_COUNTRY_ISO);
}

@Config(application = AppsWithConnectivity.WithWifi.class)
Expand All @@ -52,7 +52,7 @@ public void whenASpanIsCreated_andThereIsAWifiConnection_verifyItHasWifiConnecti
SpanData span = getSpanData();

Spans.verify(span)
.hasAttribute("net.host.connection.type", "wifi");
.hasAttribute("network.connection.type", "wifi");
}

@Config(application = AppsWithConnectivity.WithCellular.class)
Expand All @@ -61,7 +61,7 @@ public void whenASpanIsCreated_andThereIsAMobileConnection_verifyItHasMobileConn
SpanData span = getSpanData();

Spans.verify(span)
.hasAttribute("net.host.connection.type", "cell");
.hasAttribute("network.connection.type", "cell");
}

@Config(application = AppsWithConnectivity.WithCellularAndSubtype.class)
Expand All @@ -70,8 +70,8 @@ public void whenASpanIsCreated_andThereIsAMobileConnectionWithSubtype_verifyItHa
SpanData span = getSpanData();

Spans.verify(span)
.hasAttribute("net.host.connection.type", "cell")
.hasAttribute("net.host.connection.subtype", "EDGE");
.hasAttribute("network.connection.type", "cell")
.hasAttribute("network.connection.subtype", "EDGE");
}

private SpanData getSpanData() {
Expand Down
Loading

0 comments on commit 86355d0

Please sign in to comment.