Debian Codegraph @

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