Skip to content

Commit

Permalink
Docker compose servers (#426)
Browse files Browse the repository at this point in the history
* rename app and set up collector and jaeger via docker compose

* also generate span

* add version

* fix version

* whoops
  • Loading branch information
breedx-splk authored Jun 17, 2024
1 parent 7b73e7a commit 3473730
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 9 deletions.
13 changes: 11 additions & 2 deletions demo-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
This is an app built to demonstrate how to configure and use the OpenTelemetry Android agent
to observe app and user behavior.

This is very much a work in progress.
This is very much a work in progress. See the `OtelDemoApplication.kt` for
a quick and dirty example of how to get the agent initialized.

## Features

Expand All @@ -13,4 +14,12 @@ This is very much a work in progress.

## How to use

* TBD
First, start up the collector and jaeger with docker-compose:

```bash
$ docker-compose build
$ docker-compose up
```

Then run the demo app in the Android emulator and navigate to http://localhost:16686
to see the Jaeger UI.
1 change: 1 addition & 0 deletions demo-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.opentelemetry.api.incubator)

coreLibraryDesugaring(libs.desugarJdkLibs)

Expand Down
21 changes: 21 additions & 0 deletions demo-app/collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
receivers:
otlp:
protocols:
grpc:
http:
extensions:
exporters:
otlphttp:
traces_endpoint: "http://jaeger:4318/v1/traces"
logging:
verbosity: normal
logging/debug:
verbosity: detailed
service:
pipelines:
traces:
receivers: [otlp]
exporters: [logging/debug, otlphttp]
logs:
receivers: [otlp]
exporters: [logging/debug]
16 changes: 16 additions & 0 deletions demo-app/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
collector:
image: "otel/opentelemetry-collector-contrib"
volumes:
- ./collector.yaml:/etc/demo-collector.yaml
entrypoint: ["/otelcol-contrib"]
command: ["--config", "/etc/demo-collector.yaml"]
ports:
- "4317:4317" # OTLP gRPC
- "4318:4318" # OTLP HTTP
jaeger:
image: "jaegertracing/all-in-one:1.57"
environment:
- COLLECTOR_OTLP_ENABLED=true
ports:
- "16686:16686" # UI
2 changes: 2 additions & 0 deletions demo-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[versions]
opentelemetry = "1.39.0"
opentelemetry-alpha = "1.39.0-alpha"
junit = "5.10.2"
spotless = "6.25.0"
kotlin = "2.0.0"

[libraries]
androidx-appcompat = "androidx.appcompat:appcompat:1.7.0"
opentelemetry-exporter-otlp = { module = "io.opentelemetry:opentelemetry-exporter-otlp", version.ref = "opentelemetry" }
opentelemetry-api-incubator = { module = "io.opentelemetry:opentelemetry-api-incubator", version.ref = "opentelemetry-alpha" }
gson = "com.google.code.gson:gson:2.11.0"

#Test tools
Expand Down
2 changes: 1 addition & 1 deletion demo-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".OtelSampleApplication"
android:name=".OtelDemoApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlinx.coroutines.launch

class DemoViewModel : ViewModel() {
val sessionIdState = MutableStateFlow("? unknown ?")
private val tracer = OtelSampleApplication.tracer("otel.demo")!!
private val tracer = OtelDemoApplication.tracer("otel.demo")!!

init {
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -81,6 +80,6 @@ class MainActivity : ComponentActivity() {
Log.d(TAG, "Main Activity started ")
}
}
viewModel.sessionIdState.value = OtelSampleApplication.rum?.rumSessionId!!
viewModel.sessionIdState.value = OtelDemoApplication.rum?.rumSessionId!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ fun MainOtelButton(icon: Painter) {
}

fun generateClickEvent() {
// TODO: Make an actual otel event
val tracer = OtelSampleApplication.tracer("otel.demo")
val scope = "otel.demo.app"
OtelDemoApplication.eventBuilder(scope, "logo.clicked")
.emit()
// For now, we also emit a span, so that we can see something in a UI
val tracer = OtelDemoApplication.tracer(scope)
val span =
tracer
?.spanBuilder("logo.clicked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import io.opentelemetry.android.config.OtelRumConfig
import io.opentelemetry.android.features.diskbuffering.DiskBufferingConfiguration
import io.opentelemetry.api.common.AttributeKey.stringKey
import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.incubator.events.EventBuilder
import io.opentelemetry.api.trace.Tracer
import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter
import io.opentelemetry.sdk.logs.internal.SdkEventLoggerProvider
import kotlin.math.log

const val TAG = "otel.demo"

class OtelSampleApplication : Application() {
class OtelDemoApplication : Application() {
@SuppressLint("RestrictedApi")
override fun onCreate() {
super.onCreate()
Expand Down Expand Up @@ -66,5 +68,12 @@ class OtelSampleApplication : Application() {
fun tracer(name: String): Tracer? {
return rum?.openTelemetry?.tracerProvider?.get(name)
}

fun eventBuilder(scopeName: String, eventName: String): EventBuilder {
val loggerProvider = rum?.openTelemetry?.logsBridge
val eventLogger =
SdkEventLoggerProvider.create(loggerProvider).get(scopeName)
return eventLogger.builder(eventName)
}
}
}

0 comments on commit 3473730

Please sign in to comment.