forked from microsoft/ApplicationInsights-Go
/
configuration.go
48 lines (39 loc) · 1.39 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package appinsights
import (
"os"
"runtime"
"time"
)
// Configuration data used to initialize a new TelemetryClient.
type TelemetryConfiguration struct {
// Instrumentation key for the client.
InstrumentationKey string
// Endpoint URL where data will be submitted.
EndpointUrl string
// Maximum number of telemetry items that can be submitted in each
// request. If this many items are buffered, the buffer will be
// flushed before MaxBatchInterval expires.
MaxBatchSize int
// Maximum time to wait before sending a batch of telemetry.
MaxBatchInterval time.Duration
}
// Creates a new TelemetryConfiguration object with the specified
// instrumentation key and default values.
func NewTelemetryConfiguration(instrumentationKey string) *TelemetryConfiguration {
return &TelemetryConfiguration{
InstrumentationKey: instrumentationKey,
EndpointUrl: "https://dc.services.visualstudio.com/v2/track",
MaxBatchSize: 1024,
MaxBatchInterval: time.Duration(10) * time.Second,
}
}
func (config *TelemetryConfiguration) setupContext() *TelemetryContext {
context := NewTelemetryContext(config.InstrumentationKey)
context.Tags.Internal().SetSdkVersion(sdkName + ":" + Version)
context.Tags.Device().SetOsVersion(runtime.GOOS)
if hostname, err := os.Hostname(); err == nil {
context.Tags.Device().SetId(hostname)
context.Tags.Cloud().SetRoleInstance(hostname)
}
return context
}