]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/go.opencensus.io/stats/record.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / go.opencensus.io / stats / record.go
1 // Copyright 2018, OpenCensus Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15
16 package stats
17
18 import (
19 "context"
20
21 "go.opencensus.io/exemplar"
22 "go.opencensus.io/stats/internal"
23 "go.opencensus.io/tag"
24 )
25
26 func init() {
27 internal.SubscriptionReporter = func(measure string) {
28 mu.Lock()
29 measures[measure].subscribe()
30 mu.Unlock()
31 }
32 }
33
34 // Record records one or multiple measurements with the same context at once.
35 // If there are any tags in the context, measurements will be tagged with them.
36 func Record(ctx context.Context, ms ...Measurement) {
37 recorder := internal.DefaultRecorder
38 if recorder == nil {
39 return
40 }
41 if len(ms) == 0 {
42 return
43 }
44 record := false
45 for _, m := range ms {
46 if m.m.subscribed() {
47 record = true
48 break
49 }
50 }
51 if !record {
52 return
53 }
54 recorder(tag.FromContext(ctx), ms, exemplar.AttachmentsFromContext(ctx))
55 }
56
57 // RecordWithTags records one or multiple measurements at once.
58 //
59 // Measurements will be tagged with the tags in the context mutated by the mutators.
60 // RecordWithTags is useful if you want to record with tag mutations but don't want
61 // to propagate the mutations in the context.
62 func RecordWithTags(ctx context.Context, mutators []tag.Mutator, ms ...Measurement) error {
63 ctx, err := tag.New(ctx, mutators...)
64 if err != nil {
65 return err
66 }
67 Record(ctx, ms...)
68 return nil
69 }