Skip to content

Instantly share code, notes, and snippets.

@daoshengmu
Last active July 29, 2020 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daoshengmu/4ac9029ae7d1b04f51adac345b296bdd to your computer and use it in GitHub Desktop.
Save daoshengmu/4ac9029ae7d1b04f51adac345b296bdd to your computer and use it in GitHub Desktop.
My first glean c#
// Initialize Glean SDK. `uploadEnabled` can be configured according to
// user telemetry enable|disable setting.
GleanInstance.Initialize(
applicationId: "org.test.glean.sample",
applicationVersion: "1.0",
uploadEnabled: true,
configuration: new Configuration(),
dataDir: gleanDataDir
);
// Making a custom ping
var customPing = new PingType<NoReasonCodes>(
name: "sample",
includeClientId: true,
sendIfEmpty: false,
reasonCodes: null
);
// Making a string metric, it will be sent in
// `sample` ping.
var testMetric = new StringMetricType(
category: "test",
disabled: false,
lifetime: Lifetime.Application,
name: "hellow_world",
sendInPings: new string[] { "sample" });
// Set a value to this test metric.
testMetric.Set("my first metric.");
// Submit this custom ping that include the metrics
// that has `sample` in sendInPings.
customPing.Submit();
// We need to block the main process a couple of
// seconds to avoid it quits in order to give enought
// time for letting Glean ping uploader thread finishes
// its tasks.
Thread.Sleep(1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment