-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luke Kim
committed
Jun 22, 2015
0 parents
commit 736bacd
Showing
16 changed files
with
800 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,24 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
*.exe | ||
*.test | ||
*.prof |
This file contains 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,3 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
} |
This file contains 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,39 @@ | ||
// Available variables which can be used inside of strings. | ||
// ${workspaceRoot}: the root folder of the team | ||
// ${file}: the current opened file | ||
// ${fileBasename}: the current opened file's basename | ||
// ${fileDirname}: the current opened file's dirname | ||
// ${fileExtname}: the current opened file's extension | ||
// ${cwd}: the current working directory of the spawned process | ||
|
||
// A task runner that calls the Go toolset | ||
{ | ||
"version": "0.1.0", | ||
|
||
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript | ||
"command": "go", | ||
|
||
// The command is a shell script | ||
"isShellCommand": false, | ||
|
||
// Show the output window only if unrecognized errors occur. | ||
"showOutput": "always", | ||
|
||
"windows": { | ||
"command": "go.exe", | ||
}, | ||
|
||
"tasks": [ | ||
{ | ||
"taskName": "build", | ||
"args": ["install"], | ||
"isBuildCommand": true | ||
}, | ||
{ | ||
"taskName": "test", | ||
"args": ["test", "-v"], | ||
"isBuildCommand": false, | ||
"isTestCommand": true | ||
} | ||
] | ||
} |
This file contains 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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Microsoft | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains 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,34 @@ | ||
# ApplicationInsights-Go | ||
Microsoft Application Insights SDK for Go | ||
|
||
This project provides a Go SDK for Application Insights. [Application Insights](http://azure.microsoft.com/en-us/services/application-insights/) is a service that allows developers to keep their applications available, performant, and successful. This go package will allow you to send telemetry of various kinds (event, trace, exception, etc.) to the Application Insights service where they can be visualized in the Azure Portal. | ||
|
||
## Requirements ## | ||
**Install** | ||
``` | ||
go get github.com/Microsoft/ApplicationInsights-Go | ||
``` | ||
**Get an instrumentation key** | ||
>**Note**: an instrumentation key is required before any data can be sent. Please see the "[Getting an Application Insights Instrumentation Key](https://github.com/Microsoft/AppInsights-Home/wiki#getting-an-application-insights-instrumentation-key)" section of the wiki for more information. To try the SDK without an instrumentation key, set the instrumentationKey config value to a non-empty string. | ||
## Usage ## | ||
|
||
```go | ||
import "github.com/Microsoft/ApplicationInsights-Go" | ||
|
||
client := appinsights.NewTelemetryClient("<instrumentation key>") | ||
client.TrackEvent("custom event") | ||
client.TrackMetric("custom metric", 123) | ||
client.TrackTrace("trace message" | ||
``` | ||
|
||
## telpad example test and example app ## | ||
|
||
The telpad app can be used to send test telemetry and as an example of using the SDK. | ||
|
||
```bash | ||
cd src/github.com/Microsoft/ApplicationInsights-Go | ||
go install | ||
|
||
telpad | ||
``` |
This file contains 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,118 @@ | ||
package appinsights | ||
|
||
type Domain interface { | ||
} | ||
|
||
type domain struct { | ||
Ver int `json:"ver"` | ||
Properties map[string]string `json:"properties"` | ||
} | ||
|
||
type data struct { | ||
BaseType string `json:"baseType"` | ||
BaseData Domain `json:"baseData"` | ||
} | ||
|
||
type envelope struct { | ||
Name string `json:"name"` | ||
Time string `json:"time"` | ||
IKey string `json:"iKey"` | ||
Tags map[string]string `json:"tags"` | ||
Data *data `json:"data"` | ||
} | ||
|
||
type DataPointType int | ||
|
||
const ( | ||
Measurement DataPointType = iota | ||
Aggregation | ||
) | ||
|
||
type DataPoint struct { | ||
Name string `json:"name"` | ||
Kind DataPointType `json:"kind"` | ||
Value float32 `json:"value"` | ||
Count int `json:"count"` | ||
min float32 `json:"min"` | ||
max float32 `json:"max"` | ||
stdDev float32 `json:"stdDev"` | ||
} | ||
|
||
type metricData struct { | ||
domain | ||
Metrics []*DataPoint `json:"metrics"` | ||
} | ||
|
||
type eventData struct { | ||
domain | ||
Name string `json:"name"` | ||
Measurements map[string]float32 `json:"measurements"` | ||
} | ||
|
||
type SeverityLevel int | ||
|
||
const ( | ||
Verbose SeverityLevel = iota | ||
Information | ||
Warning | ||
Error | ||
Critical | ||
) | ||
|
||
type messageData struct { | ||
domain | ||
Message string `json:"message"` | ||
SeverityLevel SeverityLevel `json:"severityLevel"` | ||
} | ||
|
||
type requestData struct { | ||
domain | ||
Id string `json:"id"` | ||
Name string `json:"name"` | ||
StartTime string `json:"startTime"` // yyyy-mm-ddThh:mm:ss.fffffff-hh:mm | ||
Duration string `json:"duration"` // d:hh:mm:ss.fffffff | ||
ResponseCode string `json:"responseCode"` | ||
Success bool `json:"success"` | ||
httpMethod string `json:"httpMethod"` | ||
url string `json:"url"` | ||
Measurements map[string]float32 `json:"measurements"` | ||
} | ||
|
||
type ContextTagKeys string | ||
|
||
const ( | ||
ApplicationVersion ContextTagKeys = "ai.application.ver" | ||
ApplicationBuild = "ai.application.build" | ||
DeviceId = "ai.device.id" | ||
DeviceIp = "ai.device.ip" | ||
DeviceLanguage = "ai.device.language" | ||
DeviceLocale = "ai.device.locale" | ||
DeviceModel = "ai.device.model" | ||
DeviceNetwork = "ai.device.network" | ||
DeviceOEMName = "ai.device.oemName" | ||
DeviceOS = "ai.device.os" | ||
DeviceOSVersion = "ai.device.osVersion" | ||
DeviceRoleInstance = "ai.device.roleInstance" | ||
DeviceRoleName = "ai.device.roleName" | ||
DeviceScreenResolution = "ai.device.screenResolution" | ||
DeviceType = "ai.device.type" | ||
DeviceMachineName = "ai.device.machineName" | ||
LocationIp = "ai.location.ip" | ||
OperationId = "ai.operation.id" | ||
OperationName = "ai.operation.name" | ||
OperationParentId = "ai.operation.parentId" | ||
OperationRootId = "ai.operation.rootId" | ||
OperationSyntheticSource = "ai.operation.syntheticSource" | ||
OperationIsSynthetic = "ai.operation.isSynthetic" | ||
SessionId = "ai.session.id" | ||
SessionIsFirst = "ai.session.isFirst" | ||
SessionIsNew = "ai.session.isNew" | ||
UserAccountAcquisitionDate = "ai.user.accountAcquisitionDate" | ||
UserAccountId = "ai.user.accountId" | ||
UserAgent = "ai.user.userAgent" | ||
UserId = "ai.user.id" | ||
UserStoreRegion = "ai.user.storeRegion" | ||
SampleRate = "ai.sample.sampleRate" | ||
InternalSdkVersion = "ai.internal.sdkVersion" | ||
InternalAgentVersion = "ai.internal.agentVersion" | ||
) |
This file contains 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,17 @@ | ||
package appinsights | ||
|
||
import "testing" | ||
|
||
func TestMessageData(t *testing.T) { | ||
testMessage := "test" | ||
|
||
messageData := &messageData{ | ||
Message: testMessage, | ||
} | ||
|
||
if messageData.Message != testMessage { | ||
t.Errorf("Message is %s, want %s", messageData.Message, testMessage) | ||
} | ||
|
||
messageData.Ver = 2 | ||
} |
This file contains 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,117 @@ | ||
package appinsights | ||
|
||
import "time" | ||
|
||
type TelemetryClient interface { | ||
Context() TelemetryContext | ||
InstrumentationKey() string | ||
IsEnabled() bool | ||
SetIsEnabled(bool) | ||
Track(Telemetry) | ||
TrackEvent(string) | ||
TrackEventTelemetry(*EventTelemetry) | ||
TrackMetric(string, float32) | ||
TrackMetricTelemetry(*MetricTelemetry) | ||
TrackTrace(string) | ||
TrackTraceTelemetry(*TraceTelemetry) | ||
TrackRequest(string, time.Time, time.Duration, string, bool) | ||
TrackRequestTelemetry(*RequestTelemetry) | ||
} | ||
|
||
type telemetryClient struct { | ||
TelemetryConfiguration *TelemetryConfiguration | ||
channel TelemetryChannel | ||
context TelemetryContext | ||
isEnabled bool | ||
} | ||
|
||
func NewTelemetryClient(iKey string) TelemetryClient { | ||
config := NewTelemetryConfiguration(iKey) | ||
channel := NewInMemoryChannel(config.EndpointUrl) | ||
context := NewTelemetryContext() | ||
return &telemetryClient{ | ||
TelemetryConfiguration: config, | ||
channel: channel, | ||
context: context, | ||
isEnabled: true, | ||
} | ||
} | ||
|
||
func (tc *telemetryClient) Context() TelemetryContext { | ||
return tc.context | ||
} | ||
|
||
func (tc *telemetryClient) InstrumentationKey() string { | ||
return tc.TelemetryConfiguration.InstrumentationKey | ||
} | ||
|
||
func (tc *telemetryClient) IsEnabled() bool { | ||
return tc.isEnabled | ||
} | ||
|
||
func (tc *telemetryClient) SetIsEnabled(isEnabled bool) { | ||
tc.isEnabled = isEnabled | ||
} | ||
|
||
func (tc *telemetryClient) Track(item Telemetry) { | ||
if tc.isEnabled { | ||
iKey := tc.context.InstrumentationKey() | ||
if len(iKey) == 0 { | ||
iKey = tc.TelemetryConfiguration.InstrumentationKey | ||
} | ||
|
||
item.Context().(*telemetryContext).iKey = iKey | ||
|
||
// TODO: Copy tc.context.Properties to item.Context().Properties | ||
|
||
tc.channel.Send(item) | ||
} | ||
} | ||
|
||
func (tc *telemetryClient) TrackEvent(name string) { | ||
item := NewEventTelemetry(name) | ||
tc.TrackEventTelemetry(item) | ||
} | ||
|
||
func (tc *telemetryClient) TrackEventTelemetry(event *EventTelemetry) { | ||
var item Telemetry | ||
item = event | ||
|
||
tc.Track(item) | ||
} | ||
|
||
func (tc *telemetryClient) TrackMetric(name string, value float32) { | ||
item := NewMetricTelemetry(name, value) | ||
tc.TrackMetricTelemetry(item) | ||
} | ||
|
||
func (tc *telemetryClient) TrackMetricTelemetry(metric *MetricTelemetry) { | ||
var item Telemetry | ||
item = metric | ||
|
||
tc.Track(item) | ||
} | ||
|
||
func (tc *telemetryClient) TrackTrace(message string) { | ||
item := NewTraceTelemetry(message, Information) | ||
tc.TrackTraceTelemetry(item) | ||
} | ||
|
||
func (tc *telemetryClient) TrackTraceTelemetry(trace *TraceTelemetry) { | ||
var item Telemetry | ||
item = trace | ||
|
||
tc.Track(item) | ||
} | ||
|
||
func (tc *telemetryClient) TrackRequest(name string, timestamp time.Time, duration time.Duration, responseCode string, success bool) { | ||
item := NewRequestTelemetry(name, timestamp, duration, responseCode, success) | ||
tc.TrackRequestTelemetry(item) | ||
} | ||
|
||
func (tc *telemetryClient) TrackRequestTelemetry(request *RequestTelemetry) { | ||
var item Telemetry | ||
item = request | ||
|
||
tc.Track(item) | ||
} |
This file contains 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,13 @@ | ||
package appinsights | ||
|
||
type TelemetryConfiguration struct { | ||
InstrumentationKey string | ||
EndpointUrl string | ||
} | ||
|
||
func NewTelemetryConfiguration(instrumentationKey string) *TelemetryConfiguration { | ||
return &TelemetryConfiguration{ | ||
InstrumentationKey: instrumentationKey, | ||
EndpointUrl: "https://dc.services.visualstudio.com/v2/track", | ||
} | ||
} |
Oops, something went wrong.