Debian Codegraph @

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