-
Notifications
You must be signed in to change notification settings - Fork 65
Add initial telelmetry skeleton #495
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
base: main
Are you sure you want to change the base?
Changes from all commits
b566825
d76a24b
d422ad6
49972d3
ee01884
cd4a093
12039f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"github.com/microsoft/go-sqlcmd/internal/cmdparser" | ||
"github.com/microsoft/go-sqlcmd/internal/config" | ||
"github.com/microsoft/go-sqlcmd/internal/localizer" | ||
"github.com/microsoft/go-sqlcmd/internal/telemetry" | ||
) | ||
|
||
// AddContext implements the `sqlcmd config add-context` command | ||
|
@@ -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() | ||
} | ||
|
||
func (c *AddContext) LogTelemtry() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
eventName := "config-add-context" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
properties := map[string]string{} | ||
properties["Command"] = "config" | ||
properties["SubCommand"] = "add-context" | ||
if c.name != "" { | ||
properties["name"] = "set" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
} |
||
if c.endpointName != "" { | ||
properties["endpoint"] = "set" | ||
} | ||
if c.userName != "" { | ||
properties["user"] = "set" | ||
} | ||
telemetry.TrackEvent(eventName, properties) | ||
telemetry.CloseTelemetry() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig" | ||
"github.com/microsoft/go-sqlcmd/internal/localizer" | ||
"github.com/microsoft/go-sqlcmd/internal/pal" | ||
"github.com/microsoft/go-sqlcmd/internal/telemetry" | ||
|
||
"github.com/microsoft/go-sqlcmd/internal/cmdparser" | ||
"github.com/microsoft/go-sqlcmd/internal/config" | ||
|
@@ -170,3 +171,23 @@ func (c *AddUser) run() { | |
uniqueUserName := config.AddUser(user) | ||
output.Info(localizer.Sprintf("User '%v' added", uniqueUserName)) | ||
} | ||
|
||
func (c *AddUser) LogTelemtry() { | ||
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 commentThe 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? |
||
} | ||
if c.authType != "" { | ||
properties["authtype"] = c.authType | ||
} | ||
if c.name != "" { | ||
properties["name"] = "set" | ||
} | ||
|
||
if c.passwordEncryption != "" { | ||
properties["passwordEncryption"] = "set" | ||
} | ||
telemetry.TrackEvent(eventName, properties) | ||
telemetry.CloseTelemetry() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
github.com/docker/distribution v2.8.2+incompatible | ||
github.com/docker/docker v24.0.9+incompatible | ||
github.com/docker/go-connections v0.4.0 | ||
github.com/golang-sql/sqlexp v0.1.0 | ||
github.com/google/uuid v1.3.0 | ||
github.com/microsoft/ApplicationInsights-Go v0.4.4 | ||
github.com/microsoft/go-mssqldb v1.6.0 | ||
github.com/opencontainers/image-spec v1.0.2 | ||
github.com/peterh/liner v1.2.2 | ||
|
@@ -25,6 +27,7 @@ require ( | |
) | ||
|
||
require ( | ||
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c // indirect | ||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1 // indirect | ||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect | ||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect | ||
|
@@ -40,6 +43,7 @@ require ( | |
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/gofrs/uuid v3.3.0+incompatible // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect | ||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,8 @@ type Command interface { | |
// the Command object to have access to the dependencies it needs, without | ||
// having to manage them directly. | ||
SetCrossCuttingConcerns(dependency.Options) | ||
|
||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
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 withLogTelemetry
as a member and have whatever callsrun
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.