Skip to content

Commit 1635500

Browse files
valkumcijothomas
andauthored
feat: stackdriver: Bring monitored resources on par with official SDKs (#205)
Co-authored-by: Cijo Thomas <[email protected]>
1 parent 7999eb5 commit 1635500

File tree

2 files changed

+128
-11
lines changed

2 files changed

+128
-11
lines changed

opentelemetry-stackdriver/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
### Changed
88

9+
- Added support for `MonitoredResource::CloudFunction`, `MonitoredResource::AppEngine`,
10+
`MonitoredResource::ComputeEngine`, and `MonitoredResource::KubernetesEngine`
11+
912
## v0.25.0
1013

1114
- Bump msrv to 1.75.0

opentelemetry-stackdriver/src/lib.rs

Lines changed: 125 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,46 @@ impl From<LogContext> for InternalLogContext {
551551
fn from(cx: LogContext) -> Self {
552552
let mut labels = HashMap::default();
553553
let resource = match cx.resource {
554+
MonitoredResource::AppEngine {
555+
project_id,
556+
module_id,
557+
version_id,
558+
zone,
559+
} => {
560+
labels.insert("project_id".to_string(), project_id);
561+
if let Some(module_id) = module_id {
562+
labels.insert("module_id".to_string(), module_id);
563+
}
564+
if let Some(version_id) = version_id {
565+
labels.insert("version_id".to_string(), version_id);
566+
}
567+
if let Some(zone) = zone {
568+
labels.insert("zone".to_string(), zone);
569+
}
570+
571+
proto::api::MonitoredResource {
572+
r#type: "gae_app".to_owned(),
573+
labels,
574+
}
575+
}
576+
MonitoredResource::CloudFunction {
577+
project_id,
578+
function_name,
579+
region,
580+
} => {
581+
labels.insert("project_id".to_string(), project_id);
582+
if let Some(function_name) = function_name {
583+
labels.insert("function_name".to_string(), function_name);
584+
}
585+
if let Some(region) = region {
586+
labels.insert("region".to_string(), region);
587+
}
588+
589+
proto::api::MonitoredResource {
590+
r#type: "cloud_function".to_owned(),
591+
labels,
592+
}
593+
}
554594
MonitoredResource::CloudRunJob {
555595
project_id,
556596
job_name,
@@ -595,6 +635,26 @@ impl From<LogContext> for InternalLogContext {
595635
labels,
596636
}
597637
}
638+
639+
MonitoredResource::ComputeEngine {
640+
project_id,
641+
instance_id,
642+
zone,
643+
} => {
644+
labels.insert("project_id".to_string(), project_id);
645+
if let Some(instance_id) = instance_id {
646+
labels.insert("instance_id".to_string(), instance_id);
647+
}
648+
if let Some(zone) = zone {
649+
labels.insert("zone".to_string(), zone);
650+
}
651+
652+
proto::api::MonitoredResource {
653+
r#type: "gce_instance".to_owned(),
654+
labels,
655+
}
656+
}
657+
598658
MonitoredResource::GenericNode {
599659
project_id,
600660
location,
@@ -650,6 +710,36 @@ impl From<LogContext> for InternalLogContext {
650710
labels,
651711
}
652712
}
713+
MonitoredResource::KubernetesEngine {
714+
project_id,
715+
cluster_name,
716+
location,
717+
pod_name,
718+
namespace_name,
719+
container_name,
720+
} => {
721+
labels.insert("project_id".to_string(), project_id);
722+
if let Some(cluster_name) = cluster_name {
723+
labels.insert("cluster_name".to_string(), cluster_name);
724+
}
725+
if let Some(location) = location {
726+
labels.insert("location".to_string(), location);
727+
}
728+
if let Some(pod_name) = pod_name {
729+
labels.insert("pod_name".to_string(), pod_name);
730+
}
731+
if let Some(namespace_name) = namespace_name {
732+
labels.insert("namespace_name".to_string(), namespace_name);
733+
}
734+
if let Some(container_name) = container_name {
735+
labels.insert("container_name".to_string(), container_name);
736+
}
737+
738+
proto::api::MonitoredResource {
739+
r#type: "k8s_container".to_owned(),
740+
labels,
741+
}
742+
}
653743
};
654744

655745
Self {
@@ -665,8 +755,41 @@ impl From<LogContext> for InternalLogContext {
665755
/// Please submit an issue or pull request if you want to use a resource type not listed here.
666756
#[derive(Clone)]
667757
pub enum MonitoredResource {
668-
Global {
758+
AppEngine {
759+
project_id: String,
760+
module_id: Option<String>,
761+
version_id: Option<String>,
762+
zone: Option<String>,
763+
},
764+
CloudFunction {
765+
project_id: String,
766+
function_name: Option<String>,
767+
region: Option<String>,
768+
},
769+
CloudRunJob {
770+
project_id: String,
771+
job_name: Option<String>,
772+
location: Option<String>,
773+
},
774+
CloudRunRevision {
669775
project_id: String,
776+
service_name: Option<String>,
777+
revision_name: Option<String>,
778+
location: Option<String>,
779+
configuration_name: Option<String>,
780+
},
781+
ComputeEngine {
782+
project_id: String,
783+
instance_id: Option<String>,
784+
zone: Option<String>,
785+
},
786+
KubernetesEngine {
787+
project_id: String,
788+
location: Option<String>,
789+
cluster_name: Option<String>,
790+
namespace_name: Option<String>,
791+
pod_name: Option<String>,
792+
container_name: Option<String>,
670793
},
671794
GenericNode {
672795
project_id: String,
@@ -681,17 +804,8 @@ pub enum MonitoredResource {
681804
job: Option<String>,
682805
task_id: Option<String>,
683806
},
684-
CloudRunJob {
685-
project_id: String,
686-
job_name: Option<String>,
687-
location: Option<String>,
688-
},
689-
CloudRunRevision {
807+
Global {
690808
project_id: String,
691-
service_name: Option<String>,
692-
revision_name: Option<String>,
693-
location: Option<String>,
694-
configuration_name: Option<String>,
695809
},
696810
}
697811

0 commit comments

Comments
 (0)