-
Notifications
You must be signed in to change notification settings - Fork 65
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
Add initial telelmetry skeleton #495
base: main
Are you sure you want to change the base?
Conversation
apoorvdeshmukh
commented
Jan 2, 2024
- Telemetry and logging based on env variable
@@ -5,11 +5,13 @@ go 1.21 | |||
require ( | |||
github.com/alecthomas/chroma/v2 v2.5.0 | |||
github.com/billgraziano/dpapi v0.4.0 | |||
github.com/denisbrodbeck/machineid v1.0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.LogTelemtry() | ||
} | ||
|
||
func (c *AddContext) LogTelemtry() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -93,4 +94,23 @@ func (c *AddContext) run() { | |||
{localizer.Sprintf("To start interactive query session"), "sqlcmd query"}, | |||
{localizer.Sprintf("To run a query"), "sqlcmd query \"SELECT @@version\""}, | |||
}, localizer.Sprintf("Current Context '%v'", context.Name)) | |||
c.LogTelemtry() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of requiring run
implementation to call this directly, is it possible to define an interface with LogTelemetry
as a member and have whatever calls run
also call it if the object implements it?
Ideally the command would just populate the event and not be responsible for calling any telemetry
package methods directly. We should avoid coupling the command to the telemetry implementation.
properties["SubCommand"] = "add-context" | ||
if c.name != "" { | ||
properties["name"] = "set" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function looks mostly like boilerplate that could be implemented in some common place and just have the command implementation pass the values not the property names for Command and SubCommand.
It's probably also useful to define a new type like
type CommandEvent map[string]string
func NewCommandEvent(command string, subCommand string) *CommandEvent {
// Set Command and SubCommand properties on new CommandEvent and return the event
}
func (e *CommandEvent) SetProperty(p string, v string) *CommandEvent {
// Add the given property to the map and return e
}
eventName := "config-add-user" | ||
properties := map[string]string{} | ||
if c.username != "" { | ||
properties["username"] = "set" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it easier to build telemetry reports if a property always has a value instead of omitting it when not used? What do the report queries look like?
the telemetry property keys to identify the command and subcommand should be extractable from Refers to: internal/cmdparser/interface.go:27 in 12039f3. [](commit_id = 12039f3, deletion_comment = False) |
|
||
// LogTelemtry is used to track the useful telemetry for the command | ||
// To be enforced after the review | ||
// LogTelemtry() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) | ||
|
||
var telemetryClient appinsights.TelemetryClient | ||
var isTelemetryEnabled string = "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
func (c *AddContext) LogTelemtry() { | ||
eventName := "config-add-context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LocLang = "Sqlcmd.locLang" | ||
UserOs = "Sqlcmd.userOs" | ||
|
||
// Legacy Flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
func InitializeAppInsights() { | ||
instrumentationKey := "f305b208-557d-4fba-bf06-25345c4dfdbc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
} | ||
|
||
func CloseTelemetryAndExit(exitcode int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consider registering for os signals instead of requiring an explicit call to CloseTelemetry.
Or is it too late to call CloseTelemetry by the time such a signal arrives?
defer k.Close() | ||
|
||
s, _, err := k.GetStringValue("UserId") | ||
if err != nil && strings.Contains(err.Error(), "The system cannot find the file specified") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s, _, _ = k.GetStringValue("UserId") | ||
} | ||
if strings.Contains(s, "{") { | ||
return s[1 : len(s)-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.