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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//! Contains configurations that are mostly useful for EMF-format metrics
//!
//! The configurations are in this crate in the interest of interoperability
use ;
use crateEntryConfig;
/// This config enables splitting entries in case of multiple dimension values.
///
/// Mostly useful for EMF, but your own custom formatters can use it too.
);
/// This config is used for basic error messages. It allows generating
/// metric entries even if they can't be routed properly (for example,
/// EMF errors missing dimensions) so that something
/// will get out even if globals are misconfigured.
///
/// This config should only be used when emitting a [MetriqueValidationError],
/// using it for other kinds of entries is not supported.
///
/// Even with this option, it should not be possible to emit entries
/// that break the framing format.
);
/// An entry that represents a metrique [`ValidationError`]. This can be
/// used by [`EntrySink`] implementations to allow reporting validation
/// errors "in band".
///
/// The exact reporting format of this error currently uses
/// the property `"MetriqueValidationError"`, but is unstable and subject
/// to change between different `metrique-writer-core` versions.
///
/// This emits the config [AllowUnroutableEntries], which allows it to
/// be emitted even if there are some misconfigurations.
///
/// [`EntrySink`]: crate::EntrySink
/// [`ValidationError`]: crate::ValidationError
/// This struct is mostly useful for the EMF internal implementation
/// Putting this config on an entry will make supporting formatters extend
/// their dimension-sets with the specified dimensions. Currently, this is supported
/// by the EMF formatter by cartesian-producting the dimensions in this struct
/// with its configured ("dev-ops") dimensions.
///
/// This is useful when some of your [`Entry`] members have different dimensions than others.
///
/// ## Example
///
/// ```
/// # use std::borrow::Cow;
/// # use metrique_writer_core::config::EntryDimensions;
/// # use metrique_writer_core::{Entry, EntryWriter};
///
/// struct MyEntry;
/// impl Entry for MyEntry {
/// fn write<'a>(&'a self, writer: &mut impl EntryWriter<'a>) {
/// writer.value("AWSAccountId", "012345678901");
/// writer.value("API", "MyAPI");
/// writer.value("StringProp", "some string value");
/// writer.value("SomeField", &2u32);
/// writer.config(
/// const {
/// &EntryDimensions::new(Cow::Borrowed(&[
/// Cow::Borrowed(&[Cow::Borrowed("API")]),
/// Cow::Borrowed(&[Cow::Borrowed("API"), Cow::Borrowed("StringProp")]),
/// ]))
/// },
/// );
/// // ...
/// }
/// }
/// ```
///
/// Note that if you are using the `metrique` library, you can also get a similar effect
/// with the `#[metrics]` proc macro, at least for the `EntryDimensions` config:
///
/// ```
/// use metrique::unit_of_work::metrics;
///
/// #[metrics(emf::dimension_sets = [[], ["AWSAccountId"]])]
/// struct MyEntry {
/// #[metrics(name = "AWSAccountId")]
/// aws_account_id: String,
/// #[metrics(name = "API")]
/// api: String,
/// string_prop: String,
/// some_field: u32,
/// }
/// ```
///
/// Assuming your `Emf` was created as follows with configured ("dev-ops")
/// dimensions `[[], ["AWSAccountID"]]`:
///
/// ```
/// # use metrique_writer_format_emf::Emf;
/// Emf::all_validations("MyNS".to_string(), vec![vec![], vec!["AWSAccountId".to_string()]])
/// # ;
/// ```
///
/// Then, both when implementing [`Entry`] directly or when using `metrique`,
/// the emitted metric will be emitted under these 4 dimension sets:
///
/// ```notrust
/// ["API"],
/// ["API", "StringProp"],
/// ["AWSAccountId", "API"],
/// ["AWSAccountId", "API", "StringProp"],
/// ```
///
/// [`Entry`]: crate::Entry