Skip to content

Commit 3334140

Browse files
voodoo11Manul from Pathway
authored andcommitted
Add license key to trace resource (#6455)
GitOrigin-RevId: 039747618a0689fa9818cb8756fc9934684eeb79
1 parent 079e89a commit 3334140

File tree

7 files changed

+36
-3
lines changed

7 files changed

+36
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pyo3-asyncio = "0.20.0"
5858
pyo3-log = "0.9.0"
5959
rand = "0.8.5"
6060
rdkafka = { version = "0.36.2", features = ["ssl-vendored", "cmake-build", "zstd"] }
61+
regex = "1.10.4"
6162
reqwest = { version = "0.12.4", features = ["blocking", "json"] }
6263
rusqlite = { version = "0.31.0", features = ["bundled"] }
6364
rust-s3 = { version = "0.33.0", features = ["sync-native-tls-vendored", "sync-native-tls", "fail-on-err"], default-features = false }

python/pathway/engine.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ class TelemetryConfig:
790790
service_namespace: str | None
791791
service_instance_id: str | None
792792
run_id: str
793+
license_key: str | None
793794
@staticmethod
794795
def create(
795796
*,

python/pathway/internals/graph_runner/telemetry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def _resource(self) -> Resource:
6767
SERVICE_INSTANCE_ID: self.config.service_instance_id or "",
6868
"run.id": self.config.run_id,
6969
"python.version": sys.version,
70+
"license.key": self.config.license_key or "",
7071
}
7172
)
7273

src/engine/license.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use cached::proc_macro::cached;
44
use log::info;
55
use nix::sys::resource::Resource;
66
use once_cell::sync::Lazy;
7+
use regex::Regex;
78
use serde::Deserialize;
89
use serde_json::{json, Value};
910

@@ -49,6 +50,23 @@ impl License {
4950
}
5051
}
5152
}
53+
54+
pub fn shortcut(&self) -> String {
55+
match self {
56+
License::NoLicenseKey => String::new(),
57+
License::LicenseKey(key) => {
58+
let pattern = r"^([^-\s]+-){4}[^-\s]+(-[^-\s]+)*$";
59+
let re = Regex::new(pattern).unwrap();
60+
61+
if re.is_match(key) {
62+
let parts: Vec<&str> = key.split('-').collect();
63+
format!("{}-{}", parts[0], parts[1])
64+
} else {
65+
String::new()
66+
}
67+
}
68+
}
69+
}
5270
}
5371

5472
#[derive(Debug, Clone, thiserror::Error)]

src/engine/telemetry.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const OUTPUT_LATENCY: &str = "latency.output";
4646

4747
const ROOT_TRACE_ID: Key = Key::from_static_str("root.trace.id");
4848
const RUN_ID: Key = Key::from_static_str("run.id");
49+
const LICENSE_KEY: Key = Key::from_static_str("license.key");
4950

5051
const LOCAL_DEV_NAMESPACE: &str = "local-dev";
5152

@@ -68,6 +69,7 @@ impl Telemetry {
6869
SERVICE_NAMESPACE.string(self.config.service_namespace.clone()),
6970
ROOT_TRACE_ID.string(root_trace_id.to_string()),
7071
RUN_ID.string(self.config.run_id.clone()),
72+
LICENSE_KEY.string(self.config.license_key.clone()),
7173
])
7274
}
7375

@@ -164,6 +166,7 @@ pub struct TelemetryEnabled {
164166
pub service_instance_id: String,
165167
pub run_id: String,
166168
pub trace_parent: Option<String>,
169+
pub license_key: String,
167170
}
168171

169172
#[derive(Clone, Debug)]
@@ -198,9 +201,13 @@ impl Config {
198201
}
199202

200203
match license {
201-
License::LicenseKey(_) => {
202-
Config::create_enabled(run_id, telemetry_server, monitoring_server, trace_parent)
203-
}
204+
License::LicenseKey(_) => Config::create_enabled(
205+
run_id,
206+
telemetry_server,
207+
monitoring_server,
208+
trace_parent,
209+
license,
210+
),
204211
License::NoLicenseKey => Ok(Config::Disabled),
205212
}
206213
}
@@ -210,6 +217,7 @@ impl Config {
210217
telemetry_server: Option<String>,
211218
monitoring_server: Option<String>,
212219
trace_parent: Option<String>,
220+
license: &License,
213221
) -> Result<Self> {
214222
let service_instance_id: String = parse_env_var("PATHWAY_SERVICE_INSTANCE_ID")
215223
.map_err(DynError::from)?
@@ -233,6 +241,7 @@ impl Config {
233241
service_instance_id,
234242
run_id,
235243
trace_parent,
244+
license_key: license.shortcut(),
236245
})))
237246
}
238247
}

src/python_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,6 +3495,7 @@ pub struct TelemetryConfig {
34953495
service_namespace: Option<String>,
34963496
service_instance_id: Option<String>,
34973497
run_id: String,
3498+
license_key: Option<String>,
34983499
}
34993500

35003501
#[pymethods]
@@ -3529,6 +3530,7 @@ impl From<EngineTelemetryConfig> for TelemetryConfig {
35293530
service_namespace: Some(config.service_namespace),
35303531
service_instance_id: Some(config.service_instance_id),
35313532
run_id: config.run_id,
3533+
license_key: Some(config.license_key),
35323534
},
35333535
EngineTelemetryConfig::Disabled => Self::default(),
35343536
}

0 commit comments

Comments
 (0)