Skip to content

Commit

Permalink
Connect cardinality limit to metric SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Aug 18, 2023
1 parent 6aa1640 commit cc11cb0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions sdk/metric/limit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metric // import "go.opentelemetry.io/otel/sdk/metric"

import "go.opentelemetry.io/otel/sdk/metric/internal/x"

func cardinalityLimit() int {
if !x.Enabled(x.CardinalityLimit) {
return 0
}

// TODO: make this configurable.

// Default 2000.
return 2000
}
3 changes: 2 additions & 1 deletion sdk/metric/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ func (i *inserter[N]) cachedAggregator(scope instrumentation.Scope, kind Instrum
normID := id.normalize()
cv := i.aggregators.Lookup(normID, func() aggVal[N] {
b := aggregate.Builder[N]{
Temporality: i.pipeline.reader.temporality(kind),
Temporality: i.pipeline.reader.temporality(kind),
AggregationLimit: cardinalityLimit(),
}
if len(stream.AllowAttributeKeys) > 0 {
b.Filter = stream.attributeFilter()
Expand Down

0 comments on commit cc11cb0

Please sign in to comment.