Debian Codegraph @

semconv/v1.32.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 none.
33 CosmosDBConsistencyLevelStrong CosmosDBConsistencyLevelAttr = "Strong"
34 // CosmosDBConsistencyLevelBoundedStaleness is the none.
35 CosmosDBConsistencyLevelBoundedStaleness CosmosDBConsistencyLevelAttr = "BoundedStaleness"
36 // CosmosDBConsistencyLevelSession is the none.
37 CosmosDBConsistencyLevelSession CosmosDBConsistencyLevelAttr = "Session"
38 // CosmosDBConsistencyLevelEventual is the none.
39 CosmosDBConsistencyLevelEventual CosmosDBConsistencyLevelAttr = "Eventual"
40 // CosmosDBConsistencyLevelConsistentPrefix is the none.
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 // NewCosmosDBClientActiveInstanceCount returns a new
63 // CosmosDBClientActiveInstanceCount instrument.
64 func NewCosmosDBClientActiveInstanceCount(
65 m metric.Meter,
66 opt ...metric.Int64UpDownCounterOption,
67 ) (CosmosDBClientActiveInstanceCount, error) {
68 // Check if the meter is nil.
69 if m == nil {
70 return CosmosDBClientActiveInstanceCount{noop.Int64UpDownCounter{}}, nil
71 }
72
73 i, err := m.Int64UpDownCounter(
74 "azure.cosmosdb.client.active_instance.count",
75 append([]metric.Int64UpDownCounterOption{
76 metric.WithDescription("Number of active client instances"),
77 metric.WithUnit("{instance}"),
78 }, opt...)...,
79 )
80 if err != nil {
81 return CosmosDBClientActiveInstanceCount{noop.Int64UpDownCounter{}}, err
82 }
83 return CosmosDBClientActiveInstanceCount{i}, nil
84 }
85
86 // Inst returns the underlying metric instrument.
87 func (m CosmosDBClientActiveInstanceCount) Inst() metric.Int64UpDownCounter {
88 return m.Int64UpDownCounter
89 }
90
91 // Name returns the semantic convention name of the instrument.
92 func (CosmosDBClientActiveInstanceCount) Name() string {
93 return "azure.cosmosdb.client.active_instance.count"
94 }
95
96 // Unit returns the semantic convention unit of the instrument
97 func (CosmosDBClientActiveInstanceCount) Unit() string {
98 return "{instance}"
99 }
100
101 // Description returns the semantic convention description of the instrument
102 func (CosmosDBClientActiveInstanceCount) Description() string {
103 return "Number of active client instances"
104 }
105
106 // Add adds incr to the existing count.
107 //
108 // All additional attrs passed are included in the recorded value.
109 func (m CosmosDBClientActiveInstanceCount) Add(
110 ctx context.Context,
111 incr int64,
112 attrs ...attribute.KeyValue,
113 ) {
114 o := addOptPool.Get().(*[]metric.AddOption)
115 defer func() {
116 *o = (*o)[:0]
117 addOptPool.Put(o)
118 }()
119
120 *o = append(
121 *o,
122 metric.WithAttributes(
123 attrs...,
124 ),
125 )
126
127 m.Int64UpDownCounter.Add(ctx, incr, *o...)
128 }
129
130 // AttrServerPort returns an optional attribute for the "server.port" semantic
131 // convention. It represents the server port number.
132 func (CosmosDBClientActiveInstanceCount) AttrServerPort(val int) attribute.KeyValue {
133 return attribute.Int("server.port", val)
134 }
135
136 // AttrServerAddress returns an optional attribute for the "server.address"
137 // semantic convention. It represents the name of the database host.
138 func (CosmosDBClientActiveInstanceCount) AttrServerAddress(val string) attribute.KeyValue {
139 return attribute.String("server.address", val)
140 }
141
142 // CosmosDBClientOperationRequestCharge is an instrument used to record metric
143 // values conforming to the "azure.cosmosdb.client.operation.request_charge"
144 // semantic conventions. It represents the [Request units] consumed by the
145 // operation.
146 //
147 // [Request units]: https://learn.microsoft.com/azure/cosmos-db/request-units
148 type CosmosDBClientOperationRequestCharge struct {
149 metric.Int64Histogram
150 }
151
152 // NewCosmosDBClientOperationRequestCharge returns a new
153 // CosmosDBClientOperationRequestCharge instrument.
154 func NewCosmosDBClientOperationRequestCharge(
155 m metric.Meter,
156 opt ...metric.Int64HistogramOption,
157 ) (CosmosDBClientOperationRequestCharge, error) {
158 // Check if the meter is nil.
159 if m == nil {
160 return CosmosDBClientOperationRequestCharge{noop.Int64Histogram{}}, nil
161 }
162
163 i, err := m.Int64Histogram(
164 "azure.cosmosdb.client.operation.request_charge",
165 append([]metric.Int64HistogramOption{
166 metric.WithDescription("[Request units](https://learn.microsoft.com/azure/cosmos-db/request-units) consumed by the operation"),
167 metric.WithUnit("{request_unit}"),
168 }, opt...)...,
169 )
170 if err != nil {
171 return CosmosDBClientOperationRequestCharge{noop.Int64Histogram{}}, err
172 }
173 return CosmosDBClientOperationRequestCharge{i}, nil
174 }
175
176 // Inst returns the underlying metric instrument.
177 func (m CosmosDBClientOperationRequestCharge) Inst() metric.Int64Histogram {
178 return m.Int64Histogram
179 }
180
181 // Name returns the semantic convention name of the instrument.
182 func (CosmosDBClientOperationRequestCharge) Name() string {
183 return "azure.cosmosdb.client.operation.request_charge"
184 }
185
186 // Unit returns the semantic convention unit of the instrument
187 func (CosmosDBClientOperationRequestCharge) Unit() string {
188 return "{request_unit}"
189 }
190
191 // Description returns the semantic convention description of the instrument
192 func (CosmosDBClientOperationRequestCharge) Description() string {
193 return "[Request units](https://learn.microsoft.com/azure/cosmos-db/request-units) consumed by the operation"
194 }
195
196 // Record records val to the current distribution.
197 //
198 // All additional attrs passed are included in the recorded value.
199 func (m CosmosDBClientOperationRequestCharge) Record(
200 ctx context.Context,
201 val int64,
202 attrs ...attribute.KeyValue,
203 ) {
204 o := recOptPool.Get().(*[]metric.RecordOption)
205 defer func() {
206 *o = (*o)[:0]
207 recOptPool.Put(o)
208 }()
209
210 *o = append(
211 *o,
212 metric.WithAttributes(
213 attrs...,
214 ),
215 )
216
217 m.Int64Histogram.Record(ctx, val, *o...)
218 }
219
220 // AttrCosmosDBConsistencyLevel returns an optional attribute for the
221 // "azure.cosmosdb.consistency.level" semantic convention. It represents the
222 // account or request [consistency level].
223 //
224 // [consistency level]: https://learn.microsoft.com/azure/cosmos-db/consistency-levels
225 func (CosmosDBClientOperationRequestCharge) AttrCosmosDBConsistencyLevel(val CosmosDBConsistencyLevelAttr) attribute.KeyValue {
226 return attribute.String("azure.cosmosdb.consistency.level", string(val))
227 }
228
229 // AttrCosmosDBResponseSubStatusCode returns an optional attribute for the
230 // "azure.cosmosdb.response.sub_status_code" semantic convention. It represents
231 // the cosmos DB sub status code.
232 func (CosmosDBClientOperationRequestCharge) AttrCosmosDBResponseSubStatusCode(val int) attribute.KeyValue {
233 return attribute.Int("azure.cosmosdb.response.sub_status_code", val)
234 }
235
236 // AttrDBCollectionName returns an optional attribute for the
237 // "db.collection.name" semantic convention. It represents the cosmos DB
238 // container name.
239 func (CosmosDBClientOperationRequestCharge) AttrDBCollectionName(val string) attribute.KeyValue {
240 return attribute.String("db.collection.name", val)
241 }
242
243 // AttrDBNamespace returns an optional attribute for the "db.namespace" semantic
244 // convention. It represents the name of the database, fully qualified within the
245 // server address and port.
246 func (CosmosDBClientOperationRequestCharge) AttrDBNamespace(val string) attribute.KeyValue {
247 return attribute.String("db.namespace", val)
248 }
249
250 // AttrDBOperationName returns an optional attribute for the "db.operation.name"
251 // semantic convention. It represents the name of the operation or command being
252 // executed.
253 func (CosmosDBClientOperationRequestCharge) AttrDBOperationName(val string) attribute.KeyValue {
254 return attribute.String("db.operation.name", val)
255 }
256
257 // AttrDBResponseStatusCode returns an optional attribute for the
258 // "db.response.status_code" semantic convention. It represents the database
259 // response status code.
260 func (CosmosDBClientOperationRequestCharge) AttrDBResponseStatusCode(val string) attribute.KeyValue {
261 return attribute.String("db.response.status_code", val)
262 }
263
264 // AttrErrorType returns an optional attribute for the "error.type" semantic
265 // convention. It represents the describes a class of error the operation ended
266 // with.
267 func (CosmosDBClientOperationRequestCharge) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
268 return attribute.String("error.type", string(val))
269 }
270
271 // AttrServerPort returns an optional attribute for the "server.port" semantic
272 // convention. It represents the server port number.
273 func (CosmosDBClientOperationRequestCharge) AttrServerPort(val int) attribute.KeyValue {
274 return attribute.Int("server.port", val)
275 }
276
277 // AttrCosmosDBOperationContactedRegions returns an optional attribute for the
278 // "azure.cosmosdb.operation.contacted_regions" semantic convention. It
279 // represents the list of regions contacted during operation in the order that
280 // they were contacted. If there is more than one region listed, it indicates
281 // that the operation was performed on multiple regions i.e. cross-regional call.
282 func (CosmosDBClientOperationRequestCharge) AttrCosmosDBOperationContactedRegions(val ...string) attribute.KeyValue {
283 return attribute.StringSlice("azure.cosmosdb.operation.contacted_regions", val)
284 }
285
286 // AttrServerAddress returns an optional attribute for the "server.address"
287 // semantic convention. It represents the name of the database host.
288 func (CosmosDBClientOperationRequestCharge) AttrServerAddress(val string) attribute.KeyValue {
289 return attribute.String("server.address", val)
290 }