Debian Codegraph @

semconv/v1.39.0/signalrconv/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 signalrconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "signalr" namespace.
8 package signalrconv
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 // ConnectionStatusAttr is an attribute conforming to the
25 // signalr.connection.status semantic conventions. It represents the signalR HTTP
26 // connection closure status.
27 type ConnectionStatusAttr string
28
29 var (
30 // ConnectionStatusNormalClosure is the connection was closed normally.
31 ConnectionStatusNormalClosure ConnectionStatusAttr = "normal_closure"
32 // ConnectionStatusTimeout is the connection was closed due to a timeout.
33 ConnectionStatusTimeout ConnectionStatusAttr = "timeout"
34 // ConnectionStatusAppShutdown is the connection was closed because the app is
35 // shutting down.
36 ConnectionStatusAppShutdown ConnectionStatusAttr = "app_shutdown"
37 )
38
39 // TransportAttr is an attribute conforming to the signalr.transport semantic
40 // conventions. It represents the [SignalR transport type].
41 //
42 // [SignalR transport type]: https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md
43 type TransportAttr string
44
45 var (
46 // TransportServerSentEvents is the serverSentEvents protocol.
47 TransportServerSentEvents TransportAttr = "server_sent_events"
48 // TransportLongPolling is the longPolling protocol.
49 TransportLongPolling TransportAttr = "long_polling"
50 // TransportWebSockets is the webSockets protocol.
51 TransportWebSockets TransportAttr = "web_sockets"
52 )
53
54 // ServerActiveConnections is an instrument used to record metric values
55 // conforming to the "signalr.server.active_connections" semantic conventions. It
56 // represents the number of connections that are currently active on the server.
57 type ServerActiveConnections struct {
58 metric.Int64UpDownCounter
59 }
60
61 var newServerActiveConnectionsOpts = []metric.Int64UpDownCounterOption{
62 metric.WithDescription("Number of connections that are currently active on the server."),
63 metric.WithUnit("{connection}"),
64 }
65
66 // NewServerActiveConnections returns a new ServerActiveConnections instrument.
67 func NewServerActiveConnections(
68 m metric.Meter,
69 opt ...metric.Int64UpDownCounterOption,
70 ) (ServerActiveConnections, error) {
71 // Check if the meter is nil.
72 if m == nil {
73 return ServerActiveConnections{noop.Int64UpDownCounter{}}, nil
74 }
75
76 if len(opt) == 0 {
77 opt = newServerActiveConnectionsOpts
78 } else {
79 opt = append(opt, newServerActiveConnectionsOpts...)
80 }
81
82 i, err := m.Int64UpDownCounter(
83 "signalr.server.active_connections",
84 opt...,
85 )
86 if err != nil {
87 return ServerActiveConnections{noop.Int64UpDownCounter{}}, err
88 }
89 return ServerActiveConnections{i}, nil
90 }
91
92 // Inst returns the underlying metric instrument.
93 func (m ServerActiveConnections) Inst() metric.Int64UpDownCounter {
94 return m.Int64UpDownCounter
95 }
96
97 // Name returns the semantic convention name of the instrument.
98 func (ServerActiveConnections) Name() string {
99 return "signalr.server.active_connections"
100 }
101
102 // Unit returns the semantic convention unit of the instrument
103 func (ServerActiveConnections) Unit() string {
104 return "{connection}"
105 }
106
107 // Description returns the semantic convention description of the instrument
108 func (ServerActiveConnections) Description() string {
109 return "Number of connections that are currently active on the server."
110 }
111
112 // Add adds incr to the existing count for attrs.
113 //
114 // All additional attrs passed are included in the recorded value.
115 //
116 // Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
117 // 8.0
118 func (m ServerActiveConnections) Add(
119 ctx context.Context,
120 incr int64,
121 attrs ...attribute.KeyValue,
122 ) {
123 if len(attrs) == 0 {
124 m.Int64UpDownCounter.Add(ctx, incr)
125 return
126 }
127
128 o := addOptPool.Get().(*[]metric.AddOption)
129 defer func() {
130 *o = (*o)[:0]
131 addOptPool.Put(o)
132 }()
133
134 *o = append(
135 *o,
136 metric.WithAttributes(
137 attrs...,
138 ),
139 )
140
141 m.Int64UpDownCounter.Add(ctx, incr, *o...)
142 }
143
144 // AddSet adds incr to the existing count for set.
145 //
146 // Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
147 // 8.0
148 func (m ServerActiveConnections) AddSet(ctx context.Context, incr int64, set attribute.Set) {
149 if set.Len() == 0 {
150 m.Int64UpDownCounter.Add(ctx, incr)
151 return
152 }
153
154 o := addOptPool.Get().(*[]metric.AddOption)
155 defer func() {
156 *o = (*o)[:0]
157 addOptPool.Put(o)
158 }()
159
160 *o = append(*o, metric.WithAttributeSet(set))
161 m.Int64UpDownCounter.Add(ctx, incr, *o...)
162 }
163
164 // AttrConnectionStatus returns an optional attribute for the
165 // "signalr.connection.status" semantic convention. It represents the signalR
166 // HTTP connection closure status.
167 func (ServerActiveConnections) AttrConnectionStatus(val ConnectionStatusAttr) attribute.KeyValue {
168 return attribute.String("signalr.connection.status", string(val))
169 }
170
171 // AttrTransport returns an optional attribute for the "signalr.transport"
172 // semantic convention. It represents the [SignalR transport type].
173 //
174 // [SignalR transport type]: https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md
175 func (ServerActiveConnections) AttrTransport(val TransportAttr) attribute.KeyValue {
176 return attribute.String("signalr.transport", string(val))
177 }
178
179 // ServerConnectionDuration is an instrument used to record metric values
180 // conforming to the "signalr.server.connection.duration" semantic conventions.
181 // It represents the duration of connections on the server.
182 type ServerConnectionDuration struct {
183 metric.Float64Histogram
184 }
185
186 var newServerConnectionDurationOpts = []metric.Float64HistogramOption{
187 metric.WithDescription("The duration of connections on the server."),
188 metric.WithUnit("s"),
189 }
190
191 // NewServerConnectionDuration returns a new ServerConnectionDuration instrument.
192 func NewServerConnectionDuration(
193 m metric.Meter,
194 opt ...metric.Float64HistogramOption,
195 ) (ServerConnectionDuration, error) {
196 // Check if the meter is nil.
197 if m == nil {
198 return ServerConnectionDuration{noop.Float64Histogram{}}, nil
199 }
200
201 if len(opt) == 0 {
202 opt = newServerConnectionDurationOpts
203 } else {
204 opt = append(opt, newServerConnectionDurationOpts...)
205 }
206
207 i, err := m.Float64Histogram(
208 "signalr.server.connection.duration",
209 opt...,
210 )
211 if err != nil {
212 return ServerConnectionDuration{noop.Float64Histogram{}}, err
213 }
214 return ServerConnectionDuration{i}, nil
215 }
216
217 // Inst returns the underlying metric instrument.
218 func (m ServerConnectionDuration) Inst() metric.Float64Histogram {
219 return m.Float64Histogram
220 }
221
222 // Name returns the semantic convention name of the instrument.
223 func (ServerConnectionDuration) Name() string {
224 return "signalr.server.connection.duration"
225 }
226
227 // Unit returns the semantic convention unit of the instrument
228 func (ServerConnectionDuration) Unit() string {
229 return "s"
230 }
231
232 // Description returns the semantic convention description of the instrument
233 func (ServerConnectionDuration) Description() string {
234 return "The duration of connections on the server."
235 }
236
237 // Record records val to the current distribution for attrs.
238 //
239 // All additional attrs passed are included in the recorded value.
240 //
241 // Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
242 // 8.0
243 func (m ServerConnectionDuration) Record(
244 ctx context.Context,
245 val float64,
246 attrs ...attribute.KeyValue,
247 ) {
248 if len(attrs) == 0 {
249 m.Float64Histogram.Record(ctx, val)
250 return
251 }
252
253 o := recOptPool.Get().(*[]metric.RecordOption)
254 defer func() {
255 *o = (*o)[:0]
256 recOptPool.Put(o)
257 }()
258
259 *o = append(
260 *o,
261 metric.WithAttributes(
262 attrs...,
263 ),
264 )
265
266 m.Float64Histogram.Record(ctx, val, *o...)
267 }
268
269 // RecordSet records val to the current distribution for set.
270 //
271 // Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
272 // 8.0
273 func (m ServerConnectionDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
274 if set.Len() == 0 {
275 m.Float64Histogram.Record(ctx, val)
276 return
277 }
278
279 o := recOptPool.Get().(*[]metric.RecordOption)
280 defer func() {
281 *o = (*o)[:0]
282 recOptPool.Put(o)
283 }()
284
285 *o = append(*o, metric.WithAttributeSet(set))
286 m.Float64Histogram.Record(ctx, val, *o...)
287 }
288
289 // AttrConnectionStatus returns an optional attribute for the
290 // "signalr.connection.status" semantic convention. It represents the signalR
291 // HTTP connection closure status.
292 func (ServerConnectionDuration) AttrConnectionStatus(val ConnectionStatusAttr) attribute.KeyValue {
293 return attribute.String("signalr.connection.status", string(val))
294 }
295
296 // AttrTransport returns an optional attribute for the "signalr.transport"
297 // semantic convention. It represents the [SignalR transport type].
298 //
299 // [SignalR transport type]: https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md
300 func (ServerConnectionDuration) AttrTransport(val TransportAttr) attribute.KeyValue {
301 return attribute.String("signalr.transport", string(val))
302 }