Skip to content

Commit

Permalink
remove unnecessary level (#10951)
Browse files Browse the repository at this point in the history
The MeterProvider used to generate the matric will make calls to
recording the metric Noops. Removing the level check.

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
codeboten authored Aug 23, 2024
1 parent dadc331 commit b10029c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 18 deletions.
6 changes: 0 additions & 6 deletions exporter/exporterhelper/obsexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import (
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/metadata"
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
)

// obsReport is a helper to add observability to an exporter.
type obsReport struct {
level configtelemetry.Level
spanNamePrefix string
tracer trace.Tracer
dataType component.DataType
Expand Down Expand Up @@ -48,7 +46,6 @@ func newExporter(cfg obsReportSettings) (*obsReport, error) {
}

return &obsReport{
level: cfg.exporterCreateSettings.TelemetrySettings.MetricsLevel,
spanNamePrefix: obsmetrics.ExporterPrefix + cfg.exporterID.String(),
tracer: cfg.exporterCreateSettings.TracerProvider.Tracer(cfg.exporterID.String()),
dataType: cfg.dataType,
Expand Down Expand Up @@ -113,9 +110,6 @@ func (or *obsReport) startOp(ctx context.Context, operationSuffix string) contex
}

func (or *obsReport) recordMetrics(ctx context.Context, dataType component.DataType, sent, failed int64) {
if or.level == configtelemetry.LevelNone {
return
}
var sentMeasure, failedMeasure metric.Int64Counter
switch dataType {
case component.DataTypeTraces:
Expand Down
7 changes: 1 addition & 6 deletions receiver/receiverhelper/obsreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import (
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receiverhelper/internal/metadata"
)

// ObsReport is a helper to add observability to a receiver.
type ObsReport struct {
level configtelemetry.Level
spanNamePrefix string
transport string
longLivedCtx bool
Expand Down Expand Up @@ -56,7 +54,6 @@ func newReceiver(cfg ObsReportSettings) (*ObsReport, error) {
return nil, err
}
return &ObsReport{
level: cfg.ReceiverCreateSettings.TelemetrySettings.MetricsLevel,
spanNamePrefix: obsmetrics.ReceiverPrefix + cfg.ReceiverID.String(),
transport: cfg.Transport,
longLivedCtx: cfg.LongLivedCtx,
Expand Down Expand Up @@ -166,9 +163,7 @@ func (rec *ObsReport) endOp(

span := trace.SpanFromContext(receiverCtx)

if rec.level != configtelemetry.LevelNone {
rec.recordMetrics(receiverCtx, dataType, numAccepted, numRefused)
}
rec.recordMetrics(receiverCtx, dataType, numAccepted, numRefused)

// end span according to errors
if span.IsRecording() {
Expand Down
7 changes: 1 addition & 6 deletions receiver/scraperhelper/obsreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scrapererror"
Expand All @@ -22,7 +21,6 @@ import (

// ObsReport is a helper to add observability to a scraper.
type ObsReport struct {
level configtelemetry.Level
receiverID component.ID
scraper component.ID
tracer trace.Tracer
Expand All @@ -49,7 +47,6 @@ func newScraper(cfg ObsReportSettings) (*ObsReport, error) {
return nil, err
}
return &ObsReport{
level: cfg.ReceiverCreateSettings.TelemetrySettings.MetricsLevel,
receiverID: cfg.ReceiverID,
scraper: cfg.Scraper,
tracer: cfg.ReceiverCreateSettings.TracerProvider.Tracer(cfg.Scraper.String()),
Expand Down Expand Up @@ -91,9 +88,7 @@ func (s *ObsReport) EndMetricsOp(

span := trace.SpanFromContext(scraperCtx)

if s.level != configtelemetry.LevelNone {
s.recordMetrics(scraperCtx, numScrapedMetrics, numErroredMetrics)
}
s.recordMetrics(scraperCtx, numScrapedMetrics, numErroredMetrics)

// end span according to errors
if span.IsRecording() {
Expand Down

0 comments on commit b10029c

Please sign in to comment.