1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use crate::metrics::{InstrumentConfig, InstrumentKind, NumberKind};
use crate::sdk::InstrumentationLibrary;
use fnv::FnvHasher;
use std::borrow::Cow;
use std::hash::{Hash, Hasher};
#[derive(Clone, Debug, PartialEq)]
pub struct Descriptor {
name: String,
instrument_kind: InstrumentKind,
number_kind: NumberKind,
pub(crate) config: InstrumentConfig,
attribute_hash: u64,
}
impl Descriptor {
pub fn new<T: Into<Cow<'static, str>>>(
name: String,
instrumentation_name: T,
instrumentation_version: Option<T>,
instrument_kind: InstrumentKind,
number_kind: NumberKind,
) -> Self {
let mut hasher = FnvHasher::default();
name.hash(&mut hasher);
let instrumentation_name = instrumentation_name.into();
let instrumentation_version = instrumentation_version.map(Into::<Cow<'static, str>>::into);
instrumentation_name.as_ref().hash(&mut hasher);
instrumentation_version.as_ref().hash(&mut hasher);
instrument_kind.hash(&mut hasher);
number_kind.hash(&mut hasher);
let config =
InstrumentConfig::with_instrumentation(instrumentation_name, instrumentation_version);
Descriptor {
name,
instrument_kind,
number_kind,
config,
attribute_hash: hasher.finish(),
}
}
pub fn name(&self) -> &str {
self.name.as_str()
}
pub fn instrument_kind(&self) -> &InstrumentKind {
&self.instrument_kind
}
pub fn number_kind(&self) -> &NumberKind {
&self.number_kind
}
pub fn description(&self) -> Option<&String> {
self.config.description.as_ref()
}
pub fn set_description(&mut self, description: String) {
self.config.description = Some(description);
}
pub fn unit(&self) -> Option<&str> {
self.config.unit.as_ref().map(|unit| unit.as_ref())
}
pub fn instrumentation_name(&self) -> Cow<'static, str> {
self.config.instrumentation_name()
}
pub fn instrumentation_version(&self) -> Option<Cow<'static, str>> {
self.config.instrumentation_version()
}
pub fn instrumentation_library(&self) -> &InstrumentationLibrary {
&self.config.instrumentation_library
}
pub fn attribute_hash(&self) -> u64 {
self.attribute_hash
}
}