Skip to content

Commit

Permalink
Merge pull request #2 from instana/INSTA-18861_create_sample_app_for_…
Browse files Browse the repository at this point in the history
…lib_support

Created sample app with updated plugin support
  • Loading branch information
jobykorahgeorgeibm authored and GitHub Enterprise committed Nov 7, 2024
2 parents 4727474 + b6376bf commit 51f95d4
Show file tree
Hide file tree
Showing 45 changed files with 1,019 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A collection of awesome things regarding Instana EUM.
- [flutter-api-showcase](/flutter-api-showcase) - Example mobile application designed to showcase and test the capabilities of IBM Instana Flutter Agent and provide a comprehensive understanding of its functionality.
- [android-crash](/android-crash) - Example mobile application designed to showcase crash collection using Instana Android Agent.
- [android-crash-user-consent](/android-crash-user-consent) - Example mobile application designed to showcase crash collection using Instana Android Agent with user consent.
- [android-lib-injection-plugin](/android-lib-injection-plugin) - A Sample application to showcase that Instana android agent plugin is injectable at library level.
- [android-compose-robotshop](/android-compose-robotshop) - A Shopping application clone with fakestore apis, Instrumented with instsna having version catelog based dependecy gradles.
Features :
- Calculate revenuew in a period of time with custom metric
Expand Down
87 changes: 87 additions & 0 deletions android-lib-injection-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Built application files
*.apk
*.aar
*.ap_
*.aab
.idea

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
.DS_Store
19 changes: 19 additions & 0 deletions android-lib-injection-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Instana Android Agent Inject in Libraries

Instana Android-agent can also use to monitor a library level app using this example.

Instructions
------------

* **Step 1:** Clone the repository

* **Step 2:** Unzip the jar at [/libs/plugin.jar.zip](/libs/plugin.jar.zip), This is a jar that supports lib level injection.

* **Step 3:** Change the `URL` and `KEY` in [/ibmkony/src/main/java/com/ibm/ibmkony/InstanaIBM.kt](/ibmkony/src/main/java/com/ibm/ibmkony/InstanaIBM.kt)

* **Step 4:** Run the application.

Result
------------

You'll notice that `ibmkony`, the custom library where Instana is integrated, can monitor the application using the bridge provided at the library level. The only change in application level is applying teh plugin.
1 change: 1 addition & 0 deletions android-lib-injection-plugin/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
49 changes: 49 additions & 0 deletions android-lib-injection-plugin/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.instana.android-agent-plugin'//If you comment this http calls will not monitor automatically
}

android {
compileSdk 34

defaultConfig {
applicationId "com.apps.test"
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation project(':ibmkony')
def lifecycle_version = "2.5.1"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
implementation("com.squareup.okhttp3:okhttp:4.9.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}
21 changes: 21 additions & 0 deletions android-lib-injection-plugin/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
28 changes: 28 additions & 0 deletions android-lib-injection-plugin/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.apps.test">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name="com.apps.test.MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Sample">

<activity
android:name="com.apps.test.MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.apps.test

import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response


class MainActivity : AppCompatActivity() {
private val client = OkHttpClient()
private val apiUrl = "https://jsonplaceholder.typicode.com/todos/1" // Sample API URL

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
bindContent()
}

private suspend fun makeApiCall() {
val request = Request.Builder()
.url(apiUrl)
.build()

try {
// Execute the request asynchronously in the IO dispatcher
val response: Response = client.newCall(request).execute()

if (response.isSuccessful) {
val responseData = response.body?.string()
Log.d("MainActivity", "Response: $responseData")

// Update the UI on the main thread if needed
withContext(Dispatchers.Main) {
// Update UI, e.g., show response data in a TextView
}
} else {
Log.e("MainActivity", "Request failed with code: ${response.code}")
}
} catch (e: Exception) {
Log.e("MainActivity", "API call failed: ${e.message}")
}
}

private fun bindContent() {
val button = findViewById<Button>(R.id.makeCall)
button.setOnClickListener {
CoroutineScope(Dispatchers.IO).launch {
makeApiCall()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.apps.test

import android.app.Application
import com.ibm.ibmkony.InstanaIBM

class MainApplication : Application() {

override fun onCreate() {
super.onCreate()
//This way you can initialise Instana from your custom library.
InstanaIBM.setup(
this
)
//Using APIs from your library to call instana native methods.
InstanaIBM.setUserId("User ID Value")
InstanaIBM.setUserEmail("User Email Value")
InstanaIBM.setUsername("User Name Value")
InstanaIBM.setViewName("TEST_VIEW")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
Loading

0 comments on commit 51f95d4

Please sign in to comment.