Skip to content

Commit

Permalink
Added os.description resource attribute and updated AndroidResourceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhiia committed Aug 24, 2023
1 parent 28444b1 commit 3ad5c83
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.DEVICE_MANUFACTURER;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.DEVICE_MODEL_IDENTIFIER;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.DEVICE_MODEL_NAME;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.OS_DESCRIPTION;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.OS_NAME;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.OS_TYPE;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.OS_VERSION;
Expand All @@ -35,6 +36,7 @@ static Resource createDefault(Application application) {
.put(OS_NAME, "Android")
.put(OS_TYPE, "linux")
.put(OS_VERSION, Build.VERSION.RELEASE)
.put(OS_DESCRIPTION, getOSDescription())
.build();
}

Expand Down Expand Up @@ -68,4 +70,14 @@ private static String trapTo(Supplier<String> fn, String defaultValue) {
return defaultValue;
}
}

private static String getOSDescription() {
StringBuilder OSDescriptionBuilder = new StringBuilder();
return OSDescriptionBuilder.append("Android Version ")
.append(Build.VERSION.RELEASE)
.append(" (Build ")
.append(Build.ID)
.append(")")
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
package io.opentelemetry.android;

import static io.opentelemetry.android.RumConstants.RUM_SDK_VERSION;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.DEVICE_MANUFACTURER;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.DEVICE_MODEL_IDENTIFIER;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.DEVICE_MODEL_NAME;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.OS_DESCRIPTION;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.OS_NAME;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.OS_TYPE;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.OS_VERSION;
Expand All @@ -30,6 +32,14 @@ class AndroidResourceTest {

String appName = "robotron";
String rumSdkVersion = "1.2.3";
String osDescription =
new StringBuilder()
.append("Android Version ")
.append(Build.VERSION.RELEASE)
.append(" (Build ")
.append(Build.ID)
.append(")")
.toString();

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
Application app;
Expand All @@ -38,6 +48,7 @@ class AndroidResourceTest {
void testFullResource() {
ApplicationInfo appInfo = new ApplicationInfo();
appInfo.labelRes = 12345;

when(app.getApplicationContext().getApplicationInfo()).thenReturn(appInfo);
when(app.getApplicationContext().getString(appInfo.labelRes)).thenReturn(appName);
when(app.getApplicationContext().getResources().getString(R.string.rum_version))
Expand All @@ -51,9 +62,11 @@ void testFullResource() {
.put(RUM_SDK_VERSION, rumSdkVersion)
.put(DEVICE_MODEL_NAME, Build.MODEL)
.put(DEVICE_MODEL_IDENTIFIER, Build.MODEL)
.put(DEVICE_MANUFACTURER, Build.MANUFACTURER)
.put(OS_NAME, "Android")
.put(OS_TYPE, "linux")
.put(OS_VERSION, Build.VERSION.RELEASE)
.put(OS_DESCRIPTION, osDescription)
.build());

Resource result = AndroidResource.createDefault(app);
Expand All @@ -74,9 +87,11 @@ void testProblematicContext() {
.put(RUM_SDK_VERSION, "unknown")
.put(DEVICE_MODEL_NAME, Build.MODEL)
.put(DEVICE_MODEL_IDENTIFIER, Build.MODEL)
.put(DEVICE_MANUFACTURER, Build.MANUFACTURER)
.put(OS_NAME, "Android")
.put(OS_TYPE, "linux")
.put(OS_VERSION, Build.VERSION.RELEASE)
.put(OS_DESCRIPTION, osDescription)
.build());

Resource result = AndroidResource.createDefault(app);
Expand Down

0 comments on commit 3ad5c83

Please sign in to comment.