Conversation
apoorvdeshmukh
commented
Jan 2, 2024
- Telemetry and logging based on env variable
| require ( | ||
| github.com/alecthomas/chroma/v2 v2.5.0 | ||
| github.com/billgraziano/dpapi v0.4.0 | ||
| github.com/denisbrodbeck/machineid v1.0.1 |
| c.LogTelemtry() | ||
| } | ||
|
|
||
| func (c *AddContext) LogTelemtry() { |
| {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.
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.
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.
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() |
| ) | ||
|
|
||
| var telemetryClient appinsights.TelemetryClient | ||
| var isTelemetryEnabled string = "true" |
| } | ||
|
|
||
| func (c *AddContext) LogTelemtry() { | ||
| eventName := "config-add-context" |
| LocLang = "Sqlcmd.locLang" | ||
| UserOs = "Sqlcmd.userOs" | ||
|
|
||
| // Legacy Flags |
There was a problem hiding this comment.
| } | ||
|
|
||
| func InitializeAppInsights() { | ||
| instrumentationKey := "f305b208-557d-4fba-bf06-25345c4dfdbc" |
| } | ||
| } | ||
|
|
||
| func CloseTelemetryAndExit(exitcode int) { |
There was a problem hiding this comment.
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") { |
| s, _, _ = k.GetStringValue("UserId") | ||
| } | ||
| if strings.Contains(s, "{") { | ||
| return s[1 : len(s)-1] |