1 // Copyright 2018, OpenCensus Authors
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
21 "go.opencensus.io/stats/internal"
22 "go.opencensus.io/tag"
26 internal.SubscriptionReporter = func(measure string) {
28 measures[measure].subscribe()
33 // Record records one or multiple measurements with the same context at once.
34 // If there are any tags in the context, measurements will be tagged with them.
35 func Record(ctx context.Context, ms ...Measurement) {
36 recorder := internal.DefaultRecorder
44 for _, m := range ms {
45 if m.desc.subscribed() {
53 // TODO(songy23): fix attachments.
54 recorder(tag.FromContext(ctx), ms, map[string]interface{}{})
57 // RecordWithTags records one or multiple measurements at once.
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...)