Commit ab6eb462 authored by Michael Droettboom's avatar Michael Droettboom Committed by Alessio Placitelli
Browse files

1505395: Add a third-party test library to samples-glean

parent b83fae2c
......@@ -252,6 +252,10 @@ projects:
path: samples/glean
description: 'An app demoing how to use the Glean library to collect and send telemetry data.'
publish: false
samples-glean-library:
path: samples/glean/samples-glean-library
description: 'A third-party library used by samples-glean to demonstrate multi-library support for Glean.'
publish: false
samples-sync-history:
path: samples/sync-history
description: 'A simple app demoing Firefox Sync (History) integration.'
......
......@@ -40,6 +40,8 @@ dependencies {
implementation Dependencies.support_appcompat
implementation Dependencies.support_customtabs
implementation project(':samples-glean-library')
}
apply from: '../../components/service/glean/scripts/sdk_generator.gradle'
samples_glean_library is a toy library that uses glean to record metrics. It
exists simply to show how libraries that are neither the application or glean
itself can record metrics, and those metrics will be stored and sent as part of
the [main pings](../../../components/service/glean/docs/pings.md) that glean
provides.
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
plugins {
id "com.jetbrains.python.envs" version "0.0.26"
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion config.compileSdkVersion
defaultConfig {
minSdkVersion config.minSdkVersion
targetSdkVersion config.targetSdkVersion
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation Dependencies.kotlin_stdlib
implementation project(':service-glean')
}
apply from: '../../../components/service/glean/scripts/sdk_generator.gradle'
# This file defines the metrics that are recorded by glean telemetry. They are
# automatically converted to Kotlin code at build time using the `glean_parser`
# PyPI package.
$schema: moz://mozilla.org/schemas/glean/metrics/1-0-0
sample_metrics:
test:
type: counter
description: >
A simple counter defined in a third-party library
send_in_pings:
- baseline
bugs:
- 123456789
data_reviews:
- N/A
notification_emails:
- telemetry-client-dev@mozilla.com
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mozilla.samples.glean.library" />
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.samples.glean.library
import mozilla.samples.glean.library.GleanMetrics.SampleMetrics
import mozilla.components.service.glean.Glean
/**
* These are just simple functions to test calling the Glean API
* from a third-party library.
*/
object SamplesGleanLibrary {
/**
* Record to a metric defined in *this* library's metrics.yaml file.
*/
fun recordMetric() {
SampleMetrics.test.add()
}
/**
* Notate an active experiment.
*/
fun recordExperiment() {
Glean.setExperimentActive(
"third_party_library",
"enabled"
)
}
}
......@@ -10,6 +10,7 @@ import kotlinx.android.synthetic.main.activity_main.*
import mozilla.components.service.glean.Glean
import org.mozilla.samples.glean.GleanMetrics.Test
import org.mozilla.samples.glean.GleanMetrics.BrowserEngagement
import org.mozilla.samples.glean.library.SamplesGleanLibrary
open class MainActivity : AppCompatActivity() {
......@@ -51,5 +52,9 @@ open class MainActivity : AppCompatActivity() {
}
Test.testTimespan.stopAndSum()
// Update some metrics from a third-party library
SamplesGleanLibrary.recordMetric()
SamplesGleanLibrary.recordExperiment()
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment