Debian Codegraph @

semconv/v1.40.0/vcsconv/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 vcsconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "vcs" namespace.
8 package vcsconv
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 // ChangeStateAttr is an attribute conforming to the vcs.change.state semantic
25 // conventions. It represents the state of the change (pull request/merge
26 // request/changelist).
27 type ChangeStateAttr string
28
29 var (
30 // ChangeStateOpen is the open means the change is currently active and under
31 // review. It hasn't been merged into the target branch yet, and it's still
32 // possible to make changes or add comments.
33 ChangeStateOpen ChangeStateAttr = "open"
34 // ChangeStateWip is the WIP (work-in-progress, draft) means the change is still
35 // in progress and not yet ready for a full review. It might still undergo
36 // significant changes.
37 ChangeStateWip ChangeStateAttr = "wip"
38 // ChangeStateClosed is the closed means the merge request has been closed
39 // without merging. This can happen for various reasons, such as the changes
40 // being deemed unnecessary, the issue being resolved in another way, or the
41 // author deciding to withdraw the request.
42 ChangeStateClosed ChangeStateAttr = "closed"
43 // ChangeStateMerged is the merged indicates that the change has been
44 // successfully integrated into the target codebase.
45 ChangeStateMerged ChangeStateAttr = "merged"
46 )
47
48 // LineChangeTypeAttr is an attribute conforming to the vcs.line_change.type
49 // semantic conventions. It represents the type of line change being measured on
50 // a branch or change.
51 type LineChangeTypeAttr string
52
53 var (
54 // LineChangeTypeAdded is the how many lines were added.
55 LineChangeTypeAdded LineChangeTypeAttr = "added"
56 // LineChangeTypeRemoved is the how many lines were removed.
57 LineChangeTypeRemoved LineChangeTypeAttr = "removed"
58 )
59
60 // ProviderNameAttr is an attribute conforming to the vcs.provider.name semantic
61 // conventions. It represents the name of the version control system provider.
62 type ProviderNameAttr string
63
64 var (
65 // ProviderNameGithub is the [GitHub].
66 //
67 // [GitHub]: https://github.com
68 ProviderNameGithub ProviderNameAttr = "github"
69 // ProviderNameGitlab is the [GitLab].
70 //
71 // [GitLab]: https://gitlab.com
72 ProviderNameGitlab ProviderNameAttr = "gitlab"
73 // ProviderNameGitea is the [Gitea].
74 //
75 // [Gitea]: https://gitea.io
76 ProviderNameGitea ProviderNameAttr = "gitea"
77 // ProviderNameBitbucket is the [Bitbucket].
78 //
79 // [Bitbucket]: https://bitbucket.org
80 ProviderNameBitbucket ProviderNameAttr = "bitbucket"
81 )
82
83 // RefBaseTypeAttr is an attribute conforming to the vcs.ref.base.type semantic
84 // conventions. It represents the type of the [reference] in the repository.
85 //
86 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
87 type RefBaseTypeAttr string
88
89 var (
90 // RefBaseTypeBranch is the [branch].
91 //
92 // [branch]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbranchabranch
93 RefBaseTypeBranch RefBaseTypeAttr = "branch"
94 // RefBaseTypeTag is the [tag].
95 //
96 // [tag]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftagatag
97 RefBaseTypeTag RefBaseTypeAttr = "tag"
98 )
99
100 // RefHeadTypeAttr is an attribute conforming to the vcs.ref.head.type semantic
101 // conventions. It represents the type of the [reference] in the repository.
102 //
103 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
104 type RefHeadTypeAttr string
105
106 var (
107 // RefHeadTypeBranch is the [branch].
108 //
109 // [branch]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbranchabranch
110 RefHeadTypeBranch RefHeadTypeAttr = "branch"
111 // RefHeadTypeTag is the [tag].
112 //
113 // [tag]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftagatag
114 RefHeadTypeTag RefHeadTypeAttr = "tag"
115 )
116
117 // RefTypeAttr is an attribute conforming to the vcs.ref.type semantic
118 // conventions. It represents the type of the [reference] in the repository.
119 //
120 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
121 type RefTypeAttr string
122
123 var (
124 // RefTypeBranch is the [branch].
125 //
126 // [branch]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbranchabranch
127 RefTypeBranch RefTypeAttr = "branch"
128 // RefTypeTag is the [tag].
129 //
130 // [tag]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftagatag
131 RefTypeTag RefTypeAttr = "tag"
132 )
133
134 // RevisionDeltaDirectionAttr is an attribute conforming to the
135 // vcs.revision_delta.direction semantic conventions. It represents the type of
136 // revision comparison.
137 type RevisionDeltaDirectionAttr string
138
139 var (
140 // RevisionDeltaDirectionBehind is the how many revisions the change is behind
141 // the target ref.
142 RevisionDeltaDirectionBehind RevisionDeltaDirectionAttr = "behind"
143 // RevisionDeltaDirectionAhead is the how many revisions the change is ahead of
144 // the target ref.
145 RevisionDeltaDirectionAhead RevisionDeltaDirectionAttr = "ahead"
146 )
147
148 // ChangeCount is an instrument used to record metric values conforming to the
149 // "vcs.change.count" semantic conventions. It represents the number of changes
150 // (pull requests/merge requests/changelists) in a repository, categorized by
151 // their state (e.g. open or merged).
152 type ChangeCount struct {
153 metric.Int64UpDownCounter
154 }
155
156 var newChangeCountOpts = []metric.Int64UpDownCounterOption{
157 metric.WithDescription("The number of changes (pull requests/merge requests/changelists) in a repository, categorized by their state (e.g. open or merged)."),
158 metric.WithUnit("{change}"),
159 }
160
161 // NewChangeCount returns a new ChangeCount instrument.
162 func NewChangeCount(
163 m metric.Meter,
164 opt ...metric.Int64UpDownCounterOption,
165 ) (ChangeCount, error) {
166 // Check if the meter is nil.
167 if m == nil {
168 return ChangeCount{noop.Int64UpDownCounter{}}, nil
169 }
170
171 if len(opt) == 0 {
172 opt = newChangeCountOpts
173 } else {
174 opt = append(opt, newChangeCountOpts...)
175 }
176
177 i, err := m.Int64UpDownCounter(
178 "vcs.change.count",
179 opt...,
180 )
181 if err != nil {
182 return ChangeCount{noop.Int64UpDownCounter{}}, err
183 }
184 return ChangeCount{i}, nil
185 }
186
187 // Inst returns the underlying metric instrument.
188 func (m ChangeCount) Inst() metric.Int64UpDownCounter {
189 return m.Int64UpDownCounter
190 }
191
192 // Name returns the semantic convention name of the instrument.
193 func (ChangeCount) Name() string {
194 return "vcs.change.count"
195 }
196
197 // Unit returns the semantic convention unit of the instrument
198 func (ChangeCount) Unit() string {
199 return "{change}"
200 }
201
202 // Description returns the semantic convention description of the instrument
203 func (ChangeCount) Description() string {
204 return "The number of changes (pull requests/merge requests/changelists) in a repository, categorized by their state (e.g. open or merged)."
205 }
206
207 // Add adds incr to the existing count for attrs.
208 //
209 // The changeState is the the state of the change (pull request/merge
210 // request/changelist).
211 //
212 // The repositoryUrlFull is the the [canonical URL] of the repository providing
213 // the complete HTTP(S) address in order to locate and identify the repository
214 // through a browser.
215 //
216 // All additional attrs passed are included in the recorded value.
217 //
218 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
219 func (m ChangeCount) Add(
220 ctx context.Context,
221 incr int64,
222 changeState ChangeStateAttr,
223 repositoryUrlFull string,
224 attrs ...attribute.KeyValue,
225 ) {
226 if len(attrs) == 0 {
227 m.Int64UpDownCounter.Add(ctx, incr, metric.WithAttributes(
228 attribute.String("vcs.change.state", string(changeState)),
229 attribute.String("vcs.repository.url.full", repositoryUrlFull),
230 ))
231 return
232 }
233
234 o := addOptPool.Get().(*[]metric.AddOption)
235 defer func() {
236 *o = (*o)[:0]
237 addOptPool.Put(o)
238 }()
239
240 *o = append(
241 *o,
242 metric.WithAttributes(
243 append(
244 attrs[:len(attrs):len(attrs)],
245 attribute.String("vcs.change.state", string(changeState)),
246 attribute.String("vcs.repository.url.full", repositoryUrlFull),
247 )...,
248 ),
249 )
250
251 m.Int64UpDownCounter.Add(ctx, incr, *o...)
252 }
253
254 // AddSet adds incr to the existing count for set.
255 func (m ChangeCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
256 if set.Len() == 0 {
257 m.Int64UpDownCounter.Add(ctx, incr)
258 return
259 }
260
261 o := addOptPool.Get().(*[]metric.AddOption)
262 defer func() {
263 *o = (*o)[:0]
264 addOptPool.Put(o)
265 }()
266
267 *o = append(*o, metric.WithAttributeSet(set))
268 m.Int64UpDownCounter.Add(ctx, incr, *o...)
269 }
270
271 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
272 // convention. It represents the group owner within the version control system.
273 func (ChangeCount) AttrOwnerName(val string) attribute.KeyValue {
274 return attribute.String("vcs.owner.name", val)
275 }
276
277 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
278 // semantic convention. It represents the human readable name of the repository.
279 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
280 // or organization in GitHub.
281 func (ChangeCount) AttrRepositoryName(val string) attribute.KeyValue {
282 return attribute.String("vcs.repository.name", val)
283 }
284
285 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
286 // semantic convention. It represents the name of the version control system
287 // provider.
288 func (ChangeCount) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
289 return attribute.String("vcs.provider.name", string(val))
290 }
291
292 // ChangeDuration is an instrument used to record metric values conforming to the
293 // "vcs.change.duration" semantic conventions. It represents the time duration a
294 // change (pull request/merge request/changelist) has been in a given state.
295 type ChangeDuration struct {
296 metric.Float64Gauge
297 }
298
299 var newChangeDurationOpts = []metric.Float64GaugeOption{
300 metric.WithDescription("The time duration a change (pull request/merge request/changelist) has been in a given state."),
301 metric.WithUnit("s"),
302 }
303
304 // NewChangeDuration returns a new ChangeDuration instrument.
305 func NewChangeDuration(
306 m metric.Meter,
307 opt ...metric.Float64GaugeOption,
308 ) (ChangeDuration, error) {
309 // Check if the meter is nil.
310 if m == nil {
311 return ChangeDuration{noop.Float64Gauge{}}, nil
312 }
313
314 if len(opt) == 0 {
315 opt = newChangeDurationOpts
316 } else {
317 opt = append(opt, newChangeDurationOpts...)
318 }
319
320 i, err := m.Float64Gauge(
321 "vcs.change.duration",
322 opt...,
323 )
324 if err != nil {
325 return ChangeDuration{noop.Float64Gauge{}}, err
326 }
327 return ChangeDuration{i}, nil
328 }
329
330 // Inst returns the underlying metric instrument.
331 func (m ChangeDuration) Inst() metric.Float64Gauge {
332 return m.Float64Gauge
333 }
334
335 // Name returns the semantic convention name of the instrument.
336 func (ChangeDuration) Name() string {
337 return "vcs.change.duration"
338 }
339
340 // Unit returns the semantic convention unit of the instrument
341 func (ChangeDuration) Unit() string {
342 return "s"
343 }
344
345 // Description returns the semantic convention description of the instrument
346 func (ChangeDuration) Description() string {
347 return "The time duration a change (pull request/merge request/changelist) has been in a given state."
348 }
349
350 // Record records val to the current distribution for attrs.
351 //
352 // The changeState is the the state of the change (pull request/merge
353 // request/changelist).
354 //
355 // The refHeadName is the the name of the [reference] such as **branch** or
356 // **tag** in the repository.
357 //
358 // The repositoryUrlFull is the the [canonical URL] of the repository providing
359 // the complete HTTP(S) address in order to locate and identify the repository
360 // through a browser.
361 //
362 // All additional attrs passed are included in the recorded value.
363 //
364 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
365 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
366 func (m ChangeDuration) Record(
367 ctx context.Context,
368 val float64,
369 changeState ChangeStateAttr,
370 refHeadName string,
371 repositoryUrlFull string,
372 attrs ...attribute.KeyValue,
373 ) {
374 if len(attrs) == 0 {
375 m.Float64Gauge.Record(ctx, val, metric.WithAttributes(
376 attribute.String("vcs.change.state", string(changeState)),
377 attribute.String("vcs.ref.head.name", refHeadName),
378 attribute.String("vcs.repository.url.full", repositoryUrlFull),
379 ))
380 return
381 }
382
383 o := recOptPool.Get().(*[]metric.RecordOption)
384 defer func() {
385 *o = (*o)[:0]
386 recOptPool.Put(o)
387 }()
388
389 *o = append(
390 *o,
391 metric.WithAttributes(
392 append(
393 attrs[:len(attrs):len(attrs)],
394 attribute.String("vcs.change.state", string(changeState)),
395 attribute.String("vcs.ref.head.name", refHeadName),
396 attribute.String("vcs.repository.url.full", repositoryUrlFull),
397 )...,
398 ),
399 )
400
401 m.Float64Gauge.Record(ctx, val, *o...)
402 }
403
404 // RecordSet records val to the current distribution for set.
405 func (m ChangeDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
406 if set.Len() == 0 {
407 m.Float64Gauge.Record(ctx, val)
408 return
409 }
410
411 o := recOptPool.Get().(*[]metric.RecordOption)
412 defer func() {
413 *o = (*o)[:0]
414 recOptPool.Put(o)
415 }()
416
417 *o = append(*o, metric.WithAttributeSet(set))
418 m.Float64Gauge.Record(ctx, val, *o...)
419 }
420
421 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
422 // convention. It represents the group owner within the version control system.
423 func (ChangeDuration) AttrOwnerName(val string) attribute.KeyValue {
424 return attribute.String("vcs.owner.name", val)
425 }
426
427 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
428 // semantic convention. It represents the human readable name of the repository.
429 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
430 // or organization in GitHub.
431 func (ChangeDuration) AttrRepositoryName(val string) attribute.KeyValue {
432 return attribute.String("vcs.repository.name", val)
433 }
434
435 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
436 // semantic convention. It represents the name of the version control system
437 // provider.
438 func (ChangeDuration) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
439 return attribute.String("vcs.provider.name", string(val))
440 }
441
442 // ChangeTimeToApproval is an instrument used to record metric values conforming
443 // to the "vcs.change.time_to_approval" semantic conventions. It represents the
444 // amount of time since its creation it took a change (pull request/merge
445 // request/changelist) to get the first approval.
446 type ChangeTimeToApproval struct {
447 metric.Float64Gauge
448 }
449
450 var newChangeTimeToApprovalOpts = []metric.Float64GaugeOption{
451 metric.WithDescription("The amount of time since its creation it took a change (pull request/merge request/changelist) to get the first approval."),
452 metric.WithUnit("s"),
453 }
454
455 // NewChangeTimeToApproval returns a new ChangeTimeToApproval instrument.
456 func NewChangeTimeToApproval(
457 m metric.Meter,
458 opt ...metric.Float64GaugeOption,
459 ) (ChangeTimeToApproval, error) {
460 // Check if the meter is nil.
461 if m == nil {
462 return ChangeTimeToApproval{noop.Float64Gauge{}}, nil
463 }
464
465 if len(opt) == 0 {
466 opt = newChangeTimeToApprovalOpts
467 } else {
468 opt = append(opt, newChangeTimeToApprovalOpts...)
469 }
470
471 i, err := m.Float64Gauge(
472 "vcs.change.time_to_approval",
473 opt...,
474 )
475 if err != nil {
476 return ChangeTimeToApproval{noop.Float64Gauge{}}, err
477 }
478 return ChangeTimeToApproval{i}, nil
479 }
480
481 // Inst returns the underlying metric instrument.
482 func (m ChangeTimeToApproval) Inst() metric.Float64Gauge {
483 return m.Float64Gauge
484 }
485
486 // Name returns the semantic convention name of the instrument.
487 func (ChangeTimeToApproval) Name() string {
488 return "vcs.change.time_to_approval"
489 }
490
491 // Unit returns the semantic convention unit of the instrument
492 func (ChangeTimeToApproval) Unit() string {
493 return "s"
494 }
495
496 // Description returns the semantic convention description of the instrument
497 func (ChangeTimeToApproval) Description() string {
498 return "The amount of time since its creation it took a change (pull request/merge request/changelist) to get the first approval."
499 }
500
501 // Record records val to the current distribution for attrs.
502 //
503 // The refHeadName is the the name of the [reference] such as **branch** or
504 // **tag** in the repository.
505 //
506 // The repositoryUrlFull is the the [canonical URL] of the repository providing
507 // the complete HTTP(S) address in order to locate and identify the repository
508 // through a browser.
509 //
510 // All additional attrs passed are included in the recorded value.
511 //
512 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
513 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
514 func (m ChangeTimeToApproval) Record(
515 ctx context.Context,
516 val float64,
517 refHeadName string,
518 repositoryUrlFull string,
519 attrs ...attribute.KeyValue,
520 ) {
521 if len(attrs) == 0 {
522 m.Float64Gauge.Record(ctx, val, metric.WithAttributes(
523 attribute.String("vcs.ref.head.name", refHeadName),
524 attribute.String("vcs.repository.url.full", repositoryUrlFull),
525 ))
526 return
527 }
528
529 o := recOptPool.Get().(*[]metric.RecordOption)
530 defer func() {
531 *o = (*o)[:0]
532 recOptPool.Put(o)
533 }()
534
535 *o = append(
536 *o,
537 metric.WithAttributes(
538 append(
539 attrs[:len(attrs):len(attrs)],
540 attribute.String("vcs.ref.head.name", refHeadName),
541 attribute.String("vcs.repository.url.full", repositoryUrlFull),
542 )...,
543 ),
544 )
545
546 m.Float64Gauge.Record(ctx, val, *o...)
547 }
548
549 // RecordSet records val to the current distribution for set.
550 func (m ChangeTimeToApproval) RecordSet(ctx context.Context, val float64, set attribute.Set) {
551 if set.Len() == 0 {
552 m.Float64Gauge.Record(ctx, val)
553 return
554 }
555
556 o := recOptPool.Get().(*[]metric.RecordOption)
557 defer func() {
558 *o = (*o)[:0]
559 recOptPool.Put(o)
560 }()
561
562 *o = append(*o, metric.WithAttributeSet(set))
563 m.Float64Gauge.Record(ctx, val, *o...)
564 }
565
566 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
567 // convention. It represents the group owner within the version control system.
568 func (ChangeTimeToApproval) AttrOwnerName(val string) attribute.KeyValue {
569 return attribute.String("vcs.owner.name", val)
570 }
571
572 // AttrRefBaseName returns an optional attribute for the "vcs.ref.base.name"
573 // semantic convention. It represents the name of the [reference] such as
574 // **branch** or **tag** in the repository.
575 //
576 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
577 func (ChangeTimeToApproval) AttrRefBaseName(val string) attribute.KeyValue {
578 return attribute.String("vcs.ref.base.name", val)
579 }
580
581 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
582 // semantic convention. It represents the human readable name of the repository.
583 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
584 // or organization in GitHub.
585 func (ChangeTimeToApproval) AttrRepositoryName(val string) attribute.KeyValue {
586 return attribute.String("vcs.repository.name", val)
587 }
588
589 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
590 // semantic convention. It represents the name of the version control system
591 // provider.
592 func (ChangeTimeToApproval) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
593 return attribute.String("vcs.provider.name", string(val))
594 }
595
596 // AttrRefBaseRevision returns an optional attribute for the
597 // "vcs.ref.base.revision" semantic convention. It represents the revision,
598 // literally [revised version], The revision most often refers to a commit object
599 // in Git, or a revision number in SVN.
600 //
601 // [revised version]: https://www.merriam-webster.com/dictionary/revision
602 func (ChangeTimeToApproval) AttrRefBaseRevision(val string) attribute.KeyValue {
603 return attribute.String("vcs.ref.base.revision", val)
604 }
605
606 // AttrRefHeadRevision returns an optional attribute for the
607 // "vcs.ref.head.revision" semantic convention. It represents the revision,
608 // literally [revised version], The revision most often refers to a commit object
609 // in Git, or a revision number in SVN.
610 //
611 // [revised version]: https://www.merriam-webster.com/dictionary/revision
612 func (ChangeTimeToApproval) AttrRefHeadRevision(val string) attribute.KeyValue {
613 return attribute.String("vcs.ref.head.revision", val)
614 }
615
616 // ChangeTimeToMerge is an instrument used to record metric values conforming to
617 // the "vcs.change.time_to_merge" semantic conventions. It represents the amount
618 // of time since its creation it took a change (pull request/merge
619 // request/changelist) to get merged into the target(base) ref.
620 type ChangeTimeToMerge struct {
621 metric.Float64Gauge
622 }
623
624 var newChangeTimeToMergeOpts = []metric.Float64GaugeOption{
625 metric.WithDescription("The amount of time since its creation it took a change (pull request/merge request/changelist) to get merged into the target(base) ref."),
626 metric.WithUnit("s"),
627 }
628
629 // NewChangeTimeToMerge returns a new ChangeTimeToMerge instrument.
630 func NewChangeTimeToMerge(
631 m metric.Meter,
632 opt ...metric.Float64GaugeOption,
633 ) (ChangeTimeToMerge, error) {
634 // Check if the meter is nil.
635 if m == nil {
636 return ChangeTimeToMerge{noop.Float64Gauge{}}, nil
637 }
638
639 if len(opt) == 0 {
640 opt = newChangeTimeToMergeOpts
641 } else {
642 opt = append(opt, newChangeTimeToMergeOpts...)
643 }
644
645 i, err := m.Float64Gauge(
646 "vcs.change.time_to_merge",
647 opt...,
648 )
649 if err != nil {
650 return ChangeTimeToMerge{noop.Float64Gauge{}}, err
651 }
652 return ChangeTimeToMerge{i}, nil
653 }
654
655 // Inst returns the underlying metric instrument.
656 func (m ChangeTimeToMerge) Inst() metric.Float64Gauge {
657 return m.Float64Gauge
658 }
659
660 // Name returns the semantic convention name of the instrument.
661 func (ChangeTimeToMerge) Name() string {
662 return "vcs.change.time_to_merge"
663 }
664
665 // Unit returns the semantic convention unit of the instrument
666 func (ChangeTimeToMerge) Unit() string {
667 return "s"
668 }
669
670 // Description returns the semantic convention description of the instrument
671 func (ChangeTimeToMerge) Description() string {
672 return "The amount of time since its creation it took a change (pull request/merge request/changelist) to get merged into the target(base) ref."
673 }
674
675 // Record records val to the current distribution for attrs.
676 //
677 // The refHeadName is the the name of the [reference] such as **branch** or
678 // **tag** in the repository.
679 //
680 // The repositoryUrlFull is the the [canonical URL] of the repository providing
681 // the complete HTTP(S) address in order to locate and identify the repository
682 // through a browser.
683 //
684 // All additional attrs passed are included in the recorded value.
685 //
686 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
687 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
688 func (m ChangeTimeToMerge) Record(
689 ctx context.Context,
690 val float64,
691 refHeadName string,
692 repositoryUrlFull string,
693 attrs ...attribute.KeyValue,
694 ) {
695 if len(attrs) == 0 {
696 m.Float64Gauge.Record(ctx, val, metric.WithAttributes(
697 attribute.String("vcs.ref.head.name", refHeadName),
698 attribute.String("vcs.repository.url.full", repositoryUrlFull),
699 ))
700 return
701 }
702
703 o := recOptPool.Get().(*[]metric.RecordOption)
704 defer func() {
705 *o = (*o)[:0]
706 recOptPool.Put(o)
707 }()
708
709 *o = append(
710 *o,
711 metric.WithAttributes(
712 append(
713 attrs[:len(attrs):len(attrs)],
714 attribute.String("vcs.ref.head.name", refHeadName),
715 attribute.String("vcs.repository.url.full", repositoryUrlFull),
716 )...,
717 ),
718 )
719
720 m.Float64Gauge.Record(ctx, val, *o...)
721 }
722
723 // RecordSet records val to the current distribution for set.
724 func (m ChangeTimeToMerge) RecordSet(ctx context.Context, val float64, set attribute.Set) {
725 if set.Len() == 0 {
726 m.Float64Gauge.Record(ctx, val)
727 return
728 }
729
730 o := recOptPool.Get().(*[]metric.RecordOption)
731 defer func() {
732 *o = (*o)[:0]
733 recOptPool.Put(o)
734 }()
735
736 *o = append(*o, metric.WithAttributeSet(set))
737 m.Float64Gauge.Record(ctx, val, *o...)
738 }
739
740 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
741 // convention. It represents the group owner within the version control system.
742 func (ChangeTimeToMerge) AttrOwnerName(val string) attribute.KeyValue {
743 return attribute.String("vcs.owner.name", val)
744 }
745
746 // AttrRefBaseName returns an optional attribute for the "vcs.ref.base.name"
747 // semantic convention. It represents the name of the [reference] such as
748 // **branch** or **tag** in the repository.
749 //
750 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
751 func (ChangeTimeToMerge) AttrRefBaseName(val string) attribute.KeyValue {
752 return attribute.String("vcs.ref.base.name", val)
753 }
754
755 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
756 // semantic convention. It represents the human readable name of the repository.
757 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
758 // or organization in GitHub.
759 func (ChangeTimeToMerge) AttrRepositoryName(val string) attribute.KeyValue {
760 return attribute.String("vcs.repository.name", val)
761 }
762
763 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
764 // semantic convention. It represents the name of the version control system
765 // provider.
766 func (ChangeTimeToMerge) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
767 return attribute.String("vcs.provider.name", string(val))
768 }
769
770 // AttrRefBaseRevision returns an optional attribute for the
771 // "vcs.ref.base.revision" semantic convention. It represents the revision,
772 // literally [revised version], The revision most often refers to a commit object
773 // in Git, or a revision number in SVN.
774 //
775 // [revised version]: https://www.merriam-webster.com/dictionary/revision
776 func (ChangeTimeToMerge) AttrRefBaseRevision(val string) attribute.KeyValue {
777 return attribute.String("vcs.ref.base.revision", val)
778 }
779
780 // AttrRefHeadRevision returns an optional attribute for the
781 // "vcs.ref.head.revision" semantic convention. It represents the revision,
782 // literally [revised version], The revision most often refers to a commit object
783 // in Git, or a revision number in SVN.
784 //
785 // [revised version]: https://www.merriam-webster.com/dictionary/revision
786 func (ChangeTimeToMerge) AttrRefHeadRevision(val string) attribute.KeyValue {
787 return attribute.String("vcs.ref.head.revision", val)
788 }
789
790 // ContributorCount is an instrument used to record metric values conforming to
791 // the "vcs.contributor.count" semantic conventions. It represents the number of
792 // unique contributors to a repository.
793 type ContributorCount struct {
794 metric.Int64Gauge
795 }
796
797 var newContributorCountOpts = []metric.Int64GaugeOption{
798 metric.WithDescription("The number of unique contributors to a repository."),
799 metric.WithUnit("{contributor}"),
800 }
801
802 // NewContributorCount returns a new ContributorCount instrument.
803 func NewContributorCount(
804 m metric.Meter,
805 opt ...metric.Int64GaugeOption,
806 ) (ContributorCount, error) {
807 // Check if the meter is nil.
808 if m == nil {
809 return ContributorCount{noop.Int64Gauge{}}, nil
810 }
811
812 if len(opt) == 0 {
813 opt = newContributorCountOpts
814 } else {
815 opt = append(opt, newContributorCountOpts...)
816 }
817
818 i, err := m.Int64Gauge(
819 "vcs.contributor.count",
820 opt...,
821 )
822 if err != nil {
823 return ContributorCount{noop.Int64Gauge{}}, err
824 }
825 return ContributorCount{i}, nil
826 }
827
828 // Inst returns the underlying metric instrument.
829 func (m ContributorCount) Inst() metric.Int64Gauge {
830 return m.Int64Gauge
831 }
832
833 // Name returns the semantic convention name of the instrument.
834 func (ContributorCount) Name() string {
835 return "vcs.contributor.count"
836 }
837
838 // Unit returns the semantic convention unit of the instrument
839 func (ContributorCount) Unit() string {
840 return "{contributor}"
841 }
842
843 // Description returns the semantic convention description of the instrument
844 func (ContributorCount) Description() string {
845 return "The number of unique contributors to a repository."
846 }
847
848 // Record records val to the current distribution for attrs.
849 //
850 // The repositoryUrlFull is the the [canonical URL] of the repository providing
851 // the complete HTTP(S) address in order to locate and identify the repository
852 // through a browser.
853 //
854 // All additional attrs passed are included in the recorded value.
855 //
856 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
857 func (m ContributorCount) Record(
858 ctx context.Context,
859 val int64,
860 repositoryUrlFull string,
861 attrs ...attribute.KeyValue,
862 ) {
863 if len(attrs) == 0 {
864 m.Int64Gauge.Record(ctx, val, metric.WithAttributes(
865 attribute.String("vcs.repository.url.full", repositoryUrlFull),
866 ))
867 return
868 }
869
870 o := recOptPool.Get().(*[]metric.RecordOption)
871 defer func() {
872 *o = (*o)[:0]
873 recOptPool.Put(o)
874 }()
875
876 *o = append(
877 *o,
878 metric.WithAttributes(
879 append(
880 attrs[:len(attrs):len(attrs)],
881 attribute.String("vcs.repository.url.full", repositoryUrlFull),
882 )...,
883 ),
884 )
885
886 m.Int64Gauge.Record(ctx, val, *o...)
887 }
888
889 // RecordSet records val to the current distribution for set.
890 func (m ContributorCount) RecordSet(ctx context.Context, val int64, set attribute.Set) {
891 if set.Len() == 0 {
892 m.Int64Gauge.Record(ctx, val)
893 return
894 }
895
896 o := recOptPool.Get().(*[]metric.RecordOption)
897 defer func() {
898 *o = (*o)[:0]
899 recOptPool.Put(o)
900 }()
901
902 *o = append(*o, metric.WithAttributeSet(set))
903 m.Int64Gauge.Record(ctx, val, *o...)
904 }
905
906 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
907 // convention. It represents the group owner within the version control system.
908 func (ContributorCount) AttrOwnerName(val string) attribute.KeyValue {
909 return attribute.String("vcs.owner.name", val)
910 }
911
912 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
913 // semantic convention. It represents the human readable name of the repository.
914 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
915 // or organization in GitHub.
916 func (ContributorCount) AttrRepositoryName(val string) attribute.KeyValue {
917 return attribute.String("vcs.repository.name", val)
918 }
919
920 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
921 // semantic convention. It represents the name of the version control system
922 // provider.
923 func (ContributorCount) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
924 return attribute.String("vcs.provider.name", string(val))
925 }
926
927 // RefCount is an instrument used to record metric values conforming to the
928 // "vcs.ref.count" semantic conventions. It represents the number of refs of type
929 // branch or tag in a repository.
930 type RefCount struct {
931 metric.Int64UpDownCounter
932 }
933
934 var newRefCountOpts = []metric.Int64UpDownCounterOption{
935 metric.WithDescription("The number of refs of type branch or tag in a repository."),
936 metric.WithUnit("{ref}"),
937 }
938
939 // NewRefCount returns a new RefCount instrument.
940 func NewRefCount(
941 m metric.Meter,
942 opt ...metric.Int64UpDownCounterOption,
943 ) (RefCount, error) {
944 // Check if the meter is nil.
945 if m == nil {
946 return RefCount{noop.Int64UpDownCounter{}}, nil
947 }
948
949 if len(opt) == 0 {
950 opt = newRefCountOpts
951 } else {
952 opt = append(opt, newRefCountOpts...)
953 }
954
955 i, err := m.Int64UpDownCounter(
956 "vcs.ref.count",
957 opt...,
958 )
959 if err != nil {
960 return RefCount{noop.Int64UpDownCounter{}}, err
961 }
962 return RefCount{i}, nil
963 }
964
965 // Inst returns the underlying metric instrument.
966 func (m RefCount) Inst() metric.Int64UpDownCounter {
967 return m.Int64UpDownCounter
968 }
969
970 // Name returns the semantic convention name of the instrument.
971 func (RefCount) Name() string {
972 return "vcs.ref.count"
973 }
974
975 // Unit returns the semantic convention unit of the instrument
976 func (RefCount) Unit() string {
977 return "{ref}"
978 }
979
980 // Description returns the semantic convention description of the instrument
981 func (RefCount) Description() string {
982 return "The number of refs of type branch or tag in a repository."
983 }
984
985 // Add adds incr to the existing count for attrs.
986 //
987 // The refType is the the type of the [reference] in the repository.
988 //
989 // The repositoryUrlFull is the the [canonical URL] of the repository providing
990 // the complete HTTP(S) address in order to locate and identify the repository
991 // through a browser.
992 //
993 // All additional attrs passed are included in the recorded value.
994 //
995 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
996 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
997 func (m RefCount) Add(
998 ctx context.Context,
999 incr int64,
1000 refType RefTypeAttr,
1001 repositoryUrlFull string,
1002 attrs ...attribute.KeyValue,
1003 ) {
1004 if len(attrs) == 0 {
1005 m.Int64UpDownCounter.Add(ctx, incr, metric.WithAttributes(
1006 attribute.String("vcs.ref.type", string(refType)),
1007 attribute.String("vcs.repository.url.full", repositoryUrlFull),
1008 ))
1009 return
1010 }
1011
1012 o := addOptPool.Get().(*[]metric.AddOption)
1013 defer func() {
1014 *o = (*o)[:0]
1015 addOptPool.Put(o)
1016 }()
1017
1018 *o = append(
1019 *o,
1020 metric.WithAttributes(
1021 append(
1022 attrs[:len(attrs):len(attrs)],
1023 attribute.String("vcs.ref.type", string(refType)),
1024 attribute.String("vcs.repository.url.full", repositoryUrlFull),
1025 )...,
1026 ),
1027 )
1028
1029 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1030 }
1031
1032 // AddSet adds incr to the existing count for set.
1033 func (m RefCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1034 if set.Len() == 0 {
1035 m.Int64UpDownCounter.Add(ctx, incr)
1036 return
1037 }
1038
1039 o := addOptPool.Get().(*[]metric.AddOption)
1040 defer func() {
1041 *o = (*o)[:0]
1042 addOptPool.Put(o)
1043 }()
1044
1045 *o = append(*o, metric.WithAttributeSet(set))
1046 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1047 }
1048
1049 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
1050 // convention. It represents the group owner within the version control system.
1051 func (RefCount) AttrOwnerName(val string) attribute.KeyValue {
1052 return attribute.String("vcs.owner.name", val)
1053 }
1054
1055 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
1056 // semantic convention. It represents the human readable name of the repository.
1057 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
1058 // or organization in GitHub.
1059 func (RefCount) AttrRepositoryName(val string) attribute.KeyValue {
1060 return attribute.String("vcs.repository.name", val)
1061 }
1062
1063 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
1064 // semantic convention. It represents the name of the version control system
1065 // provider.
1066 func (RefCount) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
1067 return attribute.String("vcs.provider.name", string(val))
1068 }
1069
1070 // RefLinesDelta is an instrument used to record metric values conforming to the
1071 // "vcs.ref.lines_delta" semantic conventions. It represents the number of lines
1072 // added/removed in a ref (branch) relative to the ref from the
1073 // `vcs.ref.base.name` attribute.
1074 type RefLinesDelta struct {
1075 metric.Int64Gauge
1076 }
1077
1078 var newRefLinesDeltaOpts = []metric.Int64GaugeOption{
1079 metric.WithDescription("The number of lines added/removed in a ref (branch) relative to the ref from the `vcs.ref.base.name` attribute."),
1080 metric.WithUnit("{line}"),
1081 }
1082
1083 // NewRefLinesDelta returns a new RefLinesDelta instrument.
1084 func NewRefLinesDelta(
1085 m metric.Meter,
1086 opt ...metric.Int64GaugeOption,
1087 ) (RefLinesDelta, error) {
1088 // Check if the meter is nil.
1089 if m == nil {
1090 return RefLinesDelta{noop.Int64Gauge{}}, nil
1091 }
1092
1093 if len(opt) == 0 {
1094 opt = newRefLinesDeltaOpts
1095 } else {
1096 opt = append(opt, newRefLinesDeltaOpts...)
1097 }
1098
1099 i, err := m.Int64Gauge(
1100 "vcs.ref.lines_delta",
1101 opt...,
1102 )
1103 if err != nil {
1104 return RefLinesDelta{noop.Int64Gauge{}}, err
1105 }
1106 return RefLinesDelta{i}, nil
1107 }
1108
1109 // Inst returns the underlying metric instrument.
1110 func (m RefLinesDelta) Inst() metric.Int64Gauge {
1111 return m.Int64Gauge
1112 }
1113
1114 // Name returns the semantic convention name of the instrument.
1115 func (RefLinesDelta) Name() string {
1116 return "vcs.ref.lines_delta"
1117 }
1118
1119 // Unit returns the semantic convention unit of the instrument
1120 func (RefLinesDelta) Unit() string {
1121 return "{line}"
1122 }
1123
1124 // Description returns the semantic convention description of the instrument
1125 func (RefLinesDelta) Description() string {
1126 return "The number of lines added/removed in a ref (branch) relative to the ref from the `vcs.ref.base.name` attribute."
1127 }
1128
1129 // Record records val to the current distribution for attrs.
1130 //
1131 // The lineChangeType is the the type of line change being measured on a branch
1132 // or change.
1133 //
1134 // The refBaseName is the the name of the [reference] such as **branch** or
1135 // **tag** in the repository.
1136 //
1137 // The refBaseType is the the type of the [reference] in the repository.
1138 //
1139 // The refHeadName is the the name of the [reference] such as **branch** or
1140 // **tag** in the repository.
1141 //
1142 // The refHeadType is the the type of the [reference] in the repository.
1143 //
1144 // The repositoryUrlFull is the the [canonical URL] of the repository providing
1145 // the complete HTTP(S) address in order to locate and identify the repository
1146 // through a browser.
1147 //
1148 // All additional attrs passed are included in the recorded value.
1149 //
1150 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1151 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1152 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1153 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1154 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
1155 //
1156 // This metric should be reported for each `vcs.line_change.type` value. For
1157 // example if a ref added 3 lines and removed 2 lines,
1158 // instrumentation SHOULD report two measurements: 3 and 2 (both positive
1159 // numbers).
1160 // If number of lines added/removed should be calculated from the start of time,
1161 // then `vcs.ref.base.name` SHOULD be set to an empty string.
1162 func (m RefLinesDelta) Record(
1163 ctx context.Context,
1164 val int64,
1165 lineChangeType LineChangeTypeAttr,
1166 refBaseName string,
1167 refBaseType RefBaseTypeAttr,
1168 refHeadName string,
1169 refHeadType RefHeadTypeAttr,
1170 repositoryUrlFull string,
1171 attrs ...attribute.KeyValue,
1172 ) {
1173 if len(attrs) == 0 {
1174 m.Int64Gauge.Record(ctx, val, metric.WithAttributes(
1175 attribute.String("vcs.line_change.type", string(lineChangeType)),
1176 attribute.String("vcs.ref.base.name", refBaseName),
1177 attribute.String("vcs.ref.base.type", string(refBaseType)),
1178 attribute.String("vcs.ref.head.name", refHeadName),
1179 attribute.String("vcs.ref.head.type", string(refHeadType)),
1180 attribute.String("vcs.repository.url.full", repositoryUrlFull),
1181 ))
1182 return
1183 }
1184
1185 o := recOptPool.Get().(*[]metric.RecordOption)
1186 defer func() {
1187 *o = (*o)[:0]
1188 recOptPool.Put(o)
1189 }()
1190
1191 *o = append(
1192 *o,
1193 metric.WithAttributes(
1194 append(
1195 attrs[:len(attrs):len(attrs)],
1196 attribute.String("vcs.line_change.type", string(lineChangeType)),
1197 attribute.String("vcs.ref.base.name", refBaseName),
1198 attribute.String("vcs.ref.base.type", string(refBaseType)),
1199 attribute.String("vcs.ref.head.name", refHeadName),
1200 attribute.String("vcs.ref.head.type", string(refHeadType)),
1201 attribute.String("vcs.repository.url.full", repositoryUrlFull),
1202 )...,
1203 ),
1204 )
1205
1206 m.Int64Gauge.Record(ctx, val, *o...)
1207 }
1208
1209 // RecordSet records val to the current distribution for set.
1210 //
1211 // This metric should be reported for each `vcs.line_change.type` value. For
1212 // example if a ref added 3 lines and removed 2 lines,
1213 // instrumentation SHOULD report two measurements: 3 and 2 (both positive
1214 // numbers).
1215 // If number of lines added/removed should be calculated from the start of time,
1216 // then `vcs.ref.base.name` SHOULD be set to an empty string.
1217 func (m RefLinesDelta) RecordSet(ctx context.Context, val int64, set attribute.Set) {
1218 if set.Len() == 0 {
1219 m.Int64Gauge.Record(ctx, val)
1220 return
1221 }
1222
1223 o := recOptPool.Get().(*[]metric.RecordOption)
1224 defer func() {
1225 *o = (*o)[:0]
1226 recOptPool.Put(o)
1227 }()
1228
1229 *o = append(*o, metric.WithAttributeSet(set))
1230 m.Int64Gauge.Record(ctx, val, *o...)
1231 }
1232
1233 // AttrChangeID returns an optional attribute for the "vcs.change.id" semantic
1234 // convention. It represents the ID of the change (pull request/merge
1235 // request/changelist) if applicable. This is usually a unique (within
1236 // repository) identifier generated by the VCS system.
1237 func (RefLinesDelta) AttrChangeID(val string) attribute.KeyValue {
1238 return attribute.String("vcs.change.id", val)
1239 }
1240
1241 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
1242 // convention. It represents the group owner within the version control system.
1243 func (RefLinesDelta) AttrOwnerName(val string) attribute.KeyValue {
1244 return attribute.String("vcs.owner.name", val)
1245 }
1246
1247 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
1248 // semantic convention. It represents the human readable name of the repository.
1249 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
1250 // or organization in GitHub.
1251 func (RefLinesDelta) AttrRepositoryName(val string) attribute.KeyValue {
1252 return attribute.String("vcs.repository.name", val)
1253 }
1254
1255 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
1256 // semantic convention. It represents the name of the version control system
1257 // provider.
1258 func (RefLinesDelta) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
1259 return attribute.String("vcs.provider.name", string(val))
1260 }
1261
1262 // RefRevisionsDelta is an instrument used to record metric values conforming to
1263 // the "vcs.ref.revisions_delta" semantic conventions. It represents the number
1264 // of revisions (commits) a ref (branch) is ahead/behind the branch from the
1265 // `vcs.ref.base.name` attribute.
1266 type RefRevisionsDelta struct {
1267 metric.Int64Gauge
1268 }
1269
1270 var newRefRevisionsDeltaOpts = []metric.Int64GaugeOption{
1271 metric.WithDescription("The number of revisions (commits) a ref (branch) is ahead/behind the branch from the `vcs.ref.base.name` attribute."),
1272 metric.WithUnit("{revision}"),
1273 }
1274
1275 // NewRefRevisionsDelta returns a new RefRevisionsDelta instrument.
1276 func NewRefRevisionsDelta(
1277 m metric.Meter,
1278 opt ...metric.Int64GaugeOption,
1279 ) (RefRevisionsDelta, error) {
1280 // Check if the meter is nil.
1281 if m == nil {
1282 return RefRevisionsDelta{noop.Int64Gauge{}}, nil
1283 }
1284
1285 if len(opt) == 0 {
1286 opt = newRefRevisionsDeltaOpts
1287 } else {
1288 opt = append(opt, newRefRevisionsDeltaOpts...)
1289 }
1290
1291 i, err := m.Int64Gauge(
1292 "vcs.ref.revisions_delta",
1293 opt...,
1294 )
1295 if err != nil {
1296 return RefRevisionsDelta{noop.Int64Gauge{}}, err
1297 }
1298 return RefRevisionsDelta{i}, nil
1299 }
1300
1301 // Inst returns the underlying metric instrument.
1302 func (m RefRevisionsDelta) Inst() metric.Int64Gauge {
1303 return m.Int64Gauge
1304 }
1305
1306 // Name returns the semantic convention name of the instrument.
1307 func (RefRevisionsDelta) Name() string {
1308 return "vcs.ref.revisions_delta"
1309 }
1310
1311 // Unit returns the semantic convention unit of the instrument
1312 func (RefRevisionsDelta) Unit() string {
1313 return "{revision}"
1314 }
1315
1316 // Description returns the semantic convention description of the instrument
1317 func (RefRevisionsDelta) Description() string {
1318 return "The number of revisions (commits) a ref (branch) is ahead/behind the branch from the `vcs.ref.base.name` attribute."
1319 }
1320
1321 // Record records val to the current distribution for attrs.
1322 //
1323 // The refBaseName is the the name of the [reference] such as **branch** or
1324 // **tag** in the repository.
1325 //
1326 // The refBaseType is the the type of the [reference] in the repository.
1327 //
1328 // The refHeadName is the the name of the [reference] such as **branch** or
1329 // **tag** in the repository.
1330 //
1331 // The refHeadType is the the type of the [reference] in the repository.
1332 //
1333 // The repositoryUrlFull is the the [canonical URL] of the repository providing
1334 // the complete HTTP(S) address in order to locate and identify the repository
1335 // through a browser.
1336 //
1337 // The revisionDeltaDirection is the the type of revision comparison.
1338 //
1339 // All additional attrs passed are included in the recorded value.
1340 //
1341 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1342 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1343 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1344 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1345 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
1346 //
1347 // This metric should be reported for each `vcs.revision_delta.direction` value.
1348 // For example if branch `a` is 3 commits behind and 2 commits ahead of `trunk`,
1349 // instrumentation SHOULD report two measurements: 3 and 2 (both positive
1350 // numbers) and `vcs.ref.base.name` is set to `trunk`.
1351 func (m RefRevisionsDelta) Record(
1352 ctx context.Context,
1353 val int64,
1354 refBaseName string,
1355 refBaseType RefBaseTypeAttr,
1356 refHeadName string,
1357 refHeadType RefHeadTypeAttr,
1358 repositoryUrlFull string,
1359 revisionDeltaDirection RevisionDeltaDirectionAttr,
1360 attrs ...attribute.KeyValue,
1361 ) {
1362 if len(attrs) == 0 {
1363 m.Int64Gauge.Record(ctx, val, metric.WithAttributes(
1364 attribute.String("vcs.ref.base.name", refBaseName),
1365 attribute.String("vcs.ref.base.type", string(refBaseType)),
1366 attribute.String("vcs.ref.head.name", refHeadName),
1367 attribute.String("vcs.ref.head.type", string(refHeadType)),
1368 attribute.String("vcs.repository.url.full", repositoryUrlFull),
1369 attribute.String("vcs.revision_delta.direction", string(revisionDeltaDirection)),
1370 ))
1371 return
1372 }
1373
1374 o := recOptPool.Get().(*[]metric.RecordOption)
1375 defer func() {
1376 *o = (*o)[:0]
1377 recOptPool.Put(o)
1378 }()
1379
1380 *o = append(
1381 *o,
1382 metric.WithAttributes(
1383 append(
1384 attrs[:len(attrs):len(attrs)],
1385 attribute.String("vcs.ref.base.name", refBaseName),
1386 attribute.String("vcs.ref.base.type", string(refBaseType)),
1387 attribute.String("vcs.ref.head.name", refHeadName),
1388 attribute.String("vcs.ref.head.type", string(refHeadType)),
1389 attribute.String("vcs.repository.url.full", repositoryUrlFull),
1390 attribute.String("vcs.revision_delta.direction", string(revisionDeltaDirection)),
1391 )...,
1392 ),
1393 )
1394
1395 m.Int64Gauge.Record(ctx, val, *o...)
1396 }
1397
1398 // RecordSet records val to the current distribution for set.
1399 //
1400 // This metric should be reported for each `vcs.revision_delta.direction` value.
1401 // For example if branch `a` is 3 commits behind and 2 commits ahead of `trunk`,
1402 // instrumentation SHOULD report two measurements: 3 and 2 (both positive
1403 // numbers) and `vcs.ref.base.name` is set to `trunk`.
1404 func (m RefRevisionsDelta) RecordSet(ctx context.Context, val int64, set attribute.Set) {
1405 if set.Len() == 0 {
1406 m.Int64Gauge.Record(ctx, val)
1407 return
1408 }
1409
1410 o := recOptPool.Get().(*[]metric.RecordOption)
1411 defer func() {
1412 *o = (*o)[:0]
1413 recOptPool.Put(o)
1414 }()
1415
1416 *o = append(*o, metric.WithAttributeSet(set))
1417 m.Int64Gauge.Record(ctx, val, *o...)
1418 }
1419
1420 // AttrChangeID returns an optional attribute for the "vcs.change.id" semantic
1421 // convention. It represents the ID of the change (pull request/merge
1422 // request/changelist) if applicable. This is usually a unique (within
1423 // repository) identifier generated by the VCS system.
1424 func (RefRevisionsDelta) AttrChangeID(val string) attribute.KeyValue {
1425 return attribute.String("vcs.change.id", val)
1426 }
1427
1428 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
1429 // convention. It represents the group owner within the version control system.
1430 func (RefRevisionsDelta) AttrOwnerName(val string) attribute.KeyValue {
1431 return attribute.String("vcs.owner.name", val)
1432 }
1433
1434 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
1435 // semantic convention. It represents the human readable name of the repository.
1436 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
1437 // or organization in GitHub.
1438 func (RefRevisionsDelta) AttrRepositoryName(val string) attribute.KeyValue {
1439 return attribute.String("vcs.repository.name", val)
1440 }
1441
1442 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
1443 // semantic convention. It represents the name of the version control system
1444 // provider.
1445 func (RefRevisionsDelta) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
1446 return attribute.String("vcs.provider.name", string(val))
1447 }
1448
1449 // RefTime is an instrument used to record metric values conforming to the
1450 // "vcs.ref.time" semantic conventions. It represents the time a ref (branch)
1451 // created from the default branch (trunk) has existed. The `ref.type` attribute
1452 // will always be `branch`.
1453 type RefTime struct {
1454 metric.Float64Gauge
1455 }
1456
1457 var newRefTimeOpts = []metric.Float64GaugeOption{
1458 metric.WithDescription("Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`."),
1459 metric.WithUnit("s"),
1460 }
1461
1462 // NewRefTime returns a new RefTime instrument.
1463 func NewRefTime(
1464 m metric.Meter,
1465 opt ...metric.Float64GaugeOption,
1466 ) (RefTime, error) {
1467 // Check if the meter is nil.
1468 if m == nil {
1469 return RefTime{noop.Float64Gauge{}}, nil
1470 }
1471
1472 if len(opt) == 0 {
1473 opt = newRefTimeOpts
1474 } else {
1475 opt = append(opt, newRefTimeOpts...)
1476 }
1477
1478 i, err := m.Float64Gauge(
1479 "vcs.ref.time",
1480 opt...,
1481 )
1482 if err != nil {
1483 return RefTime{noop.Float64Gauge{}}, err
1484 }
1485 return RefTime{i}, nil
1486 }
1487
1488 // Inst returns the underlying metric instrument.
1489 func (m RefTime) Inst() metric.Float64Gauge {
1490 return m.Float64Gauge
1491 }
1492
1493 // Name returns the semantic convention name of the instrument.
1494 func (RefTime) Name() string {
1495 return "vcs.ref.time"
1496 }
1497
1498 // Unit returns the semantic convention unit of the instrument
1499 func (RefTime) Unit() string {
1500 return "s"
1501 }
1502
1503 // Description returns the semantic convention description of the instrument
1504 func (RefTime) Description() string {
1505 return "Time a ref (branch) created from the default branch (trunk) has existed. The `ref.type` attribute will always be `branch`."
1506 }
1507
1508 // Record records val to the current distribution for attrs.
1509 //
1510 // The refHeadName is the the name of the [reference] such as **branch** or
1511 // **tag** in the repository.
1512 //
1513 // The refHeadType is the the type of the [reference] in the repository.
1514 //
1515 // The repositoryUrlFull is the the [canonical URL] of the repository providing
1516 // the complete HTTP(S) address in order to locate and identify the repository
1517 // through a browser.
1518 //
1519 // All additional attrs passed are included in the recorded value.
1520 //
1521 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1522 // [reference]: https://git-scm.com/docs/gitglossary#def_ref
1523 // [canonical URL]: https://support.google.com/webmasters/answer/10347851
1524 func (m RefTime) Record(
1525 ctx context.Context,
1526 val float64,
1527 refHeadName string,
1528 refHeadType RefHeadTypeAttr,
1529 repositoryUrlFull string,
1530 attrs ...attribute.KeyValue,
1531 ) {
1532 if len(attrs) == 0 {
1533 m.Float64Gauge.Record(ctx, val, metric.WithAttributes(
1534 attribute.String("vcs.ref.head.name", refHeadName),
1535 attribute.String("vcs.ref.head.type", string(refHeadType)),
1536 attribute.String("vcs.repository.url.full", repositoryUrlFull),
1537 ))
1538 return
1539 }
1540
1541 o := recOptPool.Get().(*[]metric.RecordOption)
1542 defer func() {
1543 *o = (*o)[:0]
1544 recOptPool.Put(o)
1545 }()
1546
1547 *o = append(
1548 *o,
1549 metric.WithAttributes(
1550 append(
1551 attrs[:len(attrs):len(attrs)],
1552 attribute.String("vcs.ref.head.name", refHeadName),
1553 attribute.String("vcs.ref.head.type", string(refHeadType)),
1554 attribute.String("vcs.repository.url.full", repositoryUrlFull),
1555 )...,
1556 ),
1557 )
1558
1559 m.Float64Gauge.Record(ctx, val, *o...)
1560 }
1561
1562 // RecordSet records val to the current distribution for set.
1563 func (m RefTime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1564 if set.Len() == 0 {
1565 m.Float64Gauge.Record(ctx, val)
1566 return
1567 }
1568
1569 o := recOptPool.Get().(*[]metric.RecordOption)
1570 defer func() {
1571 *o = (*o)[:0]
1572 recOptPool.Put(o)
1573 }()
1574
1575 *o = append(*o, metric.WithAttributeSet(set))
1576 m.Float64Gauge.Record(ctx, val, *o...)
1577 }
1578
1579 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
1580 // convention. It represents the group owner within the version control system.
1581 func (RefTime) AttrOwnerName(val string) attribute.KeyValue {
1582 return attribute.String("vcs.owner.name", val)
1583 }
1584
1585 // AttrRepositoryName returns an optional attribute for the "vcs.repository.name"
1586 // semantic convention. It represents the human readable name of the repository.
1587 // It SHOULD NOT include any additional identifier like Group/SubGroup in GitLab
1588 // or organization in GitHub.
1589 func (RefTime) AttrRepositoryName(val string) attribute.KeyValue {
1590 return attribute.String("vcs.repository.name", val)
1591 }
1592
1593 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
1594 // semantic convention. It represents the name of the version control system
1595 // provider.
1596 func (RefTime) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
1597 return attribute.String("vcs.provider.name", string(val))
1598 }
1599
1600 // RepositoryCount is an instrument used to record metric values conforming to
1601 // the "vcs.repository.count" semantic conventions. It represents the number of
1602 // repositories in an organization.
1603 type RepositoryCount struct {
1604 metric.Int64UpDownCounter
1605 }
1606
1607 var newRepositoryCountOpts = []metric.Int64UpDownCounterOption{
1608 metric.WithDescription("The number of repositories in an organization."),
1609 metric.WithUnit("{repository}"),
1610 }
1611
1612 // NewRepositoryCount returns a new RepositoryCount instrument.
1613 func NewRepositoryCount(
1614 m metric.Meter,
1615 opt ...metric.Int64UpDownCounterOption,
1616 ) (RepositoryCount, error) {
1617 // Check if the meter is nil.
1618 if m == nil {
1619 return RepositoryCount{noop.Int64UpDownCounter{}}, nil
1620 }
1621
1622 if len(opt) == 0 {
1623 opt = newRepositoryCountOpts
1624 } else {
1625 opt = append(opt, newRepositoryCountOpts...)
1626 }
1627
1628 i, err := m.Int64UpDownCounter(
1629 "vcs.repository.count",
1630 opt...,
1631 )
1632 if err != nil {
1633 return RepositoryCount{noop.Int64UpDownCounter{}}, err
1634 }
1635 return RepositoryCount{i}, nil
1636 }
1637
1638 // Inst returns the underlying metric instrument.
1639 func (m RepositoryCount) Inst() metric.Int64UpDownCounter {
1640 return m.Int64UpDownCounter
1641 }
1642
1643 // Name returns the semantic convention name of the instrument.
1644 func (RepositoryCount) Name() string {
1645 return "vcs.repository.count"
1646 }
1647
1648 // Unit returns the semantic convention unit of the instrument
1649 func (RepositoryCount) Unit() string {
1650 return "{repository}"
1651 }
1652
1653 // Description returns the semantic convention description of the instrument
1654 func (RepositoryCount) Description() string {
1655 return "The number of repositories in an organization."
1656 }
1657
1658 // Add adds incr to the existing count for attrs.
1659 //
1660 // All additional attrs passed are included in the recorded value.
1661 func (m RepositoryCount) Add(
1662 ctx context.Context,
1663 incr int64,
1664 attrs ...attribute.KeyValue,
1665 ) {
1666 if len(attrs) == 0 {
1667 m.Int64UpDownCounter.Add(ctx, incr)
1668 return
1669 }
1670
1671 o := addOptPool.Get().(*[]metric.AddOption)
1672 defer func() {
1673 *o = (*o)[:0]
1674 addOptPool.Put(o)
1675 }()
1676
1677 *o = append(
1678 *o,
1679 metric.WithAttributes(
1680 attrs...,
1681 ),
1682 )
1683
1684 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1685 }
1686
1687 // AddSet adds incr to the existing count for set.
1688 func (m RepositoryCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1689 if set.Len() == 0 {
1690 m.Int64UpDownCounter.Add(ctx, incr)
1691 return
1692 }
1693
1694 o := addOptPool.Get().(*[]metric.AddOption)
1695 defer func() {
1696 *o = (*o)[:0]
1697 addOptPool.Put(o)
1698 }()
1699
1700 *o = append(*o, metric.WithAttributeSet(set))
1701 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1702 }
1703
1704 // AttrOwnerName returns an optional attribute for the "vcs.owner.name" semantic
1705 // convention. It represents the group owner within the version control system.
1706 func (RepositoryCount) AttrOwnerName(val string) attribute.KeyValue {
1707 return attribute.String("vcs.owner.name", val)
1708 }
1709
1710 // AttrProviderName returns an optional attribute for the "vcs.provider.name"
1711 // semantic convention. It represents the name of the version control system
1712 // provider.
1713 func (RepositoryCount) AttrProviderName(val ProviderNameAttr) attribute.KeyValue {
1714 return attribute.String("vcs.provider.name", string(val))
1715 }