Debian Codegraph @

semconv/v1.38.0/azureconv/metric.go

raw
1 // Code generated from semantic convention specification. DO NOT EDIT.
2
3 // Copyright The OpenTelemetry Authors
4 // SPDX-License-Identifier: Apache-2.0
5
6 // Package azureconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "azure" namespace.
8 package azureconv
9
10 import (
11 "context"
12 "sync"
13
14 "go.opentelemetry.io/otel/attribute"
15 "go.opentelemetry.io/otel/metric"
16 "go.opentelemetry.io/otel/metric/noop"
17 )
18
19 var (
20 addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
21 recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
22 )
23
24 // CosmosDBConsistencyLevelAttr is an attribute conforming to the
25 // azure.cosmosdb.consistency.level semantic conventions. It represents the
26 // account or request [consistency level].
27 //
28 // [consistency level]: https://learn.microsoft.com/azure/cosmos-db/consistency-levels
29 type CosmosDBConsistencyLevelAttr string
30
31 var (
32 // CosmosDBConsistencyLevelStrong is the strong.
33 CosmosDBConsistencyLevelStrong CosmosDBConsistencyLevelAttr = "Strong"
34 // CosmosDBConsistencyLevelBoundedStaleness is the bounded Staleness.
35 CosmosDBConsistencyLevelBoundedStaleness CosmosDBConsistencyLevelAttr = "BoundedStaleness"
36 // CosmosDBConsistencyLevelSession is the session.
37 CosmosDBConsistencyLevelSession CosmosDBConsistencyLevelAttr = "Session"
38 // CosmosDBConsistencyLevelEventual is the eventual.
39 CosmosDBConsistencyLevelEventual CosmosDBConsistencyLevelAttr = "Eventual"
40 // CosmosDBConsistencyLevelConsistentPrefix is the consistent Prefix.
41 CosmosDBConsistencyLevelConsistentPrefix CosmosDBConsistencyLevelAttr = "ConsistentPrefix"
42 )
43
44 // ErrorTypeAttr is an attribute conforming to the error.type semantic
45 // conventions. It represents the describes a class of error the operation ended
46 // with.
47 type ErrorTypeAttr string
48
49 var (
50 // ErrorTypeOther is a fallback error value to be used when the instrumentation
51 // doesn't define a custom value.
52 ErrorTypeOther ErrorTypeAttr = "_OTHER"
53 )
54
55 // CosmosDBClientActiveInstanceCount is an instrument used to record metric
56 // values conforming to the "azure.cosmosdb.client.active_instance.count"
57 // semantic conventions. It represents the number of active client instances.
58 type CosmosDBClientActiveInstanceCount struct {
59 metric.Int64UpDownCounter
60 }
61
62 var newCosmosDBClientActiveInstanceCountOpts = []metric.Int64UpDownCounterOption{
63 metric.WithDescription("Number of active client instances."),
64 metric.WithUnit("{instance}"),
65 }
66
67 // NewCosmosDBClientActiveInstanceCount returns a new
68 // CosmosDBClientActiveInstanceCount instrument.
69 func NewCosmosDBClientActiveInstanceCount(
70 m metric.Meter,
71 opt ...metric.Int64UpDownCounterOption,
72 ) (CosmosDBClientActiveInstanceCount, error) {
73 // Check if the meter is nil.
74 if m == nil {
75 return CosmosDBClientActiveInstanceCount{noop.Int64UpDownCounter{}}, nil
76 }
77
78 if len(opt) == 0 {
79 opt = newCosmosDBClientActiveInstanceCountOpts
80 } else {
81 opt = append(opt, newCosmosDBClientActiveInstanceCountOpts...)
82 }
83
84 i, err := m.Int64UpDownCounter(
85 "azure.cosmosdb.client.active_instance.count",
86 opt...,
87 )
88 if err != nil {
89 return CosmosDBClientActiveInstanceCount{noop.Int64UpDownCounter{}}, err
90 }
91 return CosmosDBClientActiveInstanceCount{i}, nil
92 }
93
94 // Inst returns the underlying metric instrument.
95 func (m CosmosDBClientActiveInstanceCount) Inst() metric.Int64UpDownCounter {
96 return m.Int64UpDownCounter
97 }
98
99 // Name returns the semantic convention name of the instrument.
100 func (CosmosDBClientActiveInstanceCount) Name() string {
101 return "azure.cosmosdb.client.active_instance.count"
102 }
103
104 // Unit returns the semantic convention unit of the instrument
105 func (CosmosDBClientActiveInstanceCount) Unit() string {
106 return "{instance}"
107 }
108
109 // Description returns the semantic convention description of the instrument
110 func (CosmosDBClientActiveInstanceCount) Description() string {
111 return "Number of active client instances."
112 }
113
114 // Add adds incr to the existing count for attrs.
115 //
116 // All additional attrs passed are included in the recorded value.
117 func (m CosmosDBClientActiveInstanceCount) Add(
118 ctx context.Context,
119 incr int64,
120 attrs ...attribute.KeyValue,
121 ) {
122 if len(attrs) == 0 {
123 m.Int64UpDownCounter.Add(ctx, incr)
124 return
125 }
126
127 o := addOptPool.Get().(*[]metric.AddOption)
128 defer func() {
129 *o = (*o)[:0]
130 addOptPool.Put(o)
131 }()
132
133 *o = append(
134 *o,
135 metric.WithAttributes(
136 attrs...,
137 ),
138 )
139
140 m.Int64UpDownCounter.Add(ctx, incr, *o...)
141 }
142
143 // AddSet adds incr to the existing count for set.
144 func (m CosmosDBClientActiveInstanceCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
145 if set.Len() == 0 {
146 m.Int64UpDownCounter.Add(ctx, incr)
147 return
148 }
149
150 o := addOptPool.Get().(*[]metric.AddOption)
151 defer func() {
152 *o = (*o)[:0]
153 addOptPool.Put(o)
154 }()
155
156 *o = append(*o, metric.WithAttributeSet(set))
157 m.Int64UpDownCounter.Add(ctx, incr, *o...)
158 }
159
160 // AttrServerPort returns an optional attribute for the "server.port" semantic
161 // convention. It represents the server port number.
162 func (CosmosDBClientActiveInstanceCount) AttrServerPort(val int) attribute.KeyValue {
163 return attribute.Int("server.port", val)
164 }
165
166 // AttrServerAddress returns an optional attribute for the "server.address"
167 // semantic convention. It represents the name of the database host.
168 func (CosmosDBClientActiveInstanceCount) AttrServerAddress(val string) attribute.KeyValue {
169 return attribute.String("server.address", val)
170 }
171
172 // CosmosDBClientOperationRequestCharge is an instrument used to record metric
173 // values conforming to the "azure.cosmosdb.client.operation.request_charge"
174 // semantic conventions. It represents the [Request units] consumed by the
175 // operation.
176 //
177 // [Request units]: https://learn.microsoft.com/azure/cosmos-db/request-units
178 type CosmosDBClientOperationRequestCharge struct {
179 metric.Int64Histogram
180 }
181
182 var newCosmosDBClientOperationRequestChargeOpts = []metric.Int64HistogramOption{
183 metric.WithDescription("[Request units](https://learn.microsoft.com/azure/cosmos-db/request-units) consumed by the operation."),
184 metric.WithUnit("{request_unit}"),
185 }
186
187 // NewCosmosDBClientOperationRequestCharge returns a new
188 // CosmosDBClientOperationRequestCharge instrument.
189 func NewCosmosDBClientOperationRequestCharge(
190 m metric.Meter,
191 opt ...metric.Int64HistogramOption,
192 ) (CosmosDBClientOperationRequestCharge, error) {
193 // Check if the meter is nil.
194 if m == nil {
195 return CosmosDBClientOperationRequestCharge{noop.Int64Histogram{}}, nil
196 }
197
198 if len(opt) == 0 {
199 opt = newCosmosDBClientOperationRequestChargeOpts
200 } else {
201 opt = append(opt, newCosmosDBClientOperationRequestChargeOpts...)
202 }
203
204 i, err := m.Int64Histogram(
205 "azure.cosmosdb.client.operation.request_charge",
206 opt...,
207 )
208 if err != nil {
209 return CosmosDBClientOperationRequestCharge{noop.Int64Histogram{}}, err
210 }
211 return CosmosDBClientOperationRequestCharge{i}, nil
212 }
213
214 // Inst returns the underlying metric instrument.
215 func (m CosmosDBClientOperationRequestCharge) Inst() metric.Int64Histogram {
216 return m.Int64Histogram
217 }
218
219 // Name returns the semantic convention name of the instrument.
220 func (CosmosDBClientOperationRequestCharge) Name() string {
221 return "azure.cosmosdb.client.operation.request_charge"
222 }
223
224 // Unit returns the semantic convention unit of the instrument
225 func (CosmosDBClientOperationRequestCharge) Unit() string {
226 return "{request_unit}"
227 }
228
229 // Description returns the semantic convention description of the instrument
230 func (CosmosDBClientOperationRequestCharge) Description() string {
231 return "[Request units](https://learn.microsoft.com/azure/cosmos-db/request-units) consumed by the operation."
232 }
233
234 // Record records val to the current distribution for attrs.
235 //
236 // The dbOperationName is the the name of the operation or command being
237 // executed.
238 //
239 // All additional attrs passed are included in the recorded value.
240 func (m CosmosDBClientOperationRequestCharge) Record(
241 ctx context.Context,
242 val int64,
243 dbOperationName string,
244 attrs ...attribute.KeyValue,
245 ) {
246 if len(attrs) == 0 {
247 m.Int64Histogram.Record(ctx, val)
248 return
249 }
250
251 o := recOptPool.Get().(*[]metric.RecordOption)
252 defer func() {
253 *o = (*o)[:0]
254 recOptPool.Put(o)
255 }()
256
257 *o = append(
258 *o,
259 metric.WithAttributes(
260 append(
261 attrs,
262 attribute.String("db.operation.name", dbOperationName),
263 )...,
264 ),
265 )
266
267 m.Int64Histogram.Record(ctx, val, *o...)
268 }
269
270 // RecordSet records val to the current distribution for set.
271 func (m CosmosDBClientOperationRequestCharge) RecordSet(ctx context.Context, val int64, set attribute.Set) {
272 if set.Len() == 0 {
273 m.Int64Histogram.Record(ctx, val)
274 return
275 }
276
277 o := recOptPool.Get().(*[]metric.RecordOption)
278 defer func() {
279 *o = (*o)[:0]
280 recOptPool.Put(o)
281 }()
282
283 *o = append(*o, metric.WithAttributeSet(set))
284 m.Int64Histogram.Record(ctx, val, *o...)
285 }
286
287 // AttrCosmosDBConsistencyLevel returns an optional attribute for the
288 // "azure.cosmosdb.consistency.level" semantic convention. It represents the
289 // account or request [consistency level].
290 //
291 // [consistency level]: https://learn.microsoft.com/azure/cosmos-db/consistency-levels
292 func (CosmosDBClientOperationRequestCharge) AttrCosmosDBConsistencyLevel(val CosmosDBConsistencyLevelAttr) attribute.KeyValue {
293 return attribute.String("azure.cosmosdb.consistency.level", string(val))
294 }
295
296 // AttrCosmosDBResponseSubStatusCode returns an optional attribute for the
297 // "azure.cosmosdb.response.sub_status_code" semantic convention. It represents
298 // the cosmos DB sub status code.
299 func (CosmosDBClientOperationRequestCharge) AttrCosmosDBResponseSubStatusCode(val int) attribute.KeyValue {
300 return attribute.Int("azure.cosmosdb.response.sub_status_code", val)
301 }
302
303 // AttrDBCollectionName returns an optional attribute for the
304 // "db.collection.name" semantic convention. It represents the cosmos DB
305 // container name.
306 func (CosmosDBClientOperationRequestCharge) AttrDBCollectionName(val string) attribute.KeyValue {
307 return attribute.String("db.collection.name", val)
308 }
309
310 // AttrDBNamespace returns an optional attribute for the "db.namespace" semantic
311 // convention. It represents the name of the database, fully qualified within the
312 // server address and port.
313 func (CosmosDBClientOperationRequestCharge) AttrDBNamespace(val string) attribute.KeyValue {
314 return attribute.String("db.namespace", val)
315 }
316
317 // AttrDBResponseStatusCode returns an optional attribute for the
318 // "db.response.status_code" semantic convention. It represents the database
319 // response status code.
320 func (CosmosDBClientOperationRequestCharge) AttrDBResponseStatusCode(val string) attribute.KeyValue {
321 return attribute.String("db.response.status_code", val)
322 }
323
324 // AttrErrorType returns an optional attribute for the "error.type" semantic
325 // convention. It represents the describes a class of error the operation ended
326 // with.
327 func (CosmosDBClientOperationRequestCharge) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
328 return attribute.String("error.type", string(val))
329 }
330
331 // AttrServerPort returns an optional attribute for the "server.port" semantic
332 // convention. It represents the server port number.
333 func (CosmosDBClientOperationRequestCharge) AttrServerPort(val int) attribute.KeyValue {
334 return attribute.Int("server.port", val)
335 }
336
337 // AttrCosmosDBOperationContactedRegions returns an optional attribute for the
338 // "azure.cosmosdb.operation.contacted_regions" semantic convention. It
339 // represents the list of regions contacted during operation in the order that
340 // they were contacted. If there is more than one region listed, it indicates
341 // that the operation was performed on multiple regions i.e. cross-regional call.
342 func (CosmosDBClientOperationRequestCharge) AttrCosmosDBOperationContactedRegions(val ...string) attribute.KeyValue {
343 return attribute.StringSlice("azure.cosmosdb.operation.contacted_regions", val)
344 }
345
346 // AttrServerAddress returns an optional attribute for the "server.address"
347 // semantic convention. It represents the name of the database host.
348 func (CosmosDBClientOperationRequestCharge) AttrServerAddress(val string) attribute.KeyValue {
349 return attribute.String("server.address", val)
350 }