1// Copyright The OpenTelemetry 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 15package exporterhelper 16 17import ( 18 "context" 19 20 "go.opencensus.io/stats" 21 "go.opencensus.io/tag" 22 23 "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" 24 "go.opentelemetry.io/collector/obsreport" 25) 26 27// TODO: Incorporate this functionality along with tests from obsreport_test.go 28// into existing `obsreport` package once its functionally is not exposed 29// as public API. For now this part is kept private. 30 31// obsExporter is a helper to add observability to a component.Exporter. 32type obsExporter struct { 33 *obsreport.Exporter 34 mutators []tag.Mutator 35} 36 37// newObsExporter creates a new observability exporter. 38func newObsExporter(cfg obsreport.ExporterSettings) *obsExporter { 39 return &obsExporter{ 40 obsreport.NewExporter(cfg), 41 []tag.Mutator{tag.Upsert(obsmetrics.TagKeyExporter, cfg.ExporterID.String(), tag.WithTTL(tag.TTLNoPropagation))}, 42 } 43} 44 45// recordTracesEnqueueFailure records number of spans that failed to be added to the sending queue. 46func (eor *obsExporter) recordTracesEnqueueFailure(ctx context.Context, numSpans int) { 47 _ = stats.RecordWithTags(ctx, eor.mutators, obsmetrics.ExporterFailedToEnqueueSpans.M(int64(numSpans))) 48} 49 50// recordMetricsEnqueueFailure records number of metric points that failed to be added to the sending queue. 51func (eor *obsExporter) recordMetricsEnqueueFailure(ctx context.Context, numMetricPoints int) { 52 _ = stats.RecordWithTags(ctx, eor.mutators, obsmetrics.ExporterFailedToEnqueueMetricPoints.M(int64(numMetricPoints))) 53} 54 55// recordLogsEnqueueFailure records number of log records that failed to be added to the sending queue. 56func (eor *obsExporter) recordLogsEnqueueFailure(ctx context.Context, numLogRecords int) { 57 _ = stats.RecordWithTags(ctx, eor.mutators, obsmetrics.ExporterFailedToEnqueueLogRecords.M(int64(numLogRecords))) 58} 59