Debian Codegraph @

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