Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added os.description resource attribute #42

Merged
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();
surbhiia marked this conversation as resolved.
Show resolved Hide resolved
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