Tracking traces with open tel collector
opentelsdk
is a library that provides an easy way to integrate OpenTelemetry tracing into your Android application. Follow the steps below to add this SDK to your project and set it up.
-
Download the sdk from git. Open your
build.gradle
file of your app module. -
Add the dependency for
opentelsdk
by importing this a library moduleimplementation project(':opentelsdk')
-
Create a folder named
assets
in thesrc/main
directory of your app module if it doesn't already exist. -
Create a file named
config.json
in theassets
folder. -
Add the following content to the
config.json
file: You can add any event name and type{ "events": [ { "event_name": "Go Shopping", "event_type": "click_event" }, { "event_name": "Learn More", "event_type": "click_event" } ] }
-
Create a class that extends
Application
in your app module. -
Set up the
OpenTelemetry
initialization in theonCreate
method.package com.yourapp import android.app.Application import com.yourcompany.opentelsdk.OpenTelemetry import com.yourcompany.opentelsdk.ConfigType class MyApplication : Application() { override fun onCreate() { super.onCreate() OpenTelemetry.initialize( ConfigType.HTTP, // HTTP or GRPC this, "https://ingest.in.signoz.cloud:443/v1/traces", "https://ingest.in.signoz.cloud:443/v1/traces", "c5d49b77-781b-4159-9394-e59b847c349e", "test" // Service name ) } }
-
Update your
AndroidManifest.xml
to use this customApplication
class:<application android:name=".MyApplication" ... > ... </application>
-
Start collecting events
lifecycleScope.launch() { EventCollector.handleEvent("Go Shopping", "") }
"Go Shopping" is parent span. The second param is child span. You can leave it empty if you want.
lifecycleScope.launch() {
EventCollector.handleEvent("Go Shopping", "Add to cart")
}
"Add to cart" here is child span of Go Shopping
You’ve now successfully integrated opentelsdk
into your Android project. Your app should be able to send traces to the specified OpenTelemetry endpoint.
For more information, please refer to the official documentation of opentelsdk
.