-
Notifications
You must be signed in to change notification settings - Fork 346
Add Telemetry to Application Name #3683
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
aaronburtle
wants to merge
10
commits into
main
Choose a base branch
from
dev/aaronburtle/Telemetry-in-app-name
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.
+2,328
−84
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce2bd0f
add telemetry to app name
aaronburtle 88673bb
fill in gaps
aaronburtle af161e1
fix hosted coverage better testing
aaronburtle 968b06e
improve hot reload logging
aaronburtle 51980d0
idempotent telemetry in hosted scenario
aaronburtle 47fa0aa
flush in hosted scenario
aaronburtle b467188
bounded logbuffer, env var isolation in test
aaronburtle 3ba9f00
Merge branch 'main' into dev/aaronburtle/Telemetry-in-app-name
aaronburtle 2ac6628
doc update, format fix
aaronburtle 8e098b8
Merge branch 'dev/aaronburtle/Telemetry-in-app-name' of https://githu…
aaronburtle 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,104 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.IO.Abstractions; | ||
| using Azure.DataApiBuilder.Config; | ||
| using Azure.DataApiBuilder.Config.ObjectModel; | ||
| using Azure.DataApiBuilder.Config.Telemetry; | ||
| using Azure.DataApiBuilder.Core.Configurations; | ||
| using Cli.Constants; | ||
| using CommandLine; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Cli.Commands | ||
| { | ||
| /// <summary> | ||
| /// Options for the <c>appname</c> command, which encodes the DAB telemetry Application Name | ||
| /// from a config file, or decodes a telemetry Application Name into a human-readable description. | ||
| /// </summary> | ||
| [Verb("appname", isDefault: false, HelpText = "Show or decode the DAB telemetry 'Application Name' embedded in SQL connections.", Hidden = false)] | ||
| public class AppNameOptions : Options | ||
| { | ||
| public AppNameOptions(string? decode = null, string? output = null, string? config = null) | ||
| : base(config) | ||
| { | ||
| Decode = decode; | ||
| Output = output; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// When provided, decodes the given telemetry Application Name string into a human-readable | ||
| /// description instead of encoding from a config file. Decoding is tolerant of truncation. | ||
| /// </summary> | ||
| [Option("decode", Required = false, HelpText = "Decode a telemetry Application Name string into a human-readable description.")] | ||
| public string? Decode { get; } | ||
|
|
||
| /// <summary> | ||
| /// Optional file path to write the result to. When omitted, the result is written to stdout. | ||
| /// </summary> | ||
| [Option('o', "output", Required = false, HelpText = "Write the result to the specified file instead of stdout.")] | ||
| public string? Output { get; } | ||
|
|
||
| /// <summary> | ||
| /// Handles the <c>appname</c> command. | ||
| /// </summary> | ||
| public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem) | ||
| { | ||
| // Decode mode: a pure, tolerant string decode. No config or validation is required. | ||
| // Presence of the option (even with an empty/whitespace value) selects decode mode; the | ||
| // decoder itself reports a friendly message for empty input. | ||
| if (Decode is not null) | ||
| { | ||
| IReadOnlyList<string> decodedLines = ApplicationNameTelemetry.Decode(Decode); | ||
| WriteResult(string.Join(Environment.NewLine, decodedLines), fileSystem, logger, trailingNewLine: true); | ||
| return CliReturnCode.SUCCESS; | ||
| } | ||
|
|
||
| // Encode mode: parse the config and emit the telemetry Application Name. | ||
| // We intentionally do NOT run full `validate` here — validation opens a database | ||
| // connection, whereas encoding only needs the parsed runtime/entity settings. | ||
| // Requiring a live database would defeat the purpose of this static inspection command. | ||
| if (!ConfigGenerator.TryGetConfigForRuntimeEngine(Config, loader, fileSystem, out _)) | ||
| { | ||
| logger.LogError("Could not determine the config file to use."); | ||
| return CliReturnCode.GENERAL_ERROR; | ||
| } | ||
|
|
||
| RuntimeConfigProvider runtimeConfigProvider = new(loader); | ||
| if (!runtimeConfigProvider.TryGetConfig(out RuntimeConfig? runtimeConfig) || runtimeConfig is null) | ||
| { | ||
| logger.LogError("Failed to parse the config file."); | ||
| return CliReturnCode.GENERAL_ERROR; | ||
| } | ||
|
|
||
| // There is no live connection context at design time, so the context fields | ||
| // (Protocol/Object/Source/Role) are emitted as placeholders. | ||
| string telemetryAppName = ApplicationNameTelemetry.EncodeTelemetryString(runtimeConfig, liveDataSource: null); | ||
| WriteResult(telemetryAppName, fileSystem, logger, trailingNewLine: false); | ||
| return CliReturnCode.SUCCESS; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Writes the result to the output file when <c>--output</c> is provided, otherwise to stdout. | ||
| /// </summary> | ||
| private void WriteResult(string content, IFileSystem fileSystem, ILogger logger, bool trailingNewLine) | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(Output)) | ||
| { | ||
| // Mirror stdout behavior: append a trailing newline for human-readable (decode) output, | ||
| // but keep encode output exact (no trailing newline) so it can be copied/piped verbatim. | ||
| string fileContent = trailingNewLine ? content + Environment.NewLine : content; | ||
| fileSystem.File.WriteAllText(Output, fileContent); | ||
| logger.LogInformation("Wrote output to '{outputFile}'.", Output); | ||
| } | ||
| else if (trailingNewLine) | ||
| { | ||
| Console.WriteLine(content); | ||
| } | ||
| else | ||
| { | ||
| Console.Write(content); | ||
| } | ||
| } | ||
| } | ||
| } |
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
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.