-
-
Notifications
You must be signed in to change notification settings - Fork 507
Add event environments and filtering #2570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ejsmith
wants to merge
6
commits into
main
Choose a base branch
from
feature/event-environments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c337d52
Add event environments and filtering
ejsmith ac99281
Keep migration seed fixture current with registered migrations
ejsmith 05efc27
Scope environment choices to the active saved view time range
ejsmith abe2060
Update browser tests for the machine and runtime tab label
ejsmith dd1470b
Support environment on GET event submissions
ejsmith cc1cfc1
Preserve supplied environment casing
ejsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| --- | ||
| title: "Environments" | ||
| --- | ||
|
|
||
| # Environments | ||
|
|
||
| Use an environment to distinguish production, staging, development, or a custom deployment within one project. Each event can carry one optional top-level `environment` string. The same error still belongs to one stack, with one shared status and fixed version. | ||
|
|
||
| ## Configure your client | ||
|
|
||
| Set a default during application startup. In the .NET client: | ||
|
|
||
| ```csharp | ||
| client.Configuration.SetEnvironment("production"); | ||
| client.CreateLog("Deployment complete").SetEnvironment("staging").Submit(); | ||
| ``` | ||
|
|
||
| You can also set `Exceptionless:Environment` in .NET configuration, or the `Exceptionless__Environment` environment variable. The hosting integration uses `IHostEnvironment.EnvironmentName` when no explicit environment is configured. A per-event value overrides the default. | ||
|
|
||
| In the JavaScript client: | ||
|
|
||
| ```javascript | ||
| await Exceptionless.startup((config) => { | ||
| config.apiKey = "API_KEY_HERE"; | ||
| config.environment = "production"; | ||
| }); | ||
|
|
||
| await Exceptionless.createLog("Deployment complete") | ||
| .setEnvironment("staging") | ||
| .submit(); | ||
| ``` | ||
|
|
||
| For direct API submissions: | ||
|
|
||
| ```json | ||
| { | ||
| "type": "log", | ||
| "message": "Deployment complete", | ||
| "environment": "production" | ||
| } | ||
| ``` | ||
|
|
||
| Names are trimmed, with a maximum of 64 characters. Events preserve the supplied casing: `" Production "` is stored and returned as `"Production"`. Filtering is case-insensitive, and aggregation keys are normalized to lowercase, so `Production` and `production` share one environment bucket. Custom names such as `qa-west` are supported. Empty, oversized, control-character, and non-string values are treated as unspecified. Historical events and older clients without this field remain unspecified; they are never assumed to be production. | ||
|
|
||
| ## Filter your data | ||
|
|
||
| Choose **Manage filters → Environment** on Events, Stacks, Sessions, or Stream. Select one or more names, or **Unspecified** for events without an environment. Clear the selection to include all environments. The picker discovers names for the selected projects and time range; you can also enter a name that has no current events. | ||
|
|
||
| Environment selections persist in URLs and saved views. Events, sessions, and stream tables have an optional Environment column. Event details show Environment in the overview; **Machine & runtime** contains the existing `data.@environment` diagnostics. | ||
|
|
||
| Environment searches and aggregations are available on every plan: | ||
|
|
||
| | Search | Meaning | | ||
| | --- | --- | | ||
| | `environment:production` | Production events | | ||
| | `(environment:production OR environment:staging)` | Either deployment | | ||
| | `_missing_:environment` | Historical or unspecified events | | ||
| | `_exists_:environment` | Events with an environment | | ||
| | `environment:"qa west"` | A custom name containing spaces | | ||
|
|
||
| Stack dashboard counts and charts use events matching the filter. Stack status remains shared, so changing status while viewing production also changes the same stack seen in staging. Automatic session detection separates the same user's activity by environment. | ||
|
|
||
| ## Fixing stacks across deployments | ||
|
|
||
| Use [fixed in version](/docs/versioning/) when environments run different releases. For example, if a stack is fixed in `2.4.0`, occurrences from production running `2.3.0` do not represent a regression just because staging already has the fix. Continue sending the application version with events. Plain **Fixed**, without a version, retains its existing behavior across all environments. | ||
|
|
||
| ## Rollout | ||
|
|
||
| Deploy the server before adopting SDK versions that expose the new setting. The server adds mappings to existing event indices without rewriting historical events. Clients that do not send an environment continue to work. `data.@environment` and custom `data.environment` values retain their existing meanings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Exceptionless.Core/Migrations/010_AddEventEnvironment.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using Exceptionless.Core.Extensions; | ||
| using Exceptionless.Core.Models; | ||
| using Exceptionless.Core.Repositories.Configuration; | ||
| using Foundatio.Repositories.Elasticsearch.Extensions; | ||
| using Foundatio.Repositories.Migrations; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Exceptionless.Core.Migrations; | ||
|
|
||
| public sealed class AddEventEnvironment : MigrationBase | ||
| { | ||
| private readonly ExceptionlessElasticConfiguration _configuration; | ||
|
|
||
| public AddEventEnvironment(ExceptionlessElasticConfiguration configuration, ILoggerFactory loggerFactory) : base(loggerFactory) | ||
| { | ||
| _configuration = configuration; | ||
| MigrationType = MigrationType.VersionedAndResumable; | ||
| Version = 10; | ||
| } | ||
|
|
||
| public override async Task RunAsync(MigrationContext context) | ||
| { | ||
| var response = await _configuration.Client.Indices.PutMappingAsync<PersistentEvent>(mapping => mapping | ||
| .Indices($"{_configuration.Events.Name}-v*-*") | ||
| .AllowNoIndices(true) | ||
| .IgnoreUnavailable(true) | ||
| .Properties(properties => properties.Text(ev => ev.Environment, | ||
| text => text.Analyzer(EventIndex.LOWER_KEYWORD_ANALYZER) | ||
| .Fields(fields => fields.Keyword("keyword", keyword => keyword.Normalizer("lowercase"))))), context.CancellationToken); | ||
| _logger.LogRequest(response); | ||
| if (!response.IsValidResponse) | ||
| { | ||
| throw new InvalidOperationException("Unable to add the event environment mapping: " + response.DebugInformation); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Exceptionless.Core/Repositories/Queries/EventEnvironmentFilter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using Foundatio.Parsers.LuceneQueries; | ||
| using Foundatio.Parsers.LuceneQueries.Nodes; | ||
|
|
||
| namespace Exceptionless.Core.Repositories.Queries; | ||
|
|
||
| /// <summary> | ||
| /// Preserves deployment scope when counting all project users, including users without matching errors. | ||
| /// </summary> | ||
| public static class EventEnvironmentFilter | ||
| { | ||
| public static async Task<string?> GetAsync(string? filter) | ||
| { | ||
| if (String.IsNullOrWhiteSpace(filter)) | ||
| return null; | ||
|
|
||
| return GetConstraint(await new LuceneQueryParser().ParseAsync(filter)); | ||
| } | ||
|
|
||
| private static string? GetConstraint(IQueryNode? node, bool negate = false) | ||
| { | ||
| if (node is not IFieldQueryNode field) | ||
| return null; | ||
|
|
||
| if (String.Equals(field.UnescapedField, "environment", StringComparison.OrdinalIgnoreCase)) | ||
| return negate ? $"NOT ({node})" : node.ToString(); | ||
|
|
||
| if (field.Field is not null || node is not GroupNode group) | ||
| return null; | ||
|
ejsmith marked this conversation as resolved.
|
||
|
|
||
| negate ^= group.IsNegated == true || group.Prefix == "-"; | ||
| if (group.Left is null) | ||
| return GetConstraint(group.Right, negate); | ||
| if (group.Right is null) | ||
| return GetConstraint(group.Left, negate); | ||
|
|
||
| string? left = GetConstraint(group.Left, negate); | ||
| string? right = GetConstraint(group.Right, negate); | ||
| bool isOr = (group.Operator == GroupOperator.Or) ^ negate; | ||
| // An unrelated OR branch permits every environment. Unrelated AND clauses do not restrict it. | ||
| if (isOr && (left is null || right is null)) | ||
| return null; | ||
| if (left is null) | ||
| return right; | ||
| if (right is null) | ||
| return left; | ||
|
|
||
| return $"({left} {(isOr ? "OR" : "AND")} {right})"; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.