1
0
Fork 0

Create init method on provider interface

This commit is contained in:
SALLEYRON Julien 2018-07-11 09:08:03 +02:00 committed by Traefiker Bot
parent b2a57ca1f3
commit 027093a5a5
52 changed files with 2760 additions and 131 deletions

View file

@ -0,0 +1,45 @@
package appinsights
import (
"bytes"
"encoding/json"
"fmt"
"time"
)
func (items TelemetryBufferItems) serialize() []byte {
var result bytes.Buffer
encoder := json.NewEncoder(&result)
for _, item := range items {
end := result.Len()
if err := encoder.Encode(prepare(item)); err != nil {
diagnosticsWriter.Write(fmt.Sprintf("Telemetry item failed to serialize: %s", err.Error()))
result.Truncate(end)
}
}
return result.Bytes()
}
func prepare(item Telemetry) *envelope {
data := &data{
BaseType: item.baseTypeName() + "Data",
BaseData: item.baseData(),
}
context := item.Context()
envelope := &envelope{
Name: "Microsoft.ApplicationInsights." + item.baseTypeName(),
Time: item.Timestamp().Format(time.RFC3339),
IKey: context.InstrumentationKey(),
Data: data,
}
if tcontext, ok := context.(*telemetryContext); ok {
envelope.Tags = tcontext.tags
}
return envelope
}