Debian Codegraph @

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