Debian Codegraph @

semconv/v1.34.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.
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 o := addOptPool.Get().(*[]metric.AddOption)
116 defer func() {
117 *o = (*o)[:0]
118 addOptPool.Put(o)
119 }()
120
121 *o = append(
122 *o,
123 metric.WithAttributes(
124 attrs...,
125 ),
126 )
127
128 m.Int64UpDownCounter.Add(ctx, incr, *o...)
129 }
130
131 // AttrConnectionStatus returns an optional attribute for the
132 // "signalr.connection.status" semantic convention. It represents the signalR
133 // HTTP connection closure status.
134 func (ServerActiveConnections) AttrConnectionStatus(val ConnectionStatusAttr) attribute.KeyValue {
135 return attribute.String("signalr.connection.status", string(val))
136 }
137
138 // AttrTransport returns an optional attribute for the "signalr.transport"
139 // semantic convention. It represents the [SignalR transport type].
140 //
141 // [SignalR transport type]: https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md
142 func (ServerActiveConnections) AttrTransport(val TransportAttr) attribute.KeyValue {
143 return attribute.String("signalr.transport", string(val))
144 }
145
146 // ServerConnectionDuration is an instrument used to record metric values
147 // conforming to the "signalr.server.connection.duration" semantic conventions.
148 // It represents the duration of connections on the server.
149 type ServerConnectionDuration struct {
150 metric.Float64Histogram
151 }
152
153 // NewServerConnectionDuration returns a new ServerConnectionDuration instrument.
154 func NewServerConnectionDuration(
155 m metric.Meter,
156 opt ...metric.Float64HistogramOption,
157 ) (ServerConnectionDuration, error) {
158 // Check if the meter is nil.
159 if m == nil {
160 return ServerConnectionDuration{noop.Float64Histogram{}}, nil
161 }
162
163 i, err := m.Float64Histogram(
164 "signalr.server.connection.duration",
165 append([]metric.Float64HistogramOption{
166 metric.WithDescription("The duration of connections on the server."),
167 metric.WithUnit("s"),
168 }, opt...)...,
169 )
170 if err != nil {
171 return ServerConnectionDuration{noop.Float64Histogram{}}, err
172 }
173 return ServerConnectionDuration{i}, nil
174 }
175
176 // Inst returns the underlying metric instrument.
177 func (m ServerConnectionDuration) Inst() metric.Float64Histogram {
178 return m.Float64Histogram
179 }
180
181 // Name returns the semantic convention name of the instrument.
182 func (ServerConnectionDuration) Name() string {
183 return "signalr.server.connection.duration"
184 }
185
186 // Unit returns the semantic convention unit of the instrument
187 func (ServerConnectionDuration) Unit() string {
188 return "s"
189 }
190
191 // Description returns the semantic convention description of the instrument
192 func (ServerConnectionDuration) Description() string {
193 return "The duration of connections on the server."
194 }
195
196 // Record records val to the current distribution.
197 //
198 // All additional attrs passed are included in the recorded value.
199 //
200 // Meter name: `Microsoft.AspNetCore.Http.Connections`; Added in: ASP.NET Core
201 // 8.0
202 func (m ServerConnectionDuration) Record(
203 ctx context.Context,
204 val float64,
205 attrs ...attribute.KeyValue,
206 ) {
207 o := recOptPool.Get().(*[]metric.RecordOption)
208 defer func() {
209 *o = (*o)[:0]
210 recOptPool.Put(o)
211 }()
212
213 *o = append(
214 *o,
215 metric.WithAttributes(
216 attrs...,
217 ),
218 )
219
220 m.Float64Histogram.Record(ctx, val, *o...)
221 }
222
223 // AttrConnectionStatus returns an optional attribute for the
224 // "signalr.connection.status" semantic convention. It represents the signalR
225 // HTTP connection closure status.
226 func (ServerConnectionDuration) AttrConnectionStatus(val ConnectionStatusAttr) attribute.KeyValue {
227 return attribute.String("signalr.connection.status", string(val))
228 }
229
230 // AttrTransport returns an optional attribute for the "signalr.transport"
231 // semantic convention. It represents the [SignalR transport type].
232 //
233 // [SignalR transport type]: https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md
234 func (ServerConnectionDuration) AttrTransport(val TransportAttr) attribute.KeyValue {
235 return attribute.String("signalr.transport", string(val))
236 }