Skip to content

Commit d2df5d4

Browse files
authored
Merge pull request #22 from Microsoft/develop
Version 0.4.2
2 parents c3f5896 + 907a0d6 commit d2df5d4

20 files changed

+321
-60
lines changed

appinsights/client.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,9 @@ func NewTelemetryClient(iKey string) TelemetryClient {
7373
// Creates a new telemetry client instance configured by the specified
7474
// TelemetryConfiguration object.
7575
func NewTelemetryClientFromConfig(config *TelemetryConfiguration) TelemetryClient {
76-
channel := NewInMemoryChannel(config)
77-
context := NewTelemetryContext()
78-
79-
config.setupContext(context)
80-
8176
return &telemetryClient{
82-
channel: channel,
83-
context: context,
77+
channel: NewInMemoryChannel(config),
78+
context: config.setupContext(),
8479
isEnabled: true,
8580
}
8681
}

appinsights/client_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ func TestEndToEnd(t *testing.T) {
110110
}
111111

112112
j[0].assertPath(t, "iKey", test_ikey)
113-
j[0].assertPath(t, "name", "Microsoft.ApplicationInsights.Event")
113+
j[0].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Event")
114114
j[0].assertPath(t, "time", "2017-11-18T10:35:21Z")
115115

116116
j[1].assertPath(t, "iKey", test_ikey)
117-
j[1].assertPath(t, "name", "Microsoft.ApplicationInsights.Metric")
117+
j[1].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Metric")
118118
j[1].assertPath(t, "time", "2017-11-18T10:35:21Z")
119119

120120
j[2].assertPath(t, "iKey", test_ikey)
121-
j[2].assertPath(t, "name", "Microsoft.ApplicationInsights.Message")
121+
j[2].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Message")
122122
j[2].assertPath(t, "time", "2017-11-18T10:35:21Z")
123123

124124
j[3].assertPath(t, "iKey", test_ikey)
125-
j[3].assertPath(t, "name", "Microsoft.ApplicationInsights.Request")
125+
j[3].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Request")
126126
j[3].assertPath(t, "time", "2017-11-18T10:34:21Z")
127127
}

appinsights/configuration.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ func NewTelemetryConfiguration(instrumentationKey string) *TelemetryConfiguratio
3434
}
3535
}
3636

37-
func (config *TelemetryConfiguration) setupContext(context *TelemetryContext) {
38-
context.iKey = config.InstrumentationKey
37+
func (config *TelemetryConfiguration) setupContext() *TelemetryContext {
38+
context := NewTelemetryContext(config.InstrumentationKey)
3939
context.Tags.Internal().SetSdkVersion(sdkName + ":" + Version)
4040
context.Tags.Device().SetOsVersion(runtime.GOOS)
4141

4242
if hostname, err := os.Hostname(); err == nil {
4343
context.Tags.Device().SetId(hostname)
4444
context.Tags.Cloud().SetRoleInstance(hostname)
4545
}
46+
47+
return context
4648
}

appinsights/contracts/availabilitydata.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ type AvailabilityData struct {
3737
}
3838

3939
// Returns the name used when this is embedded within an Envelope container.
40-
func (data *AvailabilityData) EnvelopeName() string {
41-
return "Microsoft.ApplicationInsights.Availability"
40+
func (data *AvailabilityData) EnvelopeName(key string) string {
41+
if key != "" {
42+
return "Microsoft.ApplicationInsights." + key + ".Availability"
43+
} else {
44+
return "Microsoft.ApplicationInsights.Availability"
45+
}
4246
}
4347

4448
// Returns the base type when placed within a Data object container.

appinsights/contracts/eventdata.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ type EventData struct {
2323
}
2424

2525
// Returns the name used when this is embedded within an Envelope container.
26-
func (data *EventData) EnvelopeName() string {
27-
return "Microsoft.ApplicationInsights.Event"
26+
func (data *EventData) EnvelopeName(key string) string {
27+
if key != "" {
28+
return "Microsoft.ApplicationInsights." + key + ".Event"
29+
} else {
30+
return "Microsoft.ApplicationInsights.Event"
31+
}
2832
}
2933

3034
// Returns the base type when placed within a Data object container.

appinsights/contracts/exceptiondata.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ type ExceptionData struct {
3030
}
3131

3232
// Returns the name used when this is embedded within an Envelope container.
33-
func (data *ExceptionData) EnvelopeName() string {
34-
return "Microsoft.ApplicationInsights.Exception"
33+
func (data *ExceptionData) EnvelopeName(key string) string {
34+
if key != "" {
35+
return "Microsoft.ApplicationInsights." + key + ".Exception"
36+
} else {
37+
return "Microsoft.ApplicationInsights.Exception"
38+
}
3539
}
3640

3741
// Returns the base type when placed within a Data object container.

appinsights/contracts/messagedata.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ type MessageData struct {
2323
}
2424

2525
// Returns the name used when this is embedded within an Envelope container.
26-
func (data *MessageData) EnvelopeName() string {
27-
return "Microsoft.ApplicationInsights.Message"
26+
func (data *MessageData) EnvelopeName(key string) string {
27+
if key != "" {
28+
return "Microsoft.ApplicationInsights." + key + ".Message"
29+
} else {
30+
return "Microsoft.ApplicationInsights.Message"
31+
}
2832
}
2933

3034
// Returns the base type when placed within a Data object container.

appinsights/contracts/metricdata.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ type MetricData struct {
2020
}
2121

2222
// Returns the name used when this is embedded within an Envelope container.
23-
func (data *MetricData) EnvelopeName() string {
24-
return "Microsoft.ApplicationInsights.Metric"
23+
func (data *MetricData) EnvelopeName(key string) string {
24+
if key != "" {
25+
return "Microsoft.ApplicationInsights." + key + ".Metric"
26+
} else {
27+
return "Microsoft.ApplicationInsights.Metric"
28+
}
2529
}
2630

2731
// Returns the base type when placed within a Data object container.

appinsights/contracts/pageviewdata.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ type PageViewData struct {
1919
}
2020

2121
// Returns the name used when this is embedded within an Envelope container.
22-
func (data *PageViewData) EnvelopeName() string {
23-
return "Microsoft.ApplicationInsights.PageView"
22+
func (data *PageViewData) EnvelopeName(key string) string {
23+
if key != "" {
24+
return "Microsoft.ApplicationInsights." + key + ".PageView"
25+
} else {
26+
return "Microsoft.ApplicationInsights.PageView"
27+
}
2428
}
2529

2630
// Returns the base type when placed within a Data object container.

appinsights/contracts/remotedependencydata.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ type RemoteDependencyData struct {
4949
}
5050

5151
// Returns the name used when this is embedded within an Envelope container.
52-
func (data *RemoteDependencyData) EnvelopeName() string {
53-
return "Microsoft.ApplicationInsights.RemoteDependency"
52+
func (data *RemoteDependencyData) EnvelopeName(key string) string {
53+
if key != "" {
54+
return "Microsoft.ApplicationInsights." + key + ".RemoteDependency"
55+
} else {
56+
return "Microsoft.ApplicationInsights.RemoteDependency"
57+
}
5458
}
5559

5660
// Returns the base type when placed within a Data object container.

appinsights/contracts/requestdata.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ type RequestData struct {
4646
}
4747

4848
// Returns the name used when this is embedded within an Envelope container.
49-
func (data *RequestData) EnvelopeName() string {
50-
return "Microsoft.ApplicationInsights.Request"
49+
func (data *RequestData) EnvelopeName(key string) string {
50+
if key != "" {
51+
return "Microsoft.ApplicationInsights." + key + ".Request"
52+
} else {
53+
return "Microsoft.ApplicationInsights.Request"
54+
}
5155
}
5256

5357
// Returns the base type when placed within a Data object container.

appinsights/jsonserializer_test.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestJsonSerializerEvents(t *testing.T) {
6363

6464
// Trace
6565
j[0].assertPath(t, "iKey", test_ikey)
66-
j[0].assertPath(t, "name", "Microsoft.ApplicationInsights.Message")
66+
j[0].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Message")
6767
j[0].assertPath(t, "time", "2017-11-18T10:35:21Z")
6868
j[0].assertPath(t, "sampleRate", 100.0)
6969
j[0].assertPath(t, "data.baseType", "MessageData")
@@ -73,7 +73,7 @@ func TestJsonSerializerEvents(t *testing.T) {
7373

7474
// Event
7575
j[1].assertPath(t, "iKey", test_ikey)
76-
j[1].assertPath(t, "name", "Microsoft.ApplicationInsights.Event")
76+
j[1].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Event")
7777
j[1].assertPath(t, "time", "2017-11-18T10:35:21Z")
7878
j[1].assertPath(t, "sampleRate", 100.0)
7979
j[1].assertPath(t, "data.baseType", "EventData")
@@ -82,7 +82,7 @@ func TestJsonSerializerEvents(t *testing.T) {
8282

8383
// Metric
8484
j[2].assertPath(t, "iKey", test_ikey)
85-
j[2].assertPath(t, "name", "Microsoft.ApplicationInsights.Metric")
85+
j[2].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Metric")
8686
j[2].assertPath(t, "time", "2017-11-18T10:35:21Z")
8787
j[2].assertPath(t, "sampleRate", 100.0)
8888
j[2].assertPath(t, "data.baseType", "MetricData")
@@ -95,7 +95,7 @@ func TestJsonSerializerEvents(t *testing.T) {
9595

9696
// Request
9797
j[3].assertPath(t, "iKey", test_ikey)
98-
j[3].assertPath(t, "name", "Microsoft.ApplicationInsights.Request")
98+
j[3].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Request")
9999
j[3].assertPath(t, "time", "2017-11-18T10:34:21Z") // Constructor subtracts duration
100100
j[3].assertPath(t, "sampleRate", 100.0)
101101
j[3].assertPath(t, "data.baseType", "RequestData")
@@ -109,7 +109,7 @@ func TestJsonSerializerEvents(t *testing.T) {
109109

110110
// Aggregate metric
111111
j[4].assertPath(t, "iKey", test_ikey)
112-
j[4].assertPath(t, "name", "Microsoft.ApplicationInsights.Metric")
112+
j[4].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Metric")
113113
j[4].assertPath(t, "time", "2017-11-18T10:35:21Z")
114114
j[4].assertPath(t, "sampleRate", 100.0)
115115
j[4].assertPath(t, "data.baseType", "MetricData")
@@ -125,7 +125,7 @@ func TestJsonSerializerEvents(t *testing.T) {
125125

126126
// Remote dependency
127127
j[5].assertPath(t, "iKey", test_ikey)
128-
j[5].assertPath(t, "name", "Microsoft.ApplicationInsights.RemoteDependency")
128+
j[5].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.RemoteDependency")
129129
j[5].assertPath(t, "time", "2017-11-18T10:35:21Z")
130130
j[5].assertPath(t, "sampleRate", 100.0)
131131
j[5].assertPath(t, "data.baseType", "RemoteDependencyData")
@@ -142,7 +142,7 @@ func TestJsonSerializerEvents(t *testing.T) {
142142

143143
// Availability
144144
j[6].assertPath(t, "iKey", test_ikey)
145-
j[6].assertPath(t, "name", "Microsoft.ApplicationInsights.Availability")
145+
j[6].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Availability")
146146
j[6].assertPath(t, "time", "2017-11-18T10:35:21Z")
147147
j[6].assertPath(t, "sampleRate", 100.0)
148148
j[6].assertPath(t, "data.baseType", "AvailabilityData")
@@ -157,7 +157,7 @@ func TestJsonSerializerEvents(t *testing.T) {
157157

158158
// Page view
159159
j[7].assertPath(t, "iKey", test_ikey)
160-
j[7].assertPath(t, "name", "Microsoft.ApplicationInsights.PageView")
160+
j[7].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.PageView")
161161
j[7].assertPath(t, "time", "2017-11-18T10:35:21Z")
162162
j[7].assertPath(t, "sampleRate", 100.0)
163163
j[7].assertPath(t, "data.baseType", "PageViewData")
@@ -235,7 +235,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
235235

236236
// Trace
237237
j[0].assertPath(t, "iKey", test_ikey)
238-
j[0].assertPath(t, "name", "Microsoft.ApplicationInsights.Message")
238+
j[0].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Message")
239239
j[0].assertPath(t, "time", "2017-11-18T10:35:21Z")
240240
j[0].assertPath(t, "sampleRate", 100)
241241
j[0].assertPath(t, "data.baseType", "MessageData")
@@ -245,7 +245,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
245245

246246
// Event
247247
j[1].assertPath(t, "iKey", test_ikey)
248-
j[1].assertPath(t, "name", "Microsoft.ApplicationInsights.Event")
248+
j[1].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Event")
249249
j[1].assertPath(t, "time", "2017-11-18T10:35:21Z")
250250
j[1].assertPath(t, "sampleRate", 100)
251251
j[1].assertPath(t, "data.baseType", "EventData")
@@ -254,7 +254,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
254254

255255
// Metric
256256
j[2].assertPath(t, "iKey", test_ikey)
257-
j[2].assertPath(t, "name", "Microsoft.ApplicationInsights.Metric")
257+
j[2].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Metric")
258258
j[2].assertPath(t, "time", "2017-11-18T10:35:21Z")
259259
j[2].assertPath(t, "sampleRate", 100)
260260
j[2].assertPath(t, "data.baseType", "MetricData")
@@ -267,7 +267,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
267267

268268
// Aggregate metric
269269
j[3].assertPath(t, "iKey", test_ikey)
270-
j[3].assertPath(t, "name", "Microsoft.ApplicationInsights.Metric")
270+
j[3].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Metric")
271271
j[3].assertPath(t, "time", "2017-11-18T10:35:21Z")
272272
j[3].assertPath(t, "sampleRate", 100.0)
273273
j[3].assertPath(t, "data.baseType", "MetricData")
@@ -283,7 +283,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
283283

284284
// Request
285285
j[4].assertPath(t, "iKey", test_ikey)
286-
j[4].assertPath(t, "name", "Microsoft.ApplicationInsights.Request")
286+
j[4].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Request")
287287
j[4].assertPath(t, "time", "2017-11-18T10:35:21Z") // Context takes current time since it's not supplied
288288
j[4].assertPath(t, "sampleRate", 100.0)
289289
j[4].assertPath(t, "data.baseType", "RequestData")
@@ -303,7 +303,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
303303

304304
// Remote dependency
305305
j[5].assertPath(t, "iKey", test_ikey)
306-
j[5].assertPath(t, "name", "Microsoft.ApplicationInsights.RemoteDependency")
306+
j[5].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.RemoteDependency")
307307
j[5].assertPath(t, "time", "2017-11-18T10:35:21Z")
308308
j[5].assertPath(t, "sampleRate", 100.0)
309309
j[5].assertPath(t, "data.baseType", "RemoteDependencyData")
@@ -319,7 +319,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
319319

320320
// Availability
321321
j[6].assertPath(t, "iKey", test_ikey)
322-
j[6].assertPath(t, "name", "Microsoft.ApplicationInsights.Availability")
322+
j[6].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.Availability")
323323
j[6].assertPath(t, "time", "2017-11-18T10:35:21Z")
324324
j[6].assertPath(t, "sampleRate", 100.0)
325325
j[6].assertPath(t, "data.baseType", "AvailabilityData")
@@ -333,7 +333,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
333333

334334
// Page view
335335
j[7].assertPath(t, "iKey", test_ikey)
336-
j[7].assertPath(t, "name", "Microsoft.ApplicationInsights.PageView")
336+
j[7].assertPath(t, "name", "Microsoft.ApplicationInsights.01234567000089abcdef000000000000.PageView")
337337
j[7].assertPath(t, "time", "2017-11-18T10:35:21Z")
338338
j[7].assertPath(t, "sampleRate", 100.0)
339339
j[7].assertPath(t, "data.baseType", "PageViewData")
@@ -346,7 +346,7 @@ func TestJsonSerializerNakedEvents(t *testing.T) {
346346
// Test helpers...
347347

348348
func telemetryBuffer(items ...Telemetry) telemetryBufferItems {
349-
ctx := NewTelemetryContext()
349+
ctx := NewTelemetryContext(test_ikey)
350350
ctx.iKey = test_ikey
351351

352352
var result telemetryBufferItems

appinsights/package.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package appinsights
44

55
const (
66
sdkName = "go"
7-
Version = "0.4.1"
7+
Version = "0.4.2"
88
)

appinsights/telemetry.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88
"time"
99

1010
"github.com/Microsoft/ApplicationInsights-Go/appinsights/contracts"
11-
"github.com/satori/go.uuid"
1211
)
1312

1413
// Common interface implemented by telemetry data contracts
1514
type TelemetryData interface {
16-
EnvelopeName() string
15+
EnvelopeName(string) string
1716
BaseType() string
1817
Sanitize() []string
1918
}
@@ -408,7 +407,7 @@ func NewRequestTelemetry(method, uri string, duration time.Duration, responseCod
408407
return &RequestTelemetry{
409408
Name: fmt.Sprintf("%s %s", method, nameUri),
410409
Url: uri,
411-
Id: uuid.NewV4().String(),
410+
Id: newUUID().String(),
412411
Duration: duration,
413412
ResponseCode: responseCode,
414413
Success: success,
@@ -440,7 +439,7 @@ func (request *RequestTelemetry) TelemetryData() TelemetryData {
440439
data.Source = request.Source
441440

442441
if request.Id == "" {
443-
data.Id = uuid.NewV4().String()
442+
data.Id = newUUID().String()
444443
} else {
445444
data.Id = request.Id
446445
}

0 commit comments

Comments
 (0)