Skip to content

Commit

Permalink
Addressing a set of semantic conventions deprecations and other warni…
Browse files Browse the repository at this point in the history
…ngs (#340)

* addressing a set of semantic conventions deprecations and other warnings

* spotless

* remove dead code
  • Loading branch information
breedx-splk authored May 7, 2024
1 parent 3c18984 commit ed5affa
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion android-agent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {
implementation(libs.opentelemetry.sdk)
implementation(libs.opentelemetry.exporter.logging)
implementation(libs.opentelemetry.instrumentation.api)
implementation(libs.opentelemetry.semconv)
implementation(libs.opentelemetry.semconv.incubating)
implementation(libs.opentelemetry.diskBuffering)

testImplementation(libs.robolectric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
package io.opentelemetry.android;

import static io.opentelemetry.android.common.RumConstants.RUM_SDK_VERSION;
import static io.opentelemetry.semconv.ResourceAttributes.DEVICE_MANUFACTURER;
import static io.opentelemetry.semconv.ResourceAttributes.DEVICE_MODEL_IDENTIFIER;
import static io.opentelemetry.semconv.ResourceAttributes.DEVICE_MODEL_NAME;
import static io.opentelemetry.semconv.ResourceAttributes.OS_DESCRIPTION;
import static io.opentelemetry.semconv.ResourceAttributes.OS_NAME;
import static io.opentelemetry.semconv.ResourceAttributes.OS_TYPE;
import static io.opentelemetry.semconv.ResourceAttributes.OS_VERSION;
import static io.opentelemetry.semconv.ResourceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.incubating.DeviceIncubatingAttributes.DEVICE_MANUFACTURER;
import static io.opentelemetry.semconv.incubating.DeviceIncubatingAttributes.DEVICE_MODEL_IDENTIFIER;
import static io.opentelemetry.semconv.incubating.DeviceIncubatingAttributes.DEVICE_MODEL_NAME;
import static io.opentelemetry.semconv.incubating.OsIncubatingAttributes.OS_DESCRIPTION;
import static io.opentelemetry.semconv.incubating.OsIncubatingAttributes.OS_NAME;
import static io.opentelemetry.semconv.incubating.OsIncubatingAttributes.OS_TYPE;
import static io.opentelemetry.semconv.incubating.OsIncubatingAttributes.OS_VERSION;

import android.app.Application;
import android.os.Build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,9 @@ public OpenTelemetryRumBuilder addPropagatorCustomizer(
public OpenTelemetryRumBuilder addSpanExporterCustomizer(
Function<? super SpanExporter, ? extends SpanExporter> spanExporterCustomizer) {
requireNonNull(spanExporterCustomizer, "spanExporterCustomizer");
Function<? super SpanExporter, ? extends SpanExporter> existing = spanExporterCustomizer;
this.spanExporterCustomizer =
exporter -> {
SpanExporter intermediate = existing.apply(exporter);
SpanExporter intermediate = spanExporterCustomizer.apply(exporter);
return spanExporterCustomizer.apply(intermediate);
};
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private DiskBufferingConfiguration(Builder builder) {
}

public static Builder builder() {
return new Builder(false, DEFAULT_MAX_CACHE_SIZE);
return new Builder();
}

public boolean isEnabled() {
Expand All @@ -44,16 +44,11 @@ public ExportScheduleHandler getExportScheduleHandler() {
}

public static final class Builder {
private boolean enabled;
private int maxCacheSize;
private boolean enabled = false;
private int maxCacheSize = DEFAULT_MAX_CACHE_SIZE;
private ExportScheduleHandler exportScheduleHandler =
new DefaultExportScheduleHandler(new DefaultExportScheduler());

private Builder(boolean enabled, int maxCacheSize) {
this.enabled = enabled;
this.maxCacheSize = maxCacheSize;
}

/** Enables or disables disk buffering. */
public Builder setEnabled(boolean enabled) {
this.enabled = enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SignalFromDiskExporter
private val exportTimeoutInMillis: Long = TimeUnit.SECONDS.toMillis(5),
) {
/**
* A batch contains all the signals that arrived in one call to [SpanDiskExporter.export]. So if
* A batch contains all the signals that arrived in one call to [SpanFromDiskExporter.exportStoredBatch]. So if
* that function is called 5 times, then there will be 5 batches in disk. This function reads
* and exports ONE batch every time is called.
*
Expand All @@ -41,7 +41,7 @@ class SignalFromDiskExporter
}

/**
* A batch contains all the signals that arrived in one call to [MetricDiskExporter.export]. So if
* A batch contains all the signals that arrived in one call to [MetricFromDiskExporter.exportStoredBatch]. So if
* that function is called 5 times, then there will be 5 batches in disk. This function reads
* and exports ONE batch every time is called.
*
Expand All @@ -58,7 +58,7 @@ class SignalFromDiskExporter
}

/**
* A batch contains all the signals that arrived in one call to [LogRecordDiskExporter.export]. So if
* A batch contains all the signals that arrived in one call to [LogRecordFromDiskExporter.exportStoredBatch]. So if
* that function is called 5 times, then there will be 5 batches in disk. This function reads
* and exports ONE batch every time is called.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tasks {
options.errorprone {
if (name.lowercase(Locale.getDefault()).contains("test")) {
// just disable all error prone checks for test
isEnabled.set(false);
isEnabled.set(false)
isCompilingTestOnlyCode.set(true)
} else {
if (isAndroidProject) {
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ opentelemetry-instrumentation-api = { module = "io.opentelemetry.instrumentation
opentelemetry-instrumentation-apiSemconv = { module = "io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator" }
opentelemetry-instrumentation-okhttp = { module = "io.opentelemetry.instrumentation:opentelemetry-okhttp-3.0", version.ref = "opentelemetry-instrumentation-alpha" }
opentelemetry-semconv = { module = "io.opentelemetry.semconv:opentelemetry-semconv", version.ref = "opentelemetry-semconv" }
opentelemetry-semconv-incubating = { module = "io.opentelemetry.semconv:opentelemetry-semconv-incubating", version.ref = "opentelemetry-semconv" }
opentelemetry-api = { module = "io.opentelemetry:opentelemetry-api" }
opentelemetry-sdk = { module = "io.opentelemetry:opentelemetry-sdk" }
opentelemetry-exporter-logging = { module = "io.opentelemetry:opentelemetry-exporter-logging" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public ActivityTracer addEvent(String eventName) {
return this;
}

public static Builder builder(Activity activity) {
static Builder builder(Activity activity) {
return new Builder(activity);
}

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

package io.opentelemetry.android.instrumentation.anr;

import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_STACKTRACE;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/crash/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
api(libs.opentelemetry.api)
api(project(":instrumentation:common-api"))
implementation(libs.androidx.core)
implementation(libs.opentelemetry.semconv)
implementation(libs.opentelemetry.semconv.incubating)
implementation(libs.opentelemetry.sdk)
implementation(libs.opentelemetry.instrumentation.api)
testImplementation(libs.awaitility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

package io.opentelemetry.android.instrumentation.crash;

import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_ESCAPED;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE;
import static io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes.*;

import io.opentelemetry.android.instrumentation.common.InstrumentedApplication;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.logs.Logger;
import io.opentelemetry.api.logs.LoggerProvider;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.SemanticAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
Expand Down Expand Up @@ -58,12 +63,12 @@ private void emitCrashEvent(Logger crashReporter, CrashDetails crashDetails) {
Thread thread = crashDetails.getThread();
AttributesBuilder attributesBuilder =
Attributes.builder()
.put(SemanticAttributes.EXCEPTION_ESCAPED, true)
.put(SemanticAttributes.THREAD_ID, thread.getId())
.put(SemanticAttributes.THREAD_NAME, thread.getName())
.put(SemanticAttributes.EXCEPTION_MESSAGE, throwable.getMessage())
.put(SemanticAttributes.EXCEPTION_STACKTRACE, stackTraceToString(throwable))
.put(SemanticAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
.put(EXCEPTION_ESCAPED, true)
.put(THREAD_ID, thread.getId())
.put(THREAD_NAME, thread.getName())
.put(EXCEPTION_MESSAGE, throwable.getMessage())
.put(EXCEPTION_STACKTRACE, stackTraceToString(throwable))
.put(EXCEPTION_TYPE, throwable.getClass().getName());

for (AttributesExtractor<CrashDetails, Void> extractor : additionalExtractors) {
extractor.onStart(attributesBuilder, Context.current(), crashDetails);
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
api(project(":common"))
api(project(":instrumentation:common-api"))
implementation(libs.androidx.core)
implementation(libs.opentelemetry.semconv)
implementation(libs.opentelemetry.semconv.incubating)
implementation(libs.opentelemetry.sdk)
implementation(libs.opentelemetry.instrumentation.api)
testImplementation(libs.robolectric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

package io.opentelemetry.android.instrumentation.network;

import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CARRIER_ICC;
import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CARRIER_MCC;
import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CARRIER_MNC;
import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CARRIER_NAME;
import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CONNECTION_SUBTYPE;
import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CONNECTION_TYPE;
import static io.opentelemetry.semconv.incubating.NetworkIncubatingAttributes.NETWORK_CARRIER_ICC;
import static io.opentelemetry.semconv.incubating.NetworkIncubatingAttributes.NETWORK_CARRIER_MCC;
import static io.opentelemetry.semconv.incubating.NetworkIncubatingAttributes.NETWORK_CARRIER_MNC;
import static io.opentelemetry.semconv.incubating.NetworkIncubatingAttributes.NETWORK_CARRIER_NAME;
import static io.opentelemetry.semconv.incubating.NetworkIncubatingAttributes.NETWORK_CONNECTION_SUBTYPE;
import static io.opentelemetry.semconv.incubating.NetworkIncubatingAttributes.NETWORK_CONNECTION_TYPE;

import androidx.annotation.Nullable;
import io.opentelemetry.api.common.AttributeKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.android.instrumentation.network;

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CONNECTION_TYPE;
import static io.opentelemetry.semconv.incubating.NetworkIncubatingAttributes.NETWORK_CONNECTION_TYPE;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

package io.opentelemetry.android.instrumentation.network;

import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.NetworkIncubatingAttributes.NetworkConnectionTypeValues;

enum NetworkState {
NO_NETWORK_AVAILABLE(SemanticAttributes.NetworkConnectionTypeValues.UNAVAILABLE),
TRANSPORT_CELLULAR(SemanticAttributes.NetworkConnectionTypeValues.CELL),
TRANSPORT_WIFI(SemanticAttributes.NetworkConnectionTypeValues.WIFI),
TRANSPORT_UNKNOWN(SemanticAttributes.NetworkConnectionTypeValues.UNKNOWN),
NO_NETWORK_AVAILABLE(NetworkConnectionTypeValues.UNAVAILABLE),
TRANSPORT_CELLULAR(NetworkConnectionTypeValues.CELL),
TRANSPORT_WIFI(NetworkConnectionTypeValues.WIFI),
TRANSPORT_UNKNOWN(NetworkConnectionTypeValues.UNKNOWN),
// this one doesn't seem to have an otel value at this point.
TRANSPORT_VPN("vpn");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CurrentNetwork detectCurrentNetwork() {
Carrier carrier = carrierFinder.get();
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
// If the app has the permission, use it to get a subtype.
if (hasPermission(Manifest.permission.READ_PHONE_STATE)) {
if (canReadPhoneState()) {
subType = getDataNetworkTypeName(telephonyManager.getDataNetworkType());
}
return CurrentNetwork.builder(NetworkState.TRANSPORT_CELLULAR)
Expand All @@ -66,8 +66,8 @@ public CurrentNetwork detectCurrentNetwork() {
}

// visible for testing
boolean hasPermission(String permission) {
return ActivityCompat.checkSelfPermission(context, permission)
boolean canReadPhoneState() {
return ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)
== PackageManager.PERMISSION_GRANTED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void cellular_noTelephonyPermissions() {
new PostApi28NetworkDetector(
connectivityManager, telephonyManager, carrierFinder, context) {
@Override
boolean hasPermission(String permission) {
boolean canReadPhoneState() {
return false;
}
};
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/volley/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.navigation.fragment)
implementation(libs.opentelemetry.instrumentation.api)
implementation(libs.opentelemetry.semconv)
implementation(libs.opentelemetry.semconv.incubating)
compileOnly(libs.volley)
coreLibraryDesugaring(libs.desugarJdkLibs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public List<String> getHttpResponseHeader(
}

static List<String> headersToList(List<Header> headers, String name) {
if (headers.size() == 0) {
if (headers.isEmpty()) {
return emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

package io.opentelemetry.android.instrumentation.volley;

import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.*;

import androidx.annotation.Nullable;
import com.android.volley.Header;
import com.android.volley.toolbox.HttpResponse;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.SemanticAttributes;

class VolleyResponseAttributesExtractor
implements AttributesExtractor<RequestWrapper, HttpResponse> {
Expand All @@ -37,9 +38,7 @@ private void onResponse(AttributesBuilder attributes, HttpResponse response) {
if (header.getName().equals("Content-Length")) {
String contentLength = header.getValue();
if (contentLength != null) {
attributes.put(
SemanticAttributes.HTTP_RESPONSE_BODY_SIZE,
Long.parseLong(contentLength));
attributes.put(HTTP_RESPONSE_BODY_SIZE, Long.parseLong(contentLength));
}
}
}
Expand Down

0 comments on commit ed5affa

Please sign in to comment.