Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

apoorvdeshmukh
Copy link
Contributor

  • Telemetry and logging based on env variable

AxzelBC

This comment was marked as resolved.

@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

machineid v1.0.1

should have a NOTICE update too

c.LogTelemtry()
}

func (c *AddContext) LogTelemtry() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emtry(

Telemetry

@@ -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()
Copy link
Collaborator

@shueybubbles shueybubbles Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.LogTelemtry()

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"
}
Copy link
Collaborator

@shueybubbles shueybubbles Feb 27, 2024

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"
Copy link
Collaborator

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?

@shueybubbles
Copy link
Collaborator

DefineCommand(...CommandOptions)

the telemetry property keys to identify the command and subcommand should be extractable from CommandOptions, correct? instead of having them explicitly added by the command implementation later on.


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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// LogTelemtry()

if we switch to a new method, it should probably pass the map as a parameter and not require the command to invoke telemetry methods directly.

)

var telemetryClient appinsights.TelemetryClient
var isTelemetryEnabled string = "true"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d string = "true"

it's odd to use a string as a bool

}

func (c *AddContext) LogTelemtry() {
eventName := "config-add-context"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventName := "config-add-context"

How does this eventName differ from the event name constants defined in internal/telemetry/appinsights.go?

LocLang = "Sqlcmd.locLang"
UserOs = "Sqlcmd.userOs"

// Legacy Flags
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Legacy Flags

putting these as constants implies maintenance overhead every time we add a new flag.

Is there any reason not to build these identifiers dynamically based on the cobra data? In which scenario will an engineer have to type these constant symbols into a code editor?

}

func InitializeAppInsights() {
instrumentationKey := "f305b208-557d-4fba-bf06-25345c4dfdbc"
Copy link
Collaborator

@shueybubbles shueybubbles Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"f305b208-557d-4fba-bf06-25345c4dfdbc"

can we parameterize this key at build time?
It may be desirable to have one key for local builds and a separate production key for our signed builds. The production key won't be in the repo

}
}

func CloseTelemetryAndExit(exitcode int) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clos

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?

https://www.developer.com/languages/os-signals-go/#:~:text=Since%20the%20Go%20signal%20notification%20sends%20os.Signal%20values,given%20channel.%20It%20then%20relays%20the%20incoming%20signal.

defer k.Close()

s, _, err := k.GetStringValue("UserId")
if err != nil && strings.Contains(err.Error(), "The system cannot find the file specified") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The system cannot find the file specified") {

this won't work on non-English Windows

s, _, _ = k.GetStringValue("UserId")
}
if strings.Contains(s, "{") {
return s[1 : len(s)-1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return

s =

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants