bevy_fleet/
config.rs

1use bevy::prelude::*;
2use serde::{Deserialize, Serialize};
3
4/// Configuration options specific to the OTLP exporter.
5#[derive(Clone, Debug, Serialize, Deserialize)]
6pub struct OtlpConfig {
7    /// Whether to prefer HTTP/JSON when communicating with the collector.
8    ///
9    /// The exporter still sends Protobuf-encoded payloads; this flag only
10    /// changes the advertised `Content-Type`.
11    pub use_http_json: bool,
12
13    /// Additional resource attributes that will be attached to every export.
14    pub resource_attributes: std::collections::HashMap<String, String>,
15}
16
17impl Default for OtlpConfig {
18    fn default() -> Self {
19        Self {
20            use_http_json: true,
21            resource_attributes: std::collections::HashMap::new(),
22        }
23    }
24}
25
26/// Configuration for the Fleet plugin.
27#[derive(Clone, Debug, Resource, Serialize, Deserialize)]
28pub struct FleetConfig {
29    /// Unique identifier for this application instance.
30    pub app_id: String,
31
32    /// Application name (used in OTLP as `service.name`).
33    pub app_name: String,
34
35    /// Application version (defaults to the git version when the `git-version` feature is enabled).
36    pub app_version: String,
37
38    /// OTLP collector endpoint.
39    pub aggregation_url: String,
40
41    /// Whether the plugin is enabled.
42    pub enabled: bool,
43
44    /// Interval in seconds between telemetry publishing.
45    pub publish_interval_secs: u64,
46
47    /// Maximum number of queued telemetry payloads.
48    pub max_queue_size: usize,
49
50    /// OTLP exporter tuning.
51    pub otlp_config: OtlpConfig,
52}
53
54impl Default for FleetConfig {
55    fn default() -> Self {
56        Self {
57            app_id: "bevy-app".to_string(),
58            app_name: "bevy-fleet".to_string(),
59            app_version: get_default_app_version(),
60            aggregation_url: "http://localhost:4318/v1/metrics".to_string(),
61            enabled: true,
62            publish_interval_secs: 60,
63            max_queue_size: 100,
64            otlp_config: OtlpConfig::default(),
65        }
66    }
67}
68
69/// Gets the default app version (from git-version if available)
70fn get_default_app_version() -> String {
71    #[cfg(feature = "git-version")]
72    {
73        git_version::git_version!(args = ["--always", "--dirty=-modified"], fallback = "unknown")
74            .to_string()
75    }
76
77    #[cfg(not(feature = "git-version"))]
78    {
79        "unknown".to_string()
80    }
81}
82
83/// The Fleet plugin that can be added to a Bevy app
84#[derive(Clone, Default)]
85pub struct FleetPlugin {
86    pub config: FleetConfig,
87}