Debian Codegraph @

third_party/rust/glean-core/src/glean.udl

raw
1 namespace glean {
2 void glean_enable_logging();
3
4 // Initialize the logging system to send JSON messages to a file descriptor
5 // (Unix) or file handle (Windows).
6 //
7 // No-op on Android and iOS. Use `glean_enable_logging` instead.
8 void glean_enable_logging_to_fd(u64 fd);
9
10 // Initializes Glean.
11 //
12 // This will fully initialize Glean in a separate thread.
13 // It will return immediately.
14 void glean_initialize(InternalConfiguration cfg, ClientInfoMetrics client_info, OnGleanEvents callbacks);
15
16 /// Shuts down Glean in an orderly fashion.
17 void glean_shutdown();
18
19 // Creates and initializes a new Glean object for use in a subprocess.
20 //
21 // Importantly, this will not send any pings at startup, since that
22 // sort of management should only happen in the main process.
23 //
24 // Must only be used for an uploader process.
25 // The general API or any metrics API **will not work**.
26 boolean glean_initialize_for_subprocess(InternalConfiguration cfg);
27
28 void glean_set_upload_enabled(boolean enabled);
29
30 // Experiment reporting API
31 void glean_set_experiment_active(string experiment_id, string branch, record<DOMString, string> extra);
32 void glean_set_experiment_inactive(string experiment_id);
33 RecordedExperiment? glean_test_get_experiment_data(string experiment_id);
34
35 // Experimentation ID API
36 void glean_set_experimentation_id(string experimentation_id);
37 string? glean_test_get_experimentation_id();
38
39 // EXPERIMENTAL: Register a listener to receive notification of event recordings
40 //
41 // tag: String value used later to unregister the listener
42 // listener: An object which implements the GleanEventListener interface
43 void glean_register_event_listener(string tag, GleanEventListener listener);
44 // EXPERIMENTAL: Unregister a previously registered event listener
45 //
46 // tag: The tag used when registering the listener
47 void glean_unregister_event_listener(string tag);
48
49 // Server Knobs API
50 void glean_apply_server_knobs_config(string json);
51
52 boolean glean_set_debug_view_tag(string tag);
53 string? glean_get_debug_view_tag();
54 boolean glean_set_source_tags(sequence<string> tags);
55 void glean_set_log_pings(boolean value);
56 boolean glean_get_log_pings();
57 sequence<string> glean_get_registered_ping_names();
58
59 void glean_persist_ping_lifetime_data();
60
61 void glean_handle_client_active();
62 void glean_handle_client_inactive();
63
64 void glean_submit_ping_by_name(string ping_name, optional string? reason = null);
65 boolean glean_submit_ping_by_name_sync(string ping_name, optional string? reason = null);
66
67 void glean_set_test_mode(boolean enabled);
68 void glean_test_destroy_glean(boolean clear_stores, optional string? data_path = null);
69
70 void glean_set_dirty_flag(boolean flag);
71
72 PingUploadTask glean_get_upload_task();
73 UploadTaskAction glean_process_ping_upload_response(string uuid, UploadResult result);
74
75 // Updates attribution fields with new values.
76 // AttributionMetrics fields with no values will not overwrite older values.
77 void glean_update_attribution(AttributionMetrics attribution);
78 // Returns the current attribution metrics, if any.
79 AttributionMetrics glean_test_get_attribution();
80
81 // Updates distribution fields with new values.
82 // DistributionMetrics fields with no values will not overwrite older values.
83 void glean_update_distribution(DistributionMetrics distribution);
84 // Returns the current distribution metrics, if any.
85 DistributionMetrics glean_test_get_distribution();
86 };
87
88 // A `Cow<'static, str>`, but really it's always the owned part.
89 [Custom]
90 typedef string CowString;
91
92 // The Glean configuration.
93 //
94 // This exposes all configurable parameters to the SDK side.
95 // They should not be exposed directly to users of the SDK (except `upload_enabled`).
96 dictionary InternalConfiguration {
97 string data_path;
98 string application_id;
99 string language_binding_name;
100 boolean upload_enabled;
101 u32? max_events;
102 boolean delay_ping_lifetime_io;
103 string app_build;
104 boolean use_core_mps;
105 boolean trim_data_to_registered_pings;
106 LevelFilter? log_level;
107 PingRateLimit? rate_limit;
108 boolean enable_event_timestamps;
109 string? experimentation_id;
110 boolean enable_internal_pings;
111 record<string, sequence<string>> ping_schedule;
112 u64 ping_lifetime_threshold;
113 u64 ping_lifetime_max_time; // in millis
114 };
115
116 // How to specify the rate pings may be uploaded before they are throttled.
117 dictionary PingRateLimit {
118 u64 seconds_per_interval;
119 u32 pings_per_interval;
120 };
121
122 // An enum representing the different logging levels for the `log` crate.
123 [Remote]
124 enum LevelFilter {
125 "Off",
126 "Error",
127 "Warn",
128 "Info",
129 "Debug",
130 "Trace",
131 };
132
133 // Values for the `client_info` metrics.
134 // The language SDK should collect them on `initialize` once.
135 // They will be re-used, e.g. when upload is toggled from off to on, to re-set them.
136 //
137 // See https://mozilla.github.io/glean/book/user/pings/index.html#the-client_info-section for details.
138 dictionary ClientInfoMetrics {
139 string app_build;
140 string app_display_version;
141 Datetime app_build_date;
142 string architecture;
143 string os_version;
144
145 string? channel = null;
146 string? locale = null;
147 string? device_manufacturer = null;
148 string? device_model = null;
149 string? android_sdk_version = null;
150 i64? windows_build_number = null;
151 };
152
153 dictionary AttributionMetrics {
154 string? source = null;
155 string? medium = null;
156 string? campaign = null;
157 string? term = null;
158 string? content = null;
159 };
160
161 dictionary DistributionMetrics {
162 string? name = null;
163 };
164
165 [Error]
166 enum CallbackError {
167 "UnexpectedError",
168 };
169
170 // A callback object, that is stored within the core logic for the entire lifetime of the application.
171 //
172 // This is used to trigger certain actions that need to happen on the foreign-language side.
173 callback interface OnGleanEvents {
174 // Initialization finished.
175 //
176 // The language SDK can do additional things from within the same initializer thread,
177 // e.g. starting to observe application events for foreground/background behavior.
178 // The observer then needs to call the respective client activity API.
179 void initialize_finished();
180
181 // Trigger the uploader whenever a ping was submitted.
182 //
183 // This should not block.
184 // The uploader needs to asynchronously poll Glean for new pings to upload.
185 [Throws=CallbackError]
186 void trigger_upload();
187
188 // Start the Metrics Ping Scheduler.
189 //
190 // *Note*: The implementor
191 // * DOES NOT need to schedule the uploader.
192 // * MUST NOT use a dispatched call in the immediate invocation.
193 //
194 // Returns whether it submitted a ping immediately.
195 boolean start_metrics_ping_scheduler();
196
197 // Called when upload is disabled and uploads should be stopped
198 [Throws=CallbackError]
199 void cancel_uploads();
200
201 // Called on shutdown, before Glean is fully shutdown.
202 //
203 // * This MUST NOT put any new tasks on the dispatcher.
204 // * New tasks will be ignored.
205 // * This SHOULD NOT block arbitrarily long.
206 // * Shutdown waits for a maximum of 30 seconds.
207 [Throws=CallbackError]
208 void shutdown();
209 };
210
211 // A callback handler that receives the IDs of recorded events
212 callback interface GleanEventListener {
213 // Called when an event is recorded, indicating the id of the event
214 void on_event_recorded(string id);
215 };
216
217 // Deserialized experiment data.
218 dictionary RecordedExperiment {
219 // The experiment's branch.
220 string branch;
221 // Any extra data associated with this experiment.
222 record<DOMString, string>? extra;
223 };
224
225 // Represents a request to upload a ping.
226 dictionary PingRequest {
227 // The Job ID to identify this request,
228 // this is the same as the ping UUID.
229 string document_id;
230 // The path for the server to upload the ping to.
231 string path;
232 // The body of the request, as a byte array.
233 // If gzip encoded, then the `headers` list will
234 // contain a `Content-Encoding` header with the value `gzip`.
235 sequence<u8> body;
236 // A map with all the headers to be sent with the request.
237 record<DOMString, string> headers;
238 // Whether the body has {client|ping}_info sections.
239 boolean body_has_info_sections;
240 // The ping's name. Likely also somewhere in `path`.
241 string ping_name;
242 // The capabilities required during this ping's upload.
243 sequence<string> uploader_capabilities;
244 };
245
246 // An enum representing the possible upload tasks to be performed by an uploader.
247 [Enum]
248 interface PingUploadTask {
249 // An upload task.
250 //
251 // * request: the ping request for upload
252 Upload(PingRequest request);
253
254 // A flag signaling that the pending pings directories are not done being processed,
255 // thus the requester should wait and come back later.
256 //
257 // * time: The time in milliseconds the requester should wait before requesting a new task.
258 Wait(u64 time);
259
260 // A flag signaling that requester doesn't need to request
261 // any more upload tasks at this moment.
262 //
263 // * unused: _ignored_.
264 Done(i8 unused);
265 };
266
267 // The result of an attempted ping upload.
268 [Enum]
269 interface UploadResult {
270 // A recoverable failure.
271 //
272 // During upload something went wrong,/ e.g. the network connection failed.
273 // The upload should be retried at a later time.
274 //
275 // * unused: _ignored_.
276 RecoverableFailure(i8 unused);
277
278 // An unrecoverable upload failure.
279 //
280 // A possible cause might be a malformed URL.
281 //
282 // * unused: _ignored_.
283 UnrecoverableFailure(i8 unused);
284
285 // The uploader is not capable of uploading this request due to lack of or
286 // mismatched capabilities.
287 //
288 // e.g. The ping requires upload over OHTTP,
289 // but the uploader doesn't support OHTTP.
290 //
291 // * unused: _ignored_.
292 Incapable(i8 unused);
293
294 // A HTTP response code.
295 //
296 // This can still indicate an error, depending on the status code.
297 //
298 // * code: The HTTP status code
299 HttpStatus(i32 code);
300
301 // Signal that this uploader is done with work
302 // and won't accept new work.
303 Done(i8 unused);
304 };
305
306 // Communicating back whether the uploader loop should continue.
307 enum UploadTaskAction {
308 // Instruct the caller to continue with work.
309 "Next",
310
311 // Instruct the caller to end work.
312 "End",
313 };
314
315 // The supported metrics' lifetimes.
316 //
317 // A metric's lifetime determines when its stored data gets reset.
318 enum Lifetime {
319 // The metric is reset with each sent ping
320 "Ping",
321 // The metric is reset on application restart
322 "Application",
323 // The metric is reset with each user profile
324 "User",
325 };
326
327 // The possible error types for metric recording.
328 enum ErrorType {
329 // For when the value to be recorded does not match the metric-specific restrictions
330 "InvalidValue",
331 // For when the label of a labeled metric does not match the restrictions
332 "InvalidLabel",
333 // For when the metric caught an invalid state while recording
334 "InvalidState",
335 // For when the value to be recorded overflows the metric-specific upper range
336 "InvalidOverflow",
337 };
338
339 interface PingType {
340 constructor(
341 string name,
342 boolean include_client_id,
343 boolean send_if_empty,
344 boolean precise_timestamps,
345 boolean include_info_sections,
346 boolean enabled,
347 sequence<string> schedules_pings,
348 sequence<string> reason_codes,
349 boolean follows_collection_enabled,
350 sequence<string> uploader_capabilities
351 );
352 void submit(optional string? reason = null);
353
354 void set_enabled(boolean enabled);
355 };
356
357 // The common set of data shared across all different metric types.
358 dictionary CommonMetricData {
359 // The metric's category.
360 string category;
361 // The metric's name.
362 string name;
363
364 // List of ping names to include this metric in.
365 sequence<string> send_in_pings;
366 // The metric's lifetime.
367 Lifetime lifetime;
368
369 // Whether or not the metric is disabled.
370 //
371 // Disabled metrics are never recorded.
372 boolean disabled;
373
374 // Dynamic label.
375 //
376 // When a labeled metric factory creates the specific metric to be recorded to,
377 // dynamic labels are stored in the specific label so that
378 // we can validate them when the Glean singleton is available.
379 string? dynamic_label = null;
380 };
381
382 interface CounterMetric {
383 constructor(CommonMetricData meta);
384
385 void add(optional i32 amount = 1);
386
387 i32? test_get_value(optional string? ping_name = null);
388
389 i32 test_get_num_recorded_errors(ErrorType error);
390 };
391
392 // Different resolutions supported by the time related metric types
393 // (e.g. DatetimeMetric).
394 enum TimeUnit {
395 // Represents nanosecond precision.
396 "Nanosecond",
397 // Represents microsecond precision.
398 "Microsecond",
399 // Represents millisecond precision.
400 "Millisecond",
401 // Represents second precision.
402 "Second",
403 // Represents minute precision.
404 "Minute",
405 // Represents hour precision.
406 "Hour",
407 // Represents day precision.
408 "Day",
409 };
410
411 interface TimespanMetric {
412 constructor(CommonMetricData meta, TimeUnit time_unit);
413
414 void start();
415
416 void stop();
417
418 void cancel();
419
420 void set_raw_nanos(i64 elapsed);
421
422 i64? test_get_value(optional string? ping_name = null);
423
424 i32 test_get_num_recorded_errors(ErrorType error);
425 };
426
427 interface BooleanMetric {
428 constructor(CommonMetricData meta);
429
430 void set(boolean value);
431
432 boolean? test_get_value(optional string? ping_name = null);
433
434 i32 test_get_num_recorded_errors(ErrorType error);
435 };
436
437 interface StringMetric {
438 constructor(CommonMetricData meta);
439
440 void set(string value);
441
442 string? test_get_value(optional string? ping_name = null);
443
444 i32 test_get_num_recorded_errors(ErrorType error);
445 };
446
447 [Enum]
448 interface LabeledMetricData {
449 Common(CommonMetricData cmd);
450 CustomDistribution(CommonMetricData cmd, i64 range_min, i64 range_max, i64 bucket_count, HistogramType histogram_type);
451 MemoryDistribution(CommonMetricData cmd, MemoryUnit unit);
452 TimingDistribution(CommonMetricData cmd, TimeUnit unit);
453 };
454
455 interface LabeledCounter {
456 constructor(LabeledMetricData meta, sequence<CowString>? labels);
457
458 CounterMetric get(string label);
459
460 i32 test_get_num_recorded_errors(ErrorType error);
461 };
462
463 interface LabeledBoolean {
464 constructor(LabeledMetricData meta, sequence<CowString>? labels);
465
466 BooleanMetric get(string label);
467
468 i32 test_get_num_recorded_errors(ErrorType error);
469 };
470
471 interface LabeledString {
472 constructor(LabeledMetricData meta, sequence<CowString>? labels);
473
474 StringMetric get(string label);
475
476 i32 test_get_num_recorded_errors(ErrorType error);
477 };
478
479 interface LabeledQuantity {
480 constructor(LabeledMetricData meta, sequence<CowString>? labels);
481
482 QuantityMetric get(string label);
483
484 i32 test_get_num_recorded_errors(ErrorType error);
485 };
486
487 interface StringListMetric {
488 constructor(CommonMetricData meta);
489
490 void add(string value);
491
492 void set(sequence<string> value);
493
494 sequence<string>? test_get_value(optional string? ping_name = null);
495
496 i32 test_get_num_recorded_errors(ErrorType error);
497 };
498
499 interface UrlMetric {
500 constructor(CommonMetricData meta);
501
502 void set(string value);
503
504 string? test_get_value(optional string? ping_name = null);
505
506 i32 test_get_num_recorded_errors(ErrorType error);
507 };
508
509 interface UuidMetric {
510 constructor(CommonMetricData meta);
511
512 void set(string value);
513
514 string generate_and_set();
515
516 string? test_get_value(optional string? ping_name = null);
517
518 i32 test_get_num_recorded_errors(ErrorType error);
519 };
520
521 interface QuantityMetric {
522 constructor(CommonMetricData meta);
523
524 void set(i64 value);
525
526 i64? test_get_value(optional string? ping_name = null);
527
528 i32 test_get_num_recorded_errors(ErrorType error);
529 };
530
531 // A snapshot of all buckets and the accumulated sum of a distribution.
532 dictionary DistributionData {
533 // A map containig the bucket index mapped to the accumulated count.
534 record<i64, i64> values;
535
536 // The accumulated sum of all the samples in the distribution.
537 i64 sum;
538
539 // The total number of entries in the distribution.
540 i64 count;
541 };
542
543 // Identifier for a running timer.
544 //
545 // Its internals are considered private,
546 // but due to UniFFI's behavior we expose it as a dictionary for now.
547 dictionary TimerId {
548 u64 id;
549 };
550
551 interface TimingDistributionMetric {
552 constructor(CommonMetricData meta, TimeUnit time_unit);
553
554 TimerId start();
555
556 void stop_and_accumulate(TimerId timer_id);
557
558 void cancel(TimerId timer_id);
559
560 void accumulate_samples(sequence<i64> samples);
561
562 void accumulate_single_sample(i64 sample);
563
564 DistributionData? test_get_value(optional string? ping_name = null);
565
566 i32 test_get_num_recorded_errors(ErrorType error);
567 };
568
569 // Different resolutions supported by the memory related metric types
570 // (e.g. MemoryDistributionMetric).
571 enum MemoryUnit {
572 // 1 byte
573 "Byte",
574 // 2^10 bytes
575 "Kilobyte",
576 // 2^20 bytes
577 "Megabyte",
578 // 2^30 bytes
579 "Gigabyte",
580 };
581
582 interface MemoryDistributionMetric {
583 constructor(CommonMetricData meta, MemoryUnit memory_unit);
584
585 void accumulate(i64 sample);
586
587 void accumulate_samples(sequence<i64> samples);
588
589 DistributionData? test_get_value(optional string? ping_name = null);
590
591 i32 test_get_num_recorded_errors(ErrorType error);
592 };
593
594 // Different kinds of histograms.
595 enum HistogramType {
596 // A histogram with linear distributed buckets.
597 "Linear",
598 // A histogram with exponential distributed buckets.
599 "Exponential",
600 };
601
602 interface CustomDistributionMetric {
603 constructor(CommonMetricData meta, i64 range_min, i64 range_max, i64 bucket_count, HistogramType histogram_type);
604
605 void accumulate_samples(sequence<i64> samples);
606
607 void accumulate_single_sample(i64 sample);
608
609 DistributionData? test_get_value(optional string? ping_name = null);
610
611 i32 test_get_num_recorded_errors(ErrorType error);
612 };
613
614 // Representation of a date, time and timezone.
615 dictionary Datetime {
616 i32 year;
617 u32 month;
618 u32 day;
619 u32 hour;
620 u32 minute;
621 u32 second;
622 u32 nanosecond;
623 i32 offset_seconds;
624 };
625
626 interface DatetimeMetric {
627 constructor(CommonMetricData meta, TimeUnit time_unit);
628
629 void set(optional Datetime? value = null);
630
631 Datetime? test_get_value(optional string? ping_name = null);
632
633 string? test_get_value_as_string(optional string? ping_name = null);
634
635 i32 test_get_num_recorded_errors(ErrorType error);
636 };
637
638 // Represents the recorded data for a single event.
639 dictionary RecordedEvent {
640 // The timestamp of when the event was recorded.
641 //
642 // This allows to order events from a single process run.
643 u64 timestamp;
644
645 // The event's category.
646 //
647 // This is defined by users in the metrics file.
648 string category;
649
650 // The event's name.
651 //
652 // This is defined by users in the metrics file.
653 string name;
654
655 // A map of all extra data values.
656 //
657 // The set of allowed extra keys is defined by users in the metrics file.
658 record<DOMString, string>? extra;
659 };
660
661 interface EventMetric {
662 constructor(CommonMetricData meta, sequence<string> allowed_extra_keys);
663
664 void record(record<DOMString, string> extra);
665
666 sequence<RecordedEvent>? test_get_value(optional string? ping_name = null);
667
668 i32 test_get_num_recorded_errors(ErrorType error);
669 };
670
671 dictionary Rate {
672 i32 numerator;
673 i32 denominator;
674 };
675
676 interface RateMetric {
677 constructor(CommonMetricData meta);
678
679 void add_to_numerator(i32 amount);
680
681 void add_to_denominator(i32 amount);
682
683 Rate? test_get_value(optional string? ping_name = null);
684
685 i32 test_get_num_recorded_errors(ErrorType error);
686 };
687
688 interface DenominatorMetric {
689 constructor(CommonMetricData meta, sequence<CommonMetricData> numerators);
690
691 void add(i32 amount);
692
693 i32? test_get_value(optional string? ping_name = null);
694
695 i32 test_get_num_recorded_errors(ErrorType error);
696 };
697
698 interface NumeratorMetric {
699 constructor(CommonMetricData meta);
700
701 void add_to_numerator(i32 amount);
702
703 Rate? test_get_value(optional string? ping_name = null);
704
705 i32 test_get_num_recorded_errors(ErrorType error);
706 };
707
708 interface TextMetric {
709 constructor(CommonMetricData meta);
710
711 void set(string value);
712
713 string? test_get_value(optional string? ping_name = null);
714
715 i32 test_get_num_recorded_errors(ErrorType error);
716 };
717
718 // JSON data encoded into a string
719 [Custom]
720 typedef string JsonValue;
721
722 interface ObjectMetric {
723 constructor(CommonMetricData meta);
724
725 void set_string(string object);
726
727 JsonValue? test_get_value(optional string? ping_name = null);
728
729 i32 test_get_num_recorded_errors(ErrorType error);
730
731 void record_schema_error();
732 };