{"record":{"id":"950ef01144ab6f64","repo":"microsoft/aspire","slug":"scope-limit-of-telemetryrepositorylimits-maxscopecount","errorCode":null,"errorMessage":"Scope limit of {TelemetryRepositoryLimits.MaxScopeCount} reached for {telemetryType}. Scope '{name}' will not be added.","messagePattern":"Scope limit of (.+?) reached for (.+?)\\. Scope '(.+?)' will not be added\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs","lineNumber":528,"sourceCode":"        }\n    }\n\n    public static bool TryGetOrAddScope(Dictionary<string, OtlpScope> scopes, InstrumentationScope? scope, OtlpContext context, TelemetryType telemetryType, [NotNullWhen(true)] out OtlpScope? s)\n    {\n        try\n        {\n            // The instrumentation scope information for the spans in this message.\n            // Semantically when InstrumentationScope isn't set, it is equivalent with\n            // an empty instrumentation scope name (unknown).\n            var name = scope?.Name ?? string.Empty;\n            if (scopes.TryGetValue(name, out s))\n            {\n                return true;\n            }\n\n            if (scopes.Count >= TelemetryRepositoryLimits.MaxScopeCount)\n            {\n                throw new InvalidOperationException($\"Scope limit of {TelemetryRepositoryLimits.MaxScopeCount} reached for {telemetryType}. Scope '{name}' will not be added.\");\n            }\n\n            s = (scope != null)\n                ? new OtlpScope(scope.Name, scope.Version, scope.Attributes.ToKeyValuePairs(context))\n                : OtlpScope.Empty;\n\n            scopes.Add(name, s);\n\n            context.Logger.LogTrace(\"Added scope '{ScopeName}' to {TelemetryType}.\", s.Name, telemetryType);\n            return true;\n        }\n        catch (Exception ex)\n        {\n            context.Logger.LogInformation(ex, \"Error adding scope to {TelemetryType}.\", telemetryType);\n            s = null;\n            return false;\n        }\n    }","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs#L510-L546","documentation":"Aspire Dashboard caps the number of distinct instrumentation scopes (OtlpScope) it keeps in memory per telemetry type via TelemetryRepositoryLimits.MaxScopeCount. TryGetOrAddScope throws this InvalidOperationException when a new scope arrives and the cache is already at the limit; the scope (and its telemetry) is not added. The limit protects the Dashboard from unbounded memory growth caused by hosts that generate endless unique scope identities.","triggerScenarios":"TryGetOrAddScope throws when scopes.Count >= TelemetryRepositoryLimits.MaxScopeCount and an unseen scope name/version/attributes tuple is added while importing logs, metrics, or traces. Happens on the OTLP ingestion path when telemetry carries more distinct InstrumentationScope values than the configured maximum.","commonSituations":"Applications with dynamically-named ActivitySource/Meter names (e.g. names embedding ids or timestamps); many microservices each with unique scopes funneling into one Dashboard; a bug causing a new scope identity per request; environment where the incoming telemetry volume is much higher than the Dashboard default limit anticipates.","solutions":["Find and fix the producer generating unbounded distinct scope names; use stable, static ActivitySource/Meter names.","Reduce the number of distinct instrumentation scopes in the emitting applications (share one Meter/ActivitySource per component).","Filter or aggregate telemetry upstream in an OpenTelemetry Collector so fewer scopes reach the Dashboard."],"exampleFix":"// before: unique scope per instance\nvar source = new ActivitySource($\"MyApp.{Guid.NewGuid()}\");\n// after: stable scope name\nvar source = new ActivitySource(\"MyApp\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    repository.AddTraces(request);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Scope limit of\"))\n{\n    logger.LogWarning(ex, \"Scope limit reached; scope '{Scope}' dropped.\", scopeName);\n}","preventionTips":["Use static, stable ActivitySource/Meter names; never embed ids or timestamps in scope names.","Audit libraries for dynamically-generated instrumentation scope names.","Keep the count of distinct instrumentation scopes small per application."],"tags":["opentelemetry","limits","scope","dashboard","memory"],"backgroundTag":"resource-limit-exceeded","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}