Skip to content

Commit

Permalink
Rename metric to datadog.otlp_translator.resources.missing_source
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Dec 19, 2023
1 parent c3f76c1 commit beb9b50
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .chloggen/mx-psi_rename-to-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component (e.g. pkg/quantile)
component: pkg/otlp/metrics

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Rename `datadog.otlp_translator.metrics.missing_source` to `datadog.otlp_translator.resources.missing_source` with `signal:metrics` attribute.

# The PR related to this change
issues: []

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
21 changes: 13 additions & 8 deletions pkg/otlp/metrics/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"
"go.uber.org/zap"
"golang.org/x/exp/slices"
Expand All @@ -41,8 +42,12 @@ const (
metricName string = "metric name"
errNoBucketsNoSumCount string = "no buckets mode and no send count sum are incompatible"

meterName string = "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics"
missingSourceMetricName string = "datadog.otlp_translator.metrics.missing_source"
meterName string = "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes"
missingSourceMetricName string = "datadog.otlp_translator.resources.missing_source"
)

var (
signalTypeSet = attribute.NewSet(attribute.String("signal", "logs"))
)

var _ source.Provider = (*noSourceProvider)(nil)
Expand Down Expand Up @@ -101,7 +106,7 @@ func NewTranslator(set component.TelemetrySettings, options ...TranslatorOption)
missingSources, err := meter.Int64Counter(
missingSourceMetricName,
otelmetric.WithDescription("OTLP metrics that are missing a source (e.g. hostname)"),
otelmetric.WithUnit("[metric]"),
otelmetric.WithUnit("{resource}"),
)
if err != nil {
return nil, fmt.Errorf("failed to build missing source counter: %w", err)
Expand Down Expand Up @@ -678,6 +683,11 @@ func (t *Translator) MapMetrics(ctx context.Context, md pmetric.Metrics, consume
if err != nil {
return metadata, err
}
if !hasSource {
// Only count metrics if they do not come from the translator itself.
t.instruments.missingSources.Add(ctx, 1, otelmetric.WithAttributeSet(signalTypeSet))
}

var host string
switch src.Kind {
case source.HostnameKind:
Expand All @@ -699,11 +709,6 @@ func (t *Translator) MapMetrics(ctx context.Context, md pmetric.Metrics, consume
ilm := ilms.At(j)
metricsArray := ilm.Metrics()

if !hasSource && ilm.Scope().Name() != meterName {
// Only count metrics if they do not come from the translator itself.
t.instruments.missingSources.Add(ctx, int64(metricsArray.Len()))
}

var additionalTags []string
if t.cfg.InstrumentationScopeMetadataAsTags {
additionalTags = append(attributeTags, instrumentationscope.TagsFromInstrumentationScopeMetadata(ilm.Scope())...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/otlp/metrics/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestInternalTelemetryMetrics(t *testing.T) {
name: "simple",
otlpfile: "testdata/otlpdata/source/simple.json",
ddogfile: "testdata/datadogdata/source/simple.json",
expectedNumMissing: 4,
expectedNumMissing: 1,
},
}

Expand Down

0 comments on commit beb9b50

Please sign in to comment.