microsoft/aspire · error

Dimension limit of reached.

Error message

Dimension limit of {TelemetryRepositoryLimits.MaxDimensionCount} reached.

What it means

The repository limits the number of unique metric attribute (dimension) combinations per instrument to TelemetryRepositoryLimits.MaxDimensionCount. GetOrAddMetricDimension checks the per-instrument dimension count before adding a new one and throws InvalidOperationException when the cap is reached, guarding against unbounded high-cardinality storage.

Solutions

  1. Remove or bound high-cardinality attributes on your metrics; keep tag values from small fixed sets.
  2. Increase TelemetryRepositoryLimits.MaxInstrumentCount/MaxDimensionCount limits via dashboard configuration if your workload is legitimately dimensional.
  3. Restart the dashboard to clear in-memory ingestion state after fixing the emitter.
  4. Use OTel attribute-per-cardinality guidance (e.g. drop url, user id attributes from metrics).

Example fix

// before
counter.Add(1, new KeyValuePair<string, object?>("user.id", userId)); // unbounded
// after
counter.Add(1, new KeyValuePair<string, object?>("user.tier", userTier)); // bounded set
Defensive patterns

Strategy: try-catch

Validate before calling

// audit metric attributes for unbounded values before export
foreach (var attr in attributes)
    if (attr.Value is string s && IsHighCardinality(s))
        logger.LogWarning("Attribute {Key} looks high-cardinality", attr.Key);

Try / catch

try
{
    await repo.AddMetricsAsync(request);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Dimension limit"))
{
    logger.LogWarning(ex, "Metric cardinality limit reached for instrument.");
}

Prevention

When it happens

Trigger: AddMetricToDatabase -> GetOrAddMetricDimension for an instrument whose ingestionState.DimensionCounts[instrumentId] is already >= MaxDimensionCount while the incoming point has a new attribute combination.

Common situations: Metrics with high-cardinality attributes (user ids, urls, container ids, correlation ids); a service under attack or a load test hammering unique tag values; long dashboard sessions accumulating dimensions from many emitters.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/308bfd6566b47ba5. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Dashboard/Otlp/Storage/SqliteTelemetryRepository.Metrics.Writes.cs:511

        {
            candidates = [];
            ingestionState.Dimensions.Add(cacheKey, candidates);
        }

        foreach (var candidate in candidates)
        {
            if (candidate.Attributes.SequenceEqual(attributes))
            {
                return candidate;
            }
        }

        var knownAttributeValues = ingestionState.KnownAttributeValues[instrumentId];
        knownAttributeValues.ValidateDimension(attributes);
        var dimensionCount = ingestionState.DimensionCounts[instrumentId];
        if (dimensionCount >= TelemetryRepositoryLimits.MaxDimensionCount)
        {
            throw new InvalidOperationException($"Dimension limit of {TelemetryRepositoryLimits.MaxDimensionCount} reached.");
        }
        knownAttributeValues.AddDimension(attributes);
        var dimension = new MetricDimensionState { Attributes = attributes };
        ingestionState.PendingDimensions.Add(new PendingMetricDimension(instrumentId, attributeHash, dimension));
        ingestionState.PendingDimensionAttributes.AddRange(attributes.Select((attribute, ordinal) => new PendingMetricDimensionAttribute(
            dimension,
            ordinal,
            attribute.Key,
            attribute.Value)));

        candidates.Add(dimension);
        ingestionState.DimensionCounts[instrumentId] = dimensionCount + 1;
        return dimension;
    }

    private static void InsertMetricDimensions(
        SqliteConnection connection,
        IDbTransaction transaction,

View on GitHub (pinned to 25830f84bd)